Skip to content

Commit

Permalink
Add runtime support for address table lookups (backport solana-labs#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 7, 2022
1 parent 8214bc9 commit 90498fb
Show file tree
Hide file tree
Showing 21 changed files with 663 additions and 159 deletions.
8 changes: 7 additions & 1 deletion accountsdb-plugin-postgres/scripts/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ Create TYPE "TransactionErrorCode" AS ENUM (
'WouldExceedMaxBlockCostLimit',
'UnsupportedVersion',
'InvalidWritableAccount',
'WouldExceedMaxAccountDataCostLimit'
'WouldExceedMaxAccountDataCostLimit',
'TooManyAccountLocks',
'AddressLookupError'
'AddressLookupTableNotFound',
'InvalidAddressLookupTableOwner',
'InvalidAddressLookupTableData',
'InvalidAddressLookupTableIndex'
);

CREATE TYPE "TransactionError" AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ pub enum DbTransactionErrorCode {
InvalidWritableAccount,
WouldExceedMaxAccountDataCostLimit,
TooManyAccountLocks,
AddressLookupTableNotFound,
InvalidAddressLookupTableOwner,
InvalidAddressLookupTableData,
InvalidAddressLookupTableIndex,
}

impl From<&TransactionError> for DbTransactionErrorCode {
Expand Down Expand Up @@ -364,6 +368,14 @@ impl From<&TransactionError> for DbTransactionErrorCode {
Self::WouldExceedMaxAccountDataCostLimit
}
TransactionError::TooManyAccountLocks => Self::TooManyAccountLocks,
TransactionError::AddressLookupTableNotFound => Self::AddressLookupTableNotFound,
TransactionError::InvalidAddressLookupTableOwner => {
Self::InvalidAddressLookupTableOwner
}
TransactionError::InvalidAddressLookupTableData => Self::InvalidAddressLookupTableData,
TransactionError::InvalidAddressLookupTableIndex => {
Self::InvalidAddressLookupTableIndex
}
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ use {
MAX_TRANSACTION_FORWARDING_DELAY_GPU,
},
feature_set,
message::Message,
message::{
v0::{LoadedAddresses, MessageAddressTableLookup},
Message,
},
pubkey::Pubkey,
short_vec::decode_shortu16_len,
signature::Signature,
Expand Down Expand Up @@ -1123,6 +1126,7 @@ impl BankingStage {
transaction_indexes: &[usize],
feature_set: &Arc<feature_set::FeatureSet>,
votes_only: bool,
address_loader: impl Fn(&[MessageAddressTableLookup]) -> transaction::Result<LoadedAddresses>,
) -> (Vec<SanitizedTransaction>, Vec<usize>) {
transaction_indexes
.iter()
Expand All @@ -1139,7 +1143,7 @@ impl BankingStage {
tx,
message_hash,
Some(p.meta.is_simple_vote_tx()),
|_| Err(TransactionError::UnsupportedVersion),
&address_loader,
)
.ok()?;
tx.verify_precompiles(feature_set).ok()?;
Expand Down Expand Up @@ -1205,6 +1209,7 @@ impl BankingStage {
&packet_indexes,
&bank.feature_set,
bank.vote_only_bank(),
|lookup| bank.load_lookup_table_addresses(lookup),
);
packet_conversion_time.stop();
inc_new_counter_info!("banking_stage-packet_conversion", 1);
Expand Down Expand Up @@ -1279,6 +1284,7 @@ impl BankingStage {
transaction_indexes,
&bank.feature_set,
bank.vote_only_bank(),
|lookup| bank.load_lookup_table_addresses(lookup),
);
unprocessed_packet_conversion_time.stop();

Expand Down Expand Up @@ -3228,6 +3234,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(2, txs.len());
assert_eq!(vec![0, 1], tx_packet_index);
Expand All @@ -3238,6 +3245,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(0, txs.len());
assert_eq!(0, tx_packet_index.len());
Expand All @@ -3257,6 +3265,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(3, txs.len());
assert_eq!(vec![0, 1, 2], tx_packet_index);
Expand All @@ -3267,6 +3276,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(2, txs.len());
assert_eq!(vec![0, 2], tx_packet_index);
Expand All @@ -3286,6 +3296,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(3, txs.len());
assert_eq!(vec![0, 1, 2], tx_packet_index);
Expand All @@ -3296,6 +3307,7 @@ mod tests {
&packet_indexes,
&Arc::new(FeatureSet::default()),
votes_only,
|_| Err(TransactionError::UnsupportedVersion),
);
assert_eq!(3, txs.len());
assert_eq!(vec![0, 1, 2], tx_packet_index);
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ impl Blockstore {
if let Some(&signature) = transaction.signatures.get(0) {
batch.delete::<cf::TransactionStatus>((0, signature, slot))?;
batch.delete::<cf::TransactionStatus>((1, signature, slot))?;
// TODO: support purging mapped addresses from versioned transactions
for pubkey in transaction.message.unmapped_keys() {
// TODO: support purging dynamically loaded addresses from versioned transactions
for pubkey in transaction.message.into_static_account_keys() {
batch.delete::<cf::AddressSignatures>((0, pubkey, slot, signature))?;
batch.delete::<cf::AddressSignatures>((1, pubkey, slot, signature))?;
}
Expand Down
Loading

0 comments on commit 90498fb

Please sign in to comment.