Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddressLoader: allow for non-owned MessageAddressTableLookup #2592

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ use {
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},
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},
Expand Down Expand Up @@ -82,12 +84,12 @@ impl Accounts {
pub fn load_lookup_table_addresses(
&self,
ancestors: &Ancestors,
address_table_lookup: &MessageAddressTableLookup,
address_table_lookup: SVMMessageAddressTableLookup,
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 +101,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 +613,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 +710,7 @@ mod tests {
assert_eq!(
accounts.load_lookup_table_addresses(
&ancestors,
&address_table_lookup,
SVMMessageAddressTableLookup::from(&address_table_lookup),
&SlotHashes::default(),
),
Err(AddressLookupError::LookupTableAccountNotFound),
Expand All @@ -735,7 +737,7 @@ mod tests {
assert_eq!(
accounts.load_lookup_table_addresses(
&ancestors,
&address_table_lookup,
SVMMessageAddressTableLookup::from(&address_table_lookup),
&SlotHashes::default(),
),
Err(AddressLookupError::InvalidAccountOwner),
Expand All @@ -762,7 +764,7 @@ mod tests {
assert_eq!(
accounts.load_lookup_table_addresses(
&ancestors,
&address_table_lookup,
SVMMessageAddressTableLookup::from(&address_table_lookup),
&SlotHashes::default(),
),
Err(AddressLookupError::InvalidAccountData),
Expand Down Expand Up @@ -801,7 +803,7 @@ mod tests {
assert_eq!(
accounts.load_lookup_table_addresses(
&ancestors,
&address_table_lookup,
SVMMessageAddressTableLookup::from(&address_table_lookup),
&SlotHashes::default(),
),
Ok(LoadedAddresses {
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
Expand Up @@ -8,6 +8,7 @@ use {
},
transaction::AddressLoader,
},
solana_svm_transaction::message_address_table_lookup::SVMMessageAddressTableLookup,
};

fn into_address_loader_error(err: AddressLookupError) -> AddressLoaderError {
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(SVMMessageAddressTableLookup::from),
)
}
}

impl Bank {
/// Load addresses from an iterator of `SVMMessageAddressTableLookup`.
pub fn load_addresses_from_ref<'a>(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't even need a trait - this is just a function on Bank. We will/can use this for resolving our transactions inside core/runtime.

&self,
address_table_lookups: impl Iterator<Item = SVMMessageAddressTableLookup<'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
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