Skip to content

Commit

Permalink
start sketching account updater
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Aug 29, 2024
1 parent 022062e commit 9ce1b29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ pub fn validate_fee_payer(
//
// the other thing to remember is the program cache tests. do i need to change the framework for that at all?
// hm. i believe i need a mechanism to forward the cache to the next state... ugh

//
// XXX ok new day new me. i started writing the update function this week but wanted to reuse the saver fns
// but they mutated the rollback accounts. so i started another pr to roll nonces earlier
// i am pretty sure that is almost through code review now! so i can use the saver fn now
// i think i can just use the collect accounts function directly actually? lol so simple

pub(crate) fn load_accounts<CB: TransactionProcessingCallback>(
callbacks: &CB,
Expand Down
31 changes: 26 additions & 5 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
TransactionCheckResult, TransactionLoadResult, ValidatedTransactionDetails,
},
account_overrides::AccountOverrides,
account_saver::collect_accounts_to_store,
message_processor::MessageProcessor,
program_loader::{get_program_modification_slot, load_program_with_pubkey},
rollback_accounts::RollbackAccounts,
Expand Down Expand Up @@ -267,7 +268,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
program_cache_for_tx_batch
});

let accounts_cache = load_accounts(
let mut accounts_map = load_accounts(
callbacks,
sanitized_txs,
&check_results,
Expand All @@ -278,7 +279,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
.feature_set
.is_active(&feature_set::enable_transaction_loading_failure_fees::id());

for (tx, check_result) in sanitized_txs.iter().zip(check_results) {
for (tx, check_result) in sanitized_txs.into_iter().zip(check_results) {
let validate_result = check_result.and_then(|tx_details| {
// XXX this shouldnt take callback or override
self.validate_transaction_fee_payer(
Expand All @@ -298,7 +299,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
});

let load_result = load_transaction(
&accounts_cache,
&accounts_map,
tx,
validate_result,
&mut error_metrics,
Expand Down Expand Up @@ -329,15 +330,30 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
config,
);

// XXX FIXME need to code the thing to update the accounts map. also handle nonces
// XXX TODO FIXME im going to go INSANE. first off, i really dont want to clone executed_tx
// second off WHY do we lose type specificity at some point??? im passing `sanitized_tx here` (wrongly)
// because if i try to create &[tx] it tells me
// "the trait `SVMMessage` is not implemented for `&impl SVMTransaction`"
// which i dont understand because the exact same type signature is used for `load_accounts()` et al
// i guess it becomes a reference with the `iter()` call? but `into_iter()` doesnt change it
let processing_results = [Ok(ProcessedTransaction::Executed(Box::new(
executed_tx.clone(),
)))];
let (update_accounts, _) =
collect_accounts_to_store(sanitized_txs, &processing_results);
for (pubkey, account) in update_accounts {
accounts_map.insert(*pubkey, account.clone());
}

// Update batch specific cache of the loaded programs with the modifications
// made by the transaction, if it executed successfully.
if executed_tx.was_successful() {
program_cache_for_tx_batch.merge(&executed_tx.programs_modified_by_tx);
}

Ok(ProcessedTransaction::Executed(Box::new(executed_tx)))
Ok(ProcessedTransaction::Executed(Box::new(
executed_tx.clone(),
)))
}
};

Expand Down Expand Up @@ -420,6 +436,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {

let fee_payer_address = message.fee_payer();

// XXX we CANNOT use the callback here, we MUST use the hashmap
let fee_payer_account = account_overrides
.and_then(|overrides| overrides.get(fee_payer_address).cloned())
.or_else(|| callbacks.get_account_shared_data(fee_payer_address));
Expand Down Expand Up @@ -462,6 +479,10 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
fee_details.total_fee(),
)?;

// XXX i need to do some kind of nonce validation here
// we are switching to hashmap so, i think we just check "is actual nonce data same as rollback nonce data"
// if so, we already used it, and should drop the transaction. perhaps charging fees or not, dunno

// Capture fee-subtracted fee payer account and next nonce account state
// to commit if transaction execution fails.
let rollback_accounts = RollbackAccounts::new(
Expand Down

0 comments on commit 9ce1b29

Please sign in to comment.