Skip to content

Commit

Permalink
Add loaded_accounts_stats to TransactionResults, so callsites can acc…
Browse files Browse the repository at this point in the history
…ess stats of loaded accounts for sanitized transactions

Such stats include the actual loaded-accounts-data-size, count of loaded accounts.
  • Loading branch information
tao-stones committed May 29, 2024
1 parent 930b075 commit 36aecbf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
4 changes: 4 additions & 0 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let loaded1 = Ok(LoadedTransaction {
Expand All @@ -1588,6 +1589,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded0, loaded1];
Expand Down Expand Up @@ -1964,6 +1966,7 @@ mod tests {
nonce: nonce.clone(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded];
Expand Down Expand Up @@ -2068,6 +2071,7 @@ mod tests {
nonce: nonce.clone(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded];
Expand Down
26 changes: 25 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ use {
TransactionProcessingConfig,
},
transaction_results::{
TransactionExecutionDetails, TransactionExecutionResult, TransactionResults,
TransactionExecutionDetails, TransactionExecutionResult,
TransactionLoadedAccountsStats, TransactionResults,
},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
Expand Down Expand Up @@ -4193,13 +4194,36 @@ impl Bank {
update_transaction_statuses_time.as_us(),
);

let loaded_accounts_stats = Self::collect_loaded_accounts_stats(loaded_txs);
assert_eq!(
loaded_accounts_stats.len(),
execution_results.len(),
"loaded_account_stats and execution_results are not the same size"
);

TransactionResults {
fee_collection_results,
loaded_accounts_stats,
execution_results,
rent_debits,
}
}

fn collect_loaded_accounts_stats(
loaded_txs: &[TransactionLoadResult],
) -> Vec<Result<TransactionLoadedAccountsStats>> {
loaded_txs
.iter()
.map(|load_result| match load_result {
Ok(loaded_tx) => Ok(TransactionLoadedAccountsStats {
loaded_accounts_data_size: loaded_tx.loaded_accounts_data_size,
loaded_accounts_count: loaded_tx.accounts.len(),
}),
Err(err) => Err(err.clone()),
})
.collect()
}

fn collect_rent(
&self,
execution_results: &[TransactionExecutionResult],
Expand Down
17 changes: 12 additions & 5 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct LoadedTransaction {
pub nonce: Option<NonceFull>,
pub rent: TransactionRent,
pub rent_debits: RentDebits,
pub loaded_accounts_data_size: usize,
}

impl LoadedTransaction {
Expand Down Expand Up @@ -388,6 +389,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
nonce,
rent: tx_rent,
rent_debits,
loaded_accounts_data_size: accumulated_accounts_data_size,
})
}

Expand Down Expand Up @@ -1519,7 +1521,8 @@ mod tests {
program_indices: vec![vec![]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1722,7 +1725,8 @@ mod tests {
nonce: None,
program_indices: vec![vec![1]],
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1914,7 +1918,8 @@ mod tests {
program_indices: vec![vec![2, 1]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -2006,7 +2011,8 @@ mod tests {
program_indices: vec![vec![3, 1], vec![3, 1]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -2168,7 +2174,8 @@ mod tests {
Some(mock_bank.accounts_map[&key2.pubkey()].clone())
)),
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down
2 changes: 2 additions & 0 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 32,
};

let mut processing_config = TransactionProcessingConfig::default();
Expand Down Expand Up @@ -1124,6 +1125,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
};

let processing_config = TransactionProcessingConfig {
Expand Down
7 changes: 7 additions & 0 deletions svm/src/transaction_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ use {

pub struct TransactionResults {
pub fee_collection_results: Vec<transaction::Result<()>>,
pub loaded_accounts_stats: Vec<transaction::Result<TransactionLoadedAccountsStats>>,
pub execution_results: Vec<TransactionExecutionResult>,
pub rent_debits: Vec<RentDebits>,
}

#[derive(Debug, Default, Clone)]
pub struct TransactionLoadedAccountsStats {
pub loaded_accounts_data_size: usize,
pub loaded_accounts_count: usize,
}

/// Type safe representation of a transaction execution attempt which
/// differentiates between a transaction that was executed (will be
/// committed to the ledger) and a transaction which wasn't executed
Expand Down

0 comments on commit 36aecbf

Please sign in to comment.