From 969017e4f5df89efc0fb495aeb24497bd8d92c7f Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 15 Aug 2024 09:52:01 -0500 Subject: [PATCH] Bank::load_addresses_from_ref --- Cargo.lock | 2 ++ accounts-db/Cargo.toml | 1 + accounts-db/src/accounts.rs | 21 ++++++++++--------- programs/sbf/Cargo.lock | 10 +++++++++ runtime/Cargo.toml | 1 + runtime/src/bank/address_lookup_table.rs | 16 +++++++++++++- .../src/address_table_lookup_meta.rs | 21 +++++++++++++++++++ transaction-view/src/lib.rs | 2 +- 8 files changed, 62 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12d05d7a2de96b..cc857bdee93174 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5541,6 +5541,7 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ + "agave-transaction-view", "ahash 0.8.10", "assert_matches", "bincode", @@ -7324,6 +7325,7 @@ dependencies = [ name = "solana-runtime" version = "2.1.0" dependencies = [ + "agave-transaction-view", "aquamarine", "arrayref", "assert_matches", diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 8a6d7e4d32160a..0157b76693760e 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -10,6 +10,7 @@ license = { workspace = true } edition = { workspace = true } [dependencies] +agave-transaction-view = { workspace = true } ahash = { workspace = true } bincode = { workspace = true } blake3 = { workspace = true } diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index 9033ceea6e6da5..aae55178afccf5 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -9,13 +9,14 @@ use { ancestors::Ancestors, storable_accounts::StorableAccounts, }, + agave_transaction_view::address_table_lookup_meta::MessageAddressTableLookupRef, dashmap::DashMap, log::*, solana_sdk::{ account::{AccountSharedData, ReadableAccount}, address_lookup_table::{self, error::AddressLookupError, state::AddressLookupTable}, clock::{BankId, Slot}, - message::v0::{LoadedAddresses, MessageAddressTableLookup}, + message::v0::LoadedAddresses, pubkey::Pubkey, slot_hashes::SlotHashes, transaction::{Result, SanitizedTransaction}, @@ -82,12 +83,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 +100,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 +612,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 +709,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 +736,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 +763,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 +802,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/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 829ec1e3bcbb1f..3f9986c0f8b065 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -73,6 +73,14 @@ dependencies = [ "thiserror", ] +[[package]] +name = "agave-transaction-view" +version = "2.1.0" +dependencies = [ + "solana-sdk", + "solana-svm-transaction", +] + [[package]] name = "agave-validator" version = "2.1.0" @@ -4546,6 +4554,7 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ + "agave-transaction-view", "ahash 0.8.10", "bincode", "blake3", @@ -5659,6 +5668,7 @@ dependencies = [ name = "solana-runtime" version = "2.1.0" dependencies = [ + "agave-transaction-view", "aquamarine", "arrayref", "base64 0.22.1", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b5df2c8bcded91..323934c01a82f4 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -10,6 +10,7 @@ license = { workspace = true } edition = { workspace = true } [dependencies] +agave-transaction-view = { workspace = true } aquamarine = { workspace = true } arrayref = { workspace = true } base64 = { workspace = true } diff --git a/runtime/src/bank/address_lookup_table.rs b/runtime/src/bank/address_lookup_table.rs index 344f1e8bdf09aa..d31547144dbeef 100644 --- a/runtime/src/bank/address_lookup_table.rs +++ b/runtime/src/bank/address_lookup_table.rs @@ -1,5 +1,6 @@ use { super::Bank, + agave_transaction_view::address_table_lookup_meta::MessageAddressTableLookupRef, solana_sdk::{ address_lookup_table::error::AddressLookupError, message::{ @@ -25,6 +26,20 @@ impl AddressLoader for &Bank { fn load_addresses( self, address_table_lookups: &[MessageAddressTableLookup], + ) -> Result { + self.load_addresses_from_ref( + address_table_lookups + .iter() + .map(MessageAddressTableLookupRef::from), + ) + } +} + +impl Bank { + /// Load addresses from an iterator of `MessageAddressTableLookupRef`. + pub fn load_addresses_from_ref<'a>( + &self, + address_table_lookups: impl Iterator>, ) -> Result { let slot_hashes = self .transaction_processor @@ -33,7 +48,6 @@ impl AddressLoader for &Bank { .map_err(|_| AddressLoaderError::SlotHashesSysvarNotFound)?; address_table_lookups - .iter() .map(|address_table_lookup| { self.rc .accounts diff --git a/transaction-view/src/address_table_lookup_meta.rs b/transaction-view/src/address_table_lookup_meta.rs index 28ecc67adc51ed..1d32fdc957d19b 100644 --- a/transaction-view/src/address_table_lookup_meta.rs +++ b/transaction-view/src/address_table_lookup_meta.rs @@ -103,6 +103,27 @@ impl AddressTableLookupMeta { } } +/// 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], +} + +// Convenience function to convert a `MessageAddressTableLookup` to a +// `MessageAddressTableLookupRef`. +impl<'a> From<&'a solana_sdk::message::v0::MessageAddressTableLookup> + for MessageAddressTableLookupRef<'a> +{ + fn from(atl: &'a solana_sdk::message::v0::MessageAddressTableLookup) -> Self { + Self { + account_key: &atl.account_key, + writable_indexes: &atl.writable_indexes, + readonly_indexes: &atl.readonly_indexes, + } + } +} + #[cfg(test)] mod tests { use { diff --git a/transaction-view/src/lib.rs b/transaction-view/src/lib.rs index 40cea3da25393c..baa3b91b84ef15 100644 --- a/transaction-view/src/lib.rs +++ b/transaction-view/src/lib.rs @@ -5,7 +5,7 @@ pub mod bytes; mod bytes; #[allow(dead_code)] -mod address_table_lookup_meta; +pub mod address_table_lookup_meta; #[allow(dead_code)] mod instructions_meta; #[allow(dead_code)]