Refactor: Add trait for loading addresses (#22903)
This commit is contained in:
@ -109,10 +109,7 @@ use {
|
||||
inflation::Inflation,
|
||||
instruction::CompiledInstruction,
|
||||
lamports::LamportsError,
|
||||
message::{
|
||||
v0::{LoadedAddresses, MessageAddressTableLookup},
|
||||
SanitizedMessage,
|
||||
},
|
||||
message::SanitizedMessage,
|
||||
native_loader,
|
||||
native_token::sol_to_lamports,
|
||||
nonce, nonce_account,
|
||||
@ -127,7 +124,7 @@ use {
|
||||
sysvar::{self, Sysvar, SysvarId},
|
||||
timing::years_as_slots,
|
||||
transaction::{
|
||||
AddressLookupError, Result, SanitizedTransaction, Transaction, TransactionError,
|
||||
Result, SanitizedTransaction, Transaction, TransactionError,
|
||||
TransactionVerificationMode, VersionedTransaction,
|
||||
},
|
||||
transaction_context::{InstructionTrace, TransactionAccount, TransactionContext},
|
||||
@ -157,6 +154,7 @@ use {
|
||||
},
|
||||
};
|
||||
|
||||
mod address_lookup_table;
|
||||
mod sysvar_cache;
|
||||
mod transaction_account_state_info;
|
||||
|
||||
@ -3393,9 +3391,7 @@ impl Bank {
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
let message_hash = tx.message.hash();
|
||||
SanitizedTransaction::try_create(tx, message_hash, None, |_| {
|
||||
Err(TransactionError::UnsupportedVersion)
|
||||
})
|
||||
SanitizedTransaction::try_create(tx, message_hash, None, self)
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let lock_results = self
|
||||
@ -3796,33 +3792,6 @@ impl Bank {
|
||||
Arc::make_mut(&mut cache).remove(pubkey);
|
||||
}
|
||||
|
||||
pub fn load_lookup_table_addresses(
|
||||
&self,
|
||||
address_table_lookups: &[MessageAddressTableLookup],
|
||||
) -> Result<LoadedAddresses> {
|
||||
if !self.versioned_tx_message_enabled() {
|
||||
return Err(TransactionError::UnsupportedVersion);
|
||||
}
|
||||
|
||||
let slot_hashes = self
|
||||
.sysvar_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_slot_hashes()
|
||||
.map_err(|_| TransactionError::AccountNotFound)?;
|
||||
|
||||
Ok(address_table_lookups
|
||||
.iter()
|
||||
.map(|address_table_lookup| {
|
||||
self.rc.accounts.load_lookup_table_addresses(
|
||||
&self.ancestors,
|
||||
address_table_lookup,
|
||||
&slot_hashes,
|
||||
)
|
||||
})
|
||||
.collect::<std::result::Result<_, AddressLookupError>>()?)
|
||||
}
|
||||
|
||||
/// Execute a transaction using the provided loaded accounts and update
|
||||
/// the executors cache if the transaction was successful.
|
||||
fn execute_loaded_transaction(
|
||||
@ -5760,9 +5729,7 @@ impl Bank {
|
||||
tx.message.hash()
|
||||
};
|
||||
|
||||
SanitizedTransaction::try_create(tx, message_hash, None, |lookups| {
|
||||
self.load_lookup_table_addresses(lookups)
|
||||
})
|
||||
SanitizedTransaction::try_create(tx, message_hash, None, self)
|
||||
}?;
|
||||
|
||||
if verification_mode == TransactionVerificationMode::HashAndVerifyPrecompiles
|
||||
|
38
runtime/src/bank/address_lookup_table.rs
Normal file
38
runtime/src/bank/address_lookup_table.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use {
|
||||
super::Bank,
|
||||
solana_sdk::{
|
||||
message::v0::{LoadedAddresses, MessageAddressTableLookup},
|
||||
transaction::{
|
||||
AddressLoader, AddressLookupError, Result as TransactionResult, TransactionError,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
impl AddressLoader for Bank {
|
||||
fn load_addresses(
|
||||
&self,
|
||||
address_table_lookups: &[MessageAddressTableLookup],
|
||||
) -> TransactionResult<LoadedAddresses> {
|
||||
if !self.versioned_tx_message_enabled() {
|
||||
return Err(TransactionError::UnsupportedVersion);
|
||||
}
|
||||
|
||||
let slot_hashes = self
|
||||
.sysvar_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_slot_hashes()
|
||||
.map_err(|_| TransactionError::AccountNotFound)?;
|
||||
|
||||
Ok(address_table_lookups
|
||||
.iter()
|
||||
.map(|address_table_lookup| {
|
||||
self.rc.accounts.load_lookup_table_addresses(
|
||||
&self.ancestors,
|
||||
address_table_lookup,
|
||||
&slot_hashes,
|
||||
)
|
||||
})
|
||||
.collect::<Result<_, AddressLookupError>>()?)
|
||||
}
|
||||
}
|
@ -236,7 +236,7 @@ mod tests {
|
||||
hash::Hash,
|
||||
signature::{Keypair, Signer},
|
||||
system_transaction,
|
||||
transaction::{TransactionError, VersionedTransaction},
|
||||
transaction::{DisabledAddressLoader, VersionedTransaction},
|
||||
},
|
||||
solana_vote_program::vote_transaction,
|
||||
std::{cmp, sync::Arc},
|
||||
@ -285,7 +285,7 @@ mod tests {
|
||||
VersionedTransaction::from(transaction),
|
||||
message_hash,
|
||||
Some(true),
|
||||
|_| Err(TransactionError::UnsupportedVersion),
|
||||
&DisabledAddressLoader,
|
||||
)
|
||||
.unwrap();
|
||||
(vote_transaction, vec![mint_keypair.pubkey()], 10)
|
||||
|
Reference in New Issue
Block a user