Skip to content

Commit

Permalink
ScannedLookupTableExtensions struct
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Oct 2, 2023
1 parent d3cc60f commit ae9dcba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
14 changes: 5 additions & 9 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
}
}
});
Expand Down
29 changes: 11 additions & 18 deletions ledger/src/transaction_address_lookup_table_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ lazy_static! {
static ref SDK_IDS_SET: HashSet<Pubkey> = 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<Pubkey>),
/// 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<Pubkey>),
#[derive(Default)]
pub struct ScannedLookupTableExtensions {
pub possibly_incomplete: bool,
pub accounts: Vec<Pubkey>, // 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()
Expand All @@ -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
Expand All @@ -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,
}
}

0 comments on commit ae9dcba

Please sign in to comment.