From bc243f9c4f312f8c688922920bbab0e8501c08c4 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 15 Aug 2024 09:52:01 -0500 Subject: [PATCH 1/2] 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 cd85ad9bc60a00..aadd5f24c6fb03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5523,6 +5523,7 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ + "agave-transaction-view", "ahash 0.8.10", "assert_matches", "bincode", @@ -7310,6 +7311,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 2eb876219da96a..8476724265738d 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 512aff5dc21cb6..45425c40849375 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" @@ -4540,6 +4548,7 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ + "agave-transaction-view", "ahash 0.8.10", "bincode", "blake3", @@ -5655,6 +5664,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 44d291725b7419..6b48a7d2f50730 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)] From ff011e07e4a29805c68b5a0b3971d370d14d05f0 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 16 Aug 2024 07:34:49 -0500 Subject: [PATCH 2/2] Use the svm-transaction atl type --- Cargo.lock | 2 -- accounts-db/Cargo.toml | 1 - accounts-db/src/accounts.rs | 15 ++++++------- programs/sbf/Cargo.lock | 10 --------- runtime/Cargo.toml | 1 - runtime/src/bank/address_lookup_table.rs | 8 +++---- .../src/address_table_lookup_meta.rs | 21 ------------------- 7 files changed, 12 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aadd5f24c6fb03..cd85ad9bc60a00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5523,7 +5523,6 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ - "agave-transaction-view", "ahash 0.8.10", "assert_matches", "bincode", @@ -7311,7 +7310,6 @@ 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 8476724265738d..2eb876219da96a 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -10,7 +10,6 @@ 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 aae55178afccf5..eb416c29e2f4e9 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -9,7 +9,6 @@ use { ancestors::Ancestors, storable_accounts::StorableAccounts, }, - agave_transaction_view::address_table_lookup_meta::MessageAddressTableLookupRef, dashmap::DashMap, log::*, solana_sdk::{ @@ -22,7 +21,9 @@ use { transaction::{Result, SanitizedTransaction}, transaction_context::TransactionAccount, }, - solana_svm_transaction::svm_message::SVMMessage, + solana_svm_transaction::{ + message_address_table_lookup::SVMMessageAddressTableLookup, svm_message::SVMMessage, + }, std::{ cmp::Reverse, collections::{BinaryHeap, HashSet}, @@ -83,7 +84,7 @@ impl Accounts { pub fn load_lookup_table_addresses( &self, ancestors: &Ancestors, - address_table_lookup: MessageAddressTableLookupRef, + address_table_lookup: SVMMessageAddressTableLookup, slot_hashes: &SlotHashes, ) -> std::result::Result { let table_account = self @@ -709,7 +710,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - MessageAddressTableLookupRef::from(&address_table_lookup), + SVMMessageAddressTableLookup::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::LookupTableAccountNotFound), @@ -736,7 +737,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - MessageAddressTableLookupRef::from(&address_table_lookup), + SVMMessageAddressTableLookup::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::InvalidAccountOwner), @@ -763,7 +764,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - MessageAddressTableLookupRef::from(&address_table_lookup), + SVMMessageAddressTableLookup::from(&address_table_lookup), &SlotHashes::default(), ), Err(AddressLookupError::InvalidAccountData), @@ -802,7 +803,7 @@ mod tests { assert_eq!( accounts.load_lookup_table_addresses( &ancestors, - MessageAddressTableLookupRef::from(&address_table_lookup), + SVMMessageAddressTableLookup::from(&address_table_lookup), &SlotHashes::default(), ), Ok(LoadedAddresses { diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 45425c40849375..512aff5dc21cb6 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -73,14 +73,6 @@ 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" @@ -4548,7 +4540,6 @@ dependencies = [ name = "solana-accounts-db" version = "2.1.0" dependencies = [ - "agave-transaction-view", "ahash 0.8.10", "bincode", "blake3", @@ -5664,7 +5655,6 @@ 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 6b48a7d2f50730..44d291725b7419 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -10,7 +10,6 @@ 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 d31547144dbeef..4fa4e2bc0f570a 100644 --- a/runtime/src/bank/address_lookup_table.rs +++ b/runtime/src/bank/address_lookup_table.rs @@ -1,6 +1,5 @@ use { super::Bank, - agave_transaction_view::address_table_lookup_meta::MessageAddressTableLookupRef, solana_sdk::{ address_lookup_table::error::AddressLookupError, message::{ @@ -9,6 +8,7 @@ use { }, transaction::AddressLoader, }, + solana_svm_transaction::message_address_table_lookup::SVMMessageAddressTableLookup, }; fn into_address_loader_error(err: AddressLookupError) -> AddressLoaderError { @@ -30,16 +30,16 @@ impl AddressLoader for &Bank { self.load_addresses_from_ref( address_table_lookups .iter() - .map(MessageAddressTableLookupRef::from), + .map(SVMMessageAddressTableLookup::from), ) } } impl Bank { - /// Load addresses from an iterator of `MessageAddressTableLookupRef`. + /// Load addresses from an iterator of `SVMMessageAddressTableLookup`. pub fn load_addresses_from_ref<'a>( &self, - address_table_lookups: impl Iterator>, + address_table_lookups: impl Iterator>, ) -> Result { let slot_hashes = self .transaction_processor diff --git a/transaction-view/src/address_table_lookup_meta.rs b/transaction-view/src/address_table_lookup_meta.rs index 1d32fdc957d19b..28ecc67adc51ed 100644 --- a/transaction-view/src/address_table_lookup_meta.rs +++ b/transaction-view/src/address_table_lookup_meta.rs @@ -103,27 +103,6 @@ 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 {