From ae9dcba6b49be90b5808814e0b42c7e6080ad540 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Mon, 2 Oct 2023 20:58:00 +0000 Subject: [PATCH] ScannedLookupTableExtensions struct --- ledger/src/blockstore.rs | 14 ++++----- ...ransaction_address_lookup_table_scanner.rs | 29 +++++++------------ 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 351159e91ec192..fccb0f4f7aaa44 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -21,7 +21,7 @@ use { Shred, ShredData, ShredId, ShredType, Shredder, }, slot_stats::{ShredSource, SlotsStats}, - transaction_address_lookup_table_scanner::{scan_transaction, ScanResult}, + transaction_address_lookup_table_scanner::scan_transaction, }, assert_matches::debug_assert_matches, bincode::{deserialize, serialize}, @@ -2958,14 +2958,10 @@ impl Blockstore { let tx = SanitizedVersionedTransaction::try_from(tx) .expect("transaction failed to sanitize"); - let alt_scan_result = scan_transaction(&tx); - match alt_scan_result { - ScanResult::NotFound => {} - ScanResult::NativeUsed(keys) => add_to_set(&result, &keys), - ScanResult::NonNativeUsed(keys) => { - add_to_set(&result, &keys); - possible_cpi_alt_extend.store(true, Ordering::Relaxed); - } + let alt_scan_extensions = scan_transaction(&tx); + add_to_set(&result, &alt_scan_extensions.accounts); + if alt_scan_extensions.possibly_incomplete { + possible_cpi_alt_extend.store(true, Ordering::Relaxed); } } }); diff --git a/ledger/src/transaction_address_lookup_table_scanner.rs b/ledger/src/transaction_address_lookup_table_scanner.rs index f21a2c72ff6500..dd51c97f30b031 100644 --- a/ledger/src/transaction_address_lookup_table_scanner.rs +++ b/ledger/src/transaction_address_lookup_table_scanner.rs @@ -14,21 +14,15 @@ lazy_static! { static ref SDK_IDS_SET: HashSet = SDK_IDS.iter().cloned().collect(); } -pub enum ScanResult { - /// The address lookup table program was not used - NotFound, - /// The address lookup table program was present, with non-native programs. - /// If instructions extending an account lookup table were found, the list - /// of Pubkeys will be returned. However, this may be incomplete due to the - /// possibility of non-native ixs CPIing to extend. - NonNativeUsed(Vec), - /// The address lookup table program was present, with only native programs. - /// If instructions extending an account lookup table were found, the list - /// of Pubkeys will be returned. - NativeUsed(Vec), +#[derive(Default)] +pub struct ScannedLookupTableExtensions { + pub possibly_incomplete: bool, + pub accounts: Vec, // empty if no extensions found } -pub fn scan_transaction(transaction: &SanitizedVersionedTransaction) -> ScanResult { +pub fn scan_transaction( + transaction: &SanitizedVersionedTransaction, +) -> ScannedLookupTableExtensions { // If the ALT program is not present in the account keys, it was not used if !transaction .get_message() @@ -37,7 +31,7 @@ pub fn scan_transaction(transaction: &SanitizedVersionedTransaction) -> ScanResu .iter() .any(address_lookup_table::program::check_id) { - return ScanResult::NotFound; + return ScannedLookupTableExtensions::default(); } // Accumulate accounts from account lookup table extension instructions @@ -55,9 +49,8 @@ pub fn scan_transaction(transaction: &SanitizedVersionedTransaction) -> ScanResu } } - if native_only { - ScanResult::NativeUsed(accounts) - } else { - ScanResult::NonNativeUsed(accounts) + ScannedLookupTableExtensions { + possibly_incomplete: !native_only, + accounts, } }