-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e counters split out by top usecases
- Loading branch information
1 parent
2591aae
commit fee3974
Showing
17 changed files
with
227 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
consensus/src/transaction_shuffler/use_case_aware/types.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,5 @@ | ||
// Copyright (c) Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use aptos_types::transaction::SignedTransaction; | ||
use move_core_types::account_address::AccountAddress; | ||
|
||
pub(crate) type InputIdx = usize; | ||
pub(crate) type OutputIdx = usize; | ||
|
||
#[derive(Clone, Eq, Hash, PartialEq)] | ||
pub(crate) enum UseCaseKey { | ||
Platform, | ||
ContractAddress(AccountAddress), | ||
// ModuleBundle (deprecated anyway), scripts, Multisig. | ||
Others, | ||
} | ||
|
||
impl std::fmt::Debug for UseCaseKey { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
use UseCaseKey::*; | ||
|
||
match self { | ||
Platform => write!(f, "PP"), | ||
ContractAddress(addr) => write!(f, "c{}", hex::encode_upper(&addr[31..])), | ||
Others => write!(f, "OO"), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) trait UseCaseAwareTransaction { | ||
fn parse_sender(&self) -> AccountAddress; | ||
|
||
fn parse_use_case(&self) -> UseCaseKey; | ||
} | ||
|
||
impl UseCaseAwareTransaction for SignedTransaction { | ||
fn parse_sender(&self) -> AccountAddress { | ||
self.sender() | ||
} | ||
|
||
fn parse_use_case(&self) -> UseCaseKey { | ||
use aptos_types::transaction::TransactionPayload::*; | ||
use UseCaseKey::*; | ||
|
||
match self.payload() { | ||
Script(_) | ModuleBundle(_) | Multisig(_) => Others, | ||
EntryFunction(entry_fun) => { | ||
let module_id = entry_fun.module(); | ||
if module_id.address().is_special() { | ||
Platform | ||
} else { | ||
// n.b. Generics ignored. | ||
ContractAddress(*module_id.address()) | ||
} | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use aptos_mempool_notifications::CommittedTransaction; | ||
use aptos_types::transaction::use_case::UseCaseKey; | ||
use std::collections::{HashMap, HashSet, VecDeque}; | ||
|
||
pub(crate) struct UseCaseHistory { | ||
window_size: usize, | ||
num_top_to_track: usize, | ||
recent: VecDeque<HashMap<UseCaseKey, usize>>, | ||
} | ||
|
||
impl UseCaseHistory { | ||
pub(crate) fn new(window_size: usize, num_top_to_track: usize) -> Self { | ||
Self { | ||
window_size, | ||
num_top_to_track, | ||
recent: VecDeque::with_capacity(window_size + 1), | ||
} | ||
} | ||
|
||
pub(crate) fn update_usecases_and_get_tracking_set( | ||
&mut self, | ||
transactions: &[CommittedTransaction], | ||
) -> HashSet<UseCaseKey> { | ||
let mut count_by_usecase = HashMap::new(); | ||
for transaction in transactions { | ||
*count_by_usecase | ||
.entry(transaction.use_case.clone()) | ||
.or_insert(0) += 1; | ||
} | ||
|
||
self.recent.push_back(count_by_usecase); | ||
while self.recent.len() > self.window_size { | ||
self.recent.pop_front(); | ||
} | ||
|
||
let mut total = HashMap::new(); | ||
for group in &self.recent { | ||
for (use_case, count) in group { | ||
if use_case != &UseCaseKey::Platform && use_case != &UseCaseKey::Others { | ||
*total.entry(use_case.clone()).or_insert(0) += count; | ||
} | ||
} | ||
} | ||
|
||
let mut result = HashSet::new(); | ||
result.insert(UseCaseKey::Platform); | ||
result.insert(UseCaseKey::Others); | ||
|
||
let mut sorted = total.into_iter().collect::<Vec<_>>(); | ||
sorted.sort_by_key(|(_, count)| *count); | ||
|
||
for _ in 0..self.num_top_to_track { | ||
if let Some((use_case, _)) = sorted.pop() { | ||
result.insert(use_case); | ||
} | ||
} | ||
|
||
result | ||
} | ||
} |
Oops, something went wrong.