Skip to content

Commit

Permalink
Include loaded accounts data size in TransactionResults (#1525)
Browse files Browse the repository at this point in the history
Add loaded_accounts_stats to TransactionResults, so call sites can access 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 authored May 30, 2024
1 parent 97d36e6 commit faa4fa6
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 @@ -1582,6 +1582,7 @@ mod tests {
fee_details: FeeDetails::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let loaded1 = Ok(LoadedTransaction {
Expand All @@ -1591,6 +1592,7 @@ mod tests {
fee_details: FeeDetails::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded0, loaded1];
Expand Down Expand Up @@ -1968,6 +1970,7 @@ mod tests {
fee_details: FeeDetails::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded];
Expand Down Expand Up @@ -2073,6 +2076,7 @@ mod tests {
fee_details: FeeDetails::default(),
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 @@ -4139,13 +4140,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 @@ -54,6 +54,7 @@ pub struct LoadedTransaction {
pub fee_details: FeeDetails,
pub rent: TransactionRent,
pub rent_debits: RentDebits,
pub loaded_accounts_data_size: usize,
}

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

Expand Down Expand Up @@ -1523,7 +1525,8 @@ mod tests {
nonce: None,
fee_details,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1728,7 +1731,8 @@ mod tests {
fee_details,
program_indices: vec![vec![1]],
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1912,7 +1916,8 @@ mod tests {
nonce: None,
fee_details,
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 {
nonce: None,
fee_details,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -2169,7 +2175,8 @@ mod tests {
)),
fee_details: FeeDetails::default(),
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 @@ -1001,6 +1001,7 @@ mod tests {
fee_details: FeeDetails::default(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 32,
};

let mut processing_config = TransactionProcessingConfig::default();
Expand Down Expand Up @@ -1126,6 +1127,7 @@ mod tests {
fee_details: FeeDetails::default(),
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 faa4fa6

Please sign in to comment.