diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index 9033ceea6e6da5..a0eabb70fa03f1 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -15,7 +15,7 @@ use { account::{AccountSharedData, ReadableAccount}, address_lookup_table::{self, error::AddressLookupError, state::AddressLookupTable}, clock::{BankId, Slot}, - message::v0::{LoadedAddresses, MessageAddressTableLookup}, + message::{v0::LoadedAddresses, MessageAddressTableLookupRef}, pubkey::Pubkey, slot_hashes::SlotHashes, transaction::{Result, SanitizedTransaction}, @@ -82,12 +82,12 @@ impl Accounts { pub fn load_lookup_table_addresses( &self, ancestors: &Ancestors, - address_table_lookup: &MessageAddressTableLookup, + address_table_lookup: MessageAddressTableLookupRef, slot_hashes: &SlotHashes, ) -> std::result::Result { let table_account = self .accounts_db - .load_with_fixed_root(ancestors, &address_table_lookup.account_key) + .load_with_fixed_root(ancestors, address_table_lookup.account_key) .map(|(account, _rent)| account) .ok_or(AddressLookupError::LookupTableAccountNotFound)?; @@ -99,12 +99,12 @@ impl Accounts { Ok(LoadedAddresses { writable: lookup_table.lookup( current_slot, - &address_table_lookup.writable_indexes, + address_table_lookup.writable_indexes, slot_hashes, )?, readonly: lookup_table.lookup( current_slot, - &address_table_lookup.readonly_indexes, + address_table_lookup.readonly_indexes, slot_hashes, )?, }) @@ -611,7 +611,7 @@ mod tests { address_lookup_table::state::LookupTableMeta, hash::Hash, instruction::CompiledInstruction, - message::{Message, MessageHeader}, + message::{v0::MessageAddressTableLookup, Message, MessageHeader}, native_loader, signature::{signers::Signers, Keypair, Signer}, transaction::{Transaction, TransactionError, MAX_TX_ACCOUNT_LOCKS}, @@ -708,7 +708,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - &address_table_lookup, + MessageAddressTableLookupRef::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::LookupTableAccountNotFound), @@ -735,7 +735,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - &address_table_lookup, + MessageAddressTableLookupRef::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::InvalidAccountOwner), @@ -762,7 +762,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - &address_table_lookup, + MessageAddressTableLookupRef::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::InvalidAccountData), @@ -801,7 +801,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - &address_table_lookup, + MessageAddressTableLookupRef::from(&address_table_lookup), &SlotHashes::default(), ), Ok(LoadedAddresses { diff --git a/runtime/src/bank/address_lookup_table.rs b/runtime/src/bank/address_lookup_table.rs index 344f1e8bdf09aa..dcda0e92a3859e 100644 --- a/runtime/src/bank/address_lookup_table.rs +++ b/runtime/src/bank/address_lookup_table.rs @@ -2,10 +2,7 @@ use { super::Bank, solana_sdk::{ address_lookup_table::error::AddressLookupError, - message::{ - v0::{LoadedAddresses, MessageAddressTableLookup}, - AddressLoaderError, - }, + message::{v0::LoadedAddresses, AddressLoaderError, MessageAddressTableLookupRef}, transaction::AddressLoader, }, }; @@ -22,9 +19,9 @@ fn into_address_loader_error(err: AddressLookupError) -> AddressLoaderError { } impl AddressLoader for &Bank { - fn load_addresses( + fn load_addresses_ref<'a>( self, - address_table_lookups: &[MessageAddressTableLookup], + address_table_lookups: impl Iterator>, ) -> Result { let slot_hashes = self .transaction_processor @@ -33,7 +30,6 @@ impl AddressLoader for &Bank { .map_err(|_| AddressLoaderError::SlotHashesSysvarNotFound)?; address_table_lookups - .iter() .map(|address_table_lookup| { self.rc .accounts diff --git a/sdk/program/src/message/address_loader.rs b/sdk/program/src/message/address_loader.rs index 83e514cd0bd63b..1b6db6326b534f 100644 --- a/sdk/program/src/message/address_loader.rs +++ b/sdk/program/src/message/address_loader.rs @@ -1,5 +1,6 @@ use { super::v0::{LoadedAddresses, MessageAddressTableLookup}, + crate::pubkey::Pubkey, thiserror::Error, }; @@ -30,10 +31,34 @@ pub enum AddressLoaderError { InvalidLookupIndex, } +/// A non-owning version of `MessageAddressTableLookup`. +pub struct MessageAddressTableLookupRef<'a> { + pub account_key: &'a Pubkey, + pub writable_indexes: &'a [u8], + pub readonly_indexes: &'a [u8], +} + +impl<'a> From<&'a MessageAddressTableLookup> for MessageAddressTableLookupRef<'a> { + fn from(lookup: &'a MessageAddressTableLookup) -> Self { + Self { + account_key: &lookup.account_key, + writable_indexes: &lookup.writable_indexes, + readonly_indexes: &lookup.readonly_indexes, + } + } +} + pub trait AddressLoader: Clone { fn load_addresses( self, lookups: &[MessageAddressTableLookup], + ) -> Result { + self.load_addresses_ref(lookups.iter().map(MessageAddressTableLookupRef::from)) + } + + fn load_addresses_ref<'a>( + self, + lookups: impl Iterator>, ) -> Result; } @@ -44,9 +69,9 @@ pub enum SimpleAddressLoader { } impl AddressLoader for SimpleAddressLoader { - fn load_addresses( + fn load_addresses_ref<'a>( self, - _lookups: &[MessageAddressTableLookup], + _lookups: impl Iterator>, ) -> Result { match self { Self::Disabled => Err(AddressLoaderError::Disabled), diff --git a/svm/tests/transaction_builder.rs b/svm/tests/transaction_builder.rs index 803487773a63ec..bb16e83a3230a3 100644 --- a/svm/tests/transaction_builder.rs +++ b/svm/tests/transaction_builder.rs @@ -3,8 +3,9 @@ use { hash::Hash, instruction::{AccountMeta, CompiledInstruction}, message::{ - v0::{self, LoadedAddresses, MessageAddressTableLookup}, - AddressLoader, AddressLoaderError, Message, MessageHeader, VersionedMessage, + v0::{self, LoadedAddresses}, + AddressLoader, AddressLoaderError, Message, MessageAddressTableLookupRef, + MessageHeader, VersionedMessage, }, pubkey::Pubkey, reserved_account_keys::ReservedAccountKeys, @@ -48,9 +49,9 @@ struct MockLoader {} // This implementation is only necessary if one is using account table lookups. impl AddressLoader for MockLoader { - fn load_addresses( + fn load_addresses_ref<'a>( self, - _lookups: &[MessageAddressTableLookup], + _lookups: impl Iterator>, ) -> Result { Ok(LoadedAddresses { writable: vec![],