Skip to content

Commit

Permalink
svm: simplify inspect logic (#3769)
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe authored Nov 28, 2024
1 parent f99e056 commit dc57128
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,32 @@ impl<'a, CB: TransactionProcessingCallback> AccountLoader<'a, CB> {
}

let account = if let Some(account) = self.account_cache.get(account_key) {
// Inspect the account prior to collecting rent, since
// rent collection can modify the account.
self.callbacks
.inspect_account(account_key, AccountState::Alive(account), is_writable);

// If lamports is 0, a previous transaction deallocated this account.
// Return None without inspecting, so it can be recreated.
// We return None instead of the account we found so it can be created fresh.
// We never evict from the cache, or else we would fetch stale state from accounts-db.
if account.lamports() == 0 {
None
} else {
Some(account.clone())
}
} else if let Some(account) = self.callbacks.get_account_shared_data(account_key) {
// Inspect the account prior to collecting rent, since
// rent collection can modify the account.
self.callbacks
.inspect_account(account_key, AccountState::Alive(&account), is_writable);

self.account_cache.insert(*account_key, account.clone());

Some(account)
} else {
self.callbacks
.inspect_account(account_key, AccountState::Dead, is_writable);

None
};

// Inspect prior to collecting rent, since rent collection can modify the account.
self.callbacks.inspect_account(
account_key,
if let Some(ref account) = account {
AccountState::Alive(account)
} else {
AccountState::Dead
},
is_writable,
);

account.map(|account| LoadedTransactionAccount {
loaded_size: account.data().len(),
account,
Expand Down

0 comments on commit dc57128

Please sign in to comment.