Skip to content

Commit

Permalink
Bank::load_addresses_from_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Aug 15, 2024
1 parent ecb44d7 commit 969017e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
21 changes: 11 additions & 10 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<LoadedAddresses, AddressLookupError> {
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)?;

Expand All @@ -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,
)?,
})
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 15 additions & 1 deletion runtime/src/bank/address_lookup_table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
super::Bank,
agave_transaction_view::address_table_lookup_meta::MessageAddressTableLookupRef,
solana_sdk::{
address_lookup_table::error::AddressLookupError,
message::{
Expand All @@ -25,6 +26,20 @@ impl AddressLoader for &Bank {
fn load_addresses(
self,
address_table_lookups: &[MessageAddressTableLookup],
) -> Result<LoadedAddresses, AddressLoaderError> {
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<Item = MessageAddressTableLookupRef<'a>>,
) -> Result<LoadedAddresses, AddressLoaderError> {
let slot_hashes = self
.transaction_processor
Expand All @@ -33,7 +48,6 @@ impl AddressLoader for &Bank {
.map_err(|_| AddressLoaderError::SlotHashesSysvarNotFound)?;

address_table_lookups
.iter()
.map(|address_table_lookup| {
self.rc
.accounts
Expand Down
21 changes: 21 additions & 0 deletions transaction-view/src/address_table_lookup_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion transaction-view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 969017e

Please sign in to comment.