Skip to content

Commit

Permalink
compat expansion; forge refactor (#13302)
Browse files Browse the repository at this point in the history
Expand "compat" forge test to simultaneously do traffic generation, gather stats, and run a gradual upgrade of validator nodes.

Lots of refactor to get there, replacing lots of `&Foo` and `&mut Foo` with `Arc<Mutex<Foo>>` and hidden internal mutability to make things multithread capable.
  • Loading branch information
brianolson authored and areshand committed Jun 27, 2024
1 parent f90f322 commit d2cd982
Show file tree
Hide file tree
Showing 88 changed files with 2,283 additions and 1,623 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions api/types/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,13 @@ impl<'a, S: StateView> MoveConverter<'a, S> {
status: &ExecutionStatus,
txn_aux_data: Option<TransactionAuxiliaryData>,
) -> String {
match status {
let mut status = status.to_owned();
status = if let Some(aux_data) = txn_aux_data {
ExecutionStatus::aug_with_aux_data(status, &aux_data)
} else {
status
};
match &status {
ExecutionStatus::MoveAbort {
location,
code,
Expand Down Expand Up @@ -1055,17 +1061,10 @@ impl<'a, S: StateView> MoveConverter<'a, S> {
)
},
ExecutionStatus::MiscellaneousError(code) => {
if txn_aux_data.is_none() && code.is_none() {
if code.is_none() {
"Execution failed with miscellaneous error and no status code".to_owned()
} else if code.is_some() {
format!("{:#?}", code.unwrap())
} else {
let aux_data = txn_aux_data.unwrap();
let vm_details = aux_data.get_detail_error_message();
vm_details.map_or(
"Execution failed with miscellaneous error and no status code".to_owned(),
|e| format!("{:#?}", e.status_code()),
)
format!("{:#?}", code.unwrap())
}
},
}
Expand Down
58 changes: 33 additions & 25 deletions crates/transaction-emitter-lib/src/emitter/account_minter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use aptos_sdk::{
use aptos_transaction_generator_lib::{
CounterState, ReliableTransactionSubmitter, RootAccountHandle, SEND_AMOUNT,
};
use aptos_types::account_address::AccountAddress;
use core::{
cmp::min,
result::Result::{Err, Ok},
Expand All @@ -31,7 +32,7 @@ use std::{
};

pub struct SourceAccountManager<'t> {
pub source_account: &'t LocalAccount,
pub source_account: Arc<LocalAccount>,
pub txn_executor: &'t dyn ReliableTransactionSubmitter,
pub req: &'t EmitJobRequest,
pub txn_factory: TransactionFactory,
Expand All @@ -43,17 +44,21 @@ impl<'t> RootAccountHandle for SourceAccountManager<'t> {
self.check_approve_funds(amount, reason).await.unwrap();
}

fn get_root_account(&self) -> &LocalAccount {
self.source_account
fn get_root_account(&self) -> Arc<LocalAccount> {
self.source_account.clone()
}
}

impl<'t> SourceAccountManager<'t> {
fn source_account_address(&self) -> AccountAddress {
self.source_account.address()
}

// returns true if we might want to recheck the volume, as it was auto-approved.
async fn check_approve_funds(&self, amount: u64, reason: &str) -> Result<bool> {
let balance = self
.txn_executor
.get_account_balance(self.source_account.address())
.get_account_balance(self.source_account_address())
.await?;
Ok(if self.req.mint_to_root {
// We have a root account, so amount of funds minted is not a problem
Expand All @@ -63,7 +68,7 @@ impl<'t> SourceAccountManager<'t> {
if balance < amount.checked_mul(100).unwrap_or(u64::MAX / 2) {
info!(
"Mint account {} current balance is {}, needing {} for {}, minting to refil it fully",
self.source_account.address(),
self.source_account_address(),
balance,
amount,
reason,
Expand All @@ -74,7 +79,7 @@ impl<'t> SourceAccountManager<'t> {
} else {
info!(
"Mint account {} current balance is {}, needing {} for {}. Proceeding without minting, as balance would overflow otherwise",
self.source_account.address(),
self.source_account_address(),
balance,
amount,
reason,
Expand All @@ -85,7 +90,7 @@ impl<'t> SourceAccountManager<'t> {
} else {
info!(
"Source account {} current balance is {}, needed {} coins for {}, or {:.3}% of its balance",
self.source_account.address(),
self.source_account_address(),
balance,
amount,
reason,
Expand All @@ -95,7 +100,7 @@ impl<'t> SourceAccountManager<'t> {
if balance < amount {
return Err(anyhow!(
"Source ({}) doesn't have enough coins, balance {} < needed {} for {}",
self.source_account.address(),
self.source_account_address(),
balance,
amount,
reason
Expand Down Expand Up @@ -128,15 +133,15 @@ impl<'t> SourceAccountManager<'t> {
let txn = self
.source_account
.sign_with_transaction_builder(self.txn_factory.payload(
aptos_stdlib::aptos_coin_mint(self.source_account.address(), amount),
aptos_stdlib::aptos_coin_mint(self.source_account_address(), amount),
));

if let Err(e) = txn_executor.execute_transactions(&[txn]).await {
// This cannot work simultaneously across different txn emitters,
// so check on failure if another emitter has refilled it instead

let balance = txn_executor
.get_account_balance(self.source_account.address())
.get_account_balance(self.source_account_address())
.await?;
if balance > u64::MAX / 2 {
Ok(())
Expand Down Expand Up @@ -393,7 +398,7 @@ impl<'t> AccountMinter<'t> {

pub async fn create_and_fund_seed_accounts(
&mut self,
mut new_source_account: Option<LocalAccount>,
new_source_account: Option<LocalAccount>,
txn_executor: &dyn ReliableTransactionSubmitter,
account_generator: Box<dyn LocalAccountGenerator>,
seed_account_num: usize,
Expand All @@ -407,6 +412,10 @@ impl<'t> AccountMinter<'t> {
);
let mut i = 0;
let mut seed_accounts = vec![];
let source_account = match new_source_account {
None => self.source_account.get_root_account().clone(),
Some(param_account) => Arc::new(param_account),
};
while i < seed_account_num {
let batch_size = min(max_submit_batch_size, seed_account_num - i);
let mut rng = StdRng::from_rng(self.rng()).unwrap();
Expand All @@ -418,11 +427,7 @@ impl<'t> AccountMinter<'t> {
.iter()
.map(|account| {
create_and_fund_account_request(
if let Some(account) = &mut new_source_account {
account
} else {
self.source_account.get_root_account()
},
source_account.clone(),
coins_per_seed_account,
account.public_key(),
txn_factory,
Expand Down Expand Up @@ -470,16 +475,17 @@ impl<'t> AccountMinter<'t> {
coins_for_source: u64,
) -> Result<LocalAccount> {
const NUM_TRIES: usize = 3;
let root_account = self.source_account.get_root_account();
let root_address = root_account.address();
for i in 0..NUM_TRIES {
self.source_account.get_root_account().set_sequence_number(
txn_executor
.query_sequence_number(self.source_account.get_root_account().address())
.await?,
);
{
let new_sequence_number = txn_executor.query_sequence_number(root_address).await?;
root_account.set_sequence_number(new_sequence_number);
}

let new_source_account = LocalAccount::generate(self.rng());
let txn = create_and_fund_account_request(
self.source_account.get_root_account(),
root_account.clone(),
coins_for_source,
new_source_account.public_key(),
&self.txn_factory,
Expand Down Expand Up @@ -530,12 +536,14 @@ async fn create_and_fund_new_accounts(
.chunks(max_num_accounts_per_batch)
.map(|chunk| chunk.to_vec())
.collect::<Vec<_>>();
let source_address = source_account.address();
let source_account = Arc::new(source_account);
for batch in accounts_by_batch {
let creation_requests: Vec<_> = batch
.iter()
.map(|account| {
create_and_fund_account_request(
&source_account,
source_account.clone(),
coins_per_new_account,
account.public_key(),
txn_factory,
Expand All @@ -546,13 +554,13 @@ async fn create_and_fund_new_accounts(
txn_executor
.execute_transactions_with_counter(&creation_requests, counters)
.await
.with_context(|| format!("Account {} couldn't mint", source_account.address()))?;
.with_context(|| format!("Account {} couldn't mint", source_address))?;
}
Ok(())
}

pub fn create_and_fund_account_request(
creation_account: &LocalAccount,
creation_account: Arc<LocalAccount>,
amount: u64,
pubkey: &Ed25519PublicKey,
txn_factory: &TransactionFactory,
Expand Down
Loading

0 comments on commit d2cd982

Please sign in to comment.