Skip to content

Commit

Permalink
proper re-sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed May 18, 2023
1 parent 4a60e2f commit ca20a5e
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use {
clock::{Slot, FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
feature_set, saturating_add_assign,
timing::timestamp,
transaction::{self, AddressLoader, SanitizedTransaction, TransactionError},
transaction::{
self, AddressLoader, SanitizedTransaction, SanitizedVersionedTransaction,
TransactionError,
},
},
std::{
sync::{atomic::Ordering, Arc},
Expand Down Expand Up @@ -404,6 +407,26 @@ impl Consumer {
txs: &[SanitizedTransaction],
max_slot_ages: &[Slot],
) -> ProcessTransactionBatchOutput {
/// Re-sanitize a transaction for epoch cross.
fn resanitize(
transaction: &SanitizedTransaction,
bank: &Bank,
) -> transaction::Result<SanitizedTransaction> {
let versioned_transaction = transaction.to_versioned_transaction();
let sanitized_versioned_transaction =
SanitizedVersionedTransaction::try_from(versioned_transaction)?;

let message_hash = *transaction.message_hash();
let is_simple_vote_tx = transaction.is_simple_vote_transaction();

SanitizedTransaction::try_new(
sanitized_versioned_transaction,
message_hash,
is_simple_vote_tx,
bank,
)
}

// Need to filter out transactions since they were sanitized earlier.
// This means that the transaction may cross and epoch boundary (not allowed),
// or account lookup tables may have been closed.
Expand All @@ -413,12 +436,16 @@ impl Consumer {
.map(|(tx, max_slot_age)| {
if *max_slot_age < bank.slot() {
// Attempt re-sanitization after epoch-cross.
// Only need to verify pre-compiles.
tx.verify_precompiles(&bank.feature_set)?;
}
let lookup_tables = tx.message().message_address_table_lookups();
if !lookup_tables.is_empty() {
bank.load_addresses(lookup_tables)?;
// Re-sanitized transaction should be equal to the original transaction,
// but whether it will pass sanitization needs to be checked.
resanitize(tx, bank)?;
} else {
// Any transaction executed between sanitization time and now may have closed the lookup table(s).
// Above re-sanitization already loads addresses, so don't need to re-check in that case.
let lookup_tables = tx.message().message_address_table_lookups();
if !lookup_tables.is_empty() {
bank.load_addresses(lookup_tables)?;
}
}
Ok(())
})
Expand Down

0 comments on commit ca20a5e

Please sign in to comment.