From 925a603f0a253d6dc98e613f2b44193ecddc762c Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Tue, 20 Aug 2024 08:48:28 -0500 Subject: [PATCH] transaction_status_service: remove get_account_locks_unchecked (#2555) --- ledger/src/blockstore.rs | 56 +++++++++++------------ ledger/src/blockstore/blockstore_purge.rs | 21 ++++++--- rpc/src/transaction_status_service.rs | 11 +++-- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index b5bca01a8b2078..2101896d9a0558 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2879,12 +2879,11 @@ impl Blockstore { } } - pub fn write_transaction_status( + pub fn write_transaction_status<'a>( &self, slot: Slot, signature: Signature, - writable_keys: Vec<&Pubkey>, - readonly_keys: Vec<&Pubkey>, + keys_with_writable: impl Iterator, status: TransactionStatusMeta, transaction_index: usize, ) -> Result<()> { @@ -2893,18 +2892,14 @@ impl Blockstore { .map_err(|_| BlockstoreError::TransactionIndexOverflow)?; self.transaction_status_cf .put_protobuf((signature, slot), &status)?; - for address in writable_keys { - self.address_signatures_cf.put( - (*address, slot, transaction_index, signature), - &AddressSignatureMeta { writeable: true }, - )?; - } - for address in readonly_keys { + + for (address, writeable) in keys_with_writable { self.address_signatures_cf.put( (*address, slot, transaction_index, signature), - &AddressSignatureMeta { writeable: false }, + &AddressSignatureMeta { writeable }, )?; } + Ok(()) } @@ -8684,8 +8679,11 @@ pub mod tests { .write_transaction_status( slot, signature, - vec![&Pubkey::new_unique()], - vec![&Pubkey::new_unique()], + vec![ + (&Pubkey::new_unique(), true), + (&Pubkey::new_unique(), false), + ] + .into_iter(), TransactionStatusMeta { fee: slot * 1_000, ..TransactionStatusMeta::default() @@ -9072,8 +9070,7 @@ pub mod tests { .write_transaction_status( lowest_cleanup_slot, signature1, - vec![&address0], - vec![], + vec![(&address0, true)].into_iter(), TransactionStatusMeta::default(), 0, ) @@ -9082,8 +9079,7 @@ pub mod tests { .write_transaction_status( lowest_available_slot, signature2, - vec![&address1], - vec![], + vec![(&address1, true)].into_iter(), TransactionStatusMeta::default(), 0, ) @@ -9451,8 +9447,7 @@ pub mod tests { .write_transaction_status( slot1, signature, - vec![&address0], - vec![&address1], + vec![(&address0, true), (&address1, false)].into_iter(), TransactionStatusMeta::default(), x as usize, ) @@ -9465,8 +9460,7 @@ pub mod tests { .write_transaction_status( slot2, signature, - vec![&address0], - vec![&address1], + vec![(&address0, true), (&address1, false)].into_iter(), TransactionStatusMeta::default(), x as usize, ) @@ -9478,8 +9472,7 @@ pub mod tests { .write_transaction_status( slot2, signature, - vec![&address0], - vec![&address1], + vec![(&address0, true), (&address1, false)].into_iter(), TransactionStatusMeta::default(), x as usize, ) @@ -9492,8 +9485,7 @@ pub mod tests { .write_transaction_status( slot3, signature, - vec![&address0], - vec![&address1], + vec![(&address0, true), (&address1, false)].into_iter(), TransactionStatusMeta::default(), x as usize, ) @@ -9576,8 +9568,11 @@ pub mod tests { .write_transaction_status( slot, transaction.signatures[0], - transaction.message.static_account_keys().iter().collect(), - vec![], + transaction + .message + .static_account_keys() + .iter() + .map(|key| (key, true)), TransactionStatusMeta::default(), counter, ) @@ -9604,8 +9599,11 @@ pub mod tests { .write_transaction_status( slot, transaction.signatures[0], - transaction.message.static_account_keys().iter().collect(), - vec![], + transaction + .message + .static_account_keys() + .iter() + .map(|key| (key, true)), TransactionStatusMeta::default(), counter, ) diff --git a/ledger/src/blockstore/blockstore_purge.rs b/ledger/src/blockstore/blockstore_purge.rs index d442732303fa2a..b2d79c2bf59672 100644 --- a/ledger/src/blockstore/blockstore_purge.rs +++ b/ledger/src/blockstore/blockstore_purge.rs @@ -582,8 +582,11 @@ pub mod tests { .write_transaction_status( x, Signature::from(random_bytes), - vec![&Pubkey::try_from(&random_bytes[..32]).unwrap()], - vec![&Pubkey::try_from(&random_bytes[32..]).unwrap()], + vec![ + (&Pubkey::try_from(&random_bytes[..32]).unwrap(), true), + (&Pubkey::try_from(&random_bytes[32..]).unwrap(), false), + ] + .into_iter(), TransactionStatusMeta::default(), 0, ) @@ -640,8 +643,11 @@ pub mod tests { .write_transaction_status( x, signature, - vec![&Pubkey::try_from(&random_bytes[..32]).unwrap()], - vec![&Pubkey::try_from(&random_bytes[32..]).unwrap()], + vec![ + (&Pubkey::try_from(&random_bytes[..32]).unwrap(), true), + (&Pubkey::try_from(&random_bytes[32..]).unwrap(), false), + ] + .into_iter(), TransactionStatusMeta::default(), 0, ) @@ -715,8 +721,11 @@ pub mod tests { .write_transaction_status( slot, transaction.signatures[0], - transaction.message.static_account_keys().iter().collect(), - vec![], + transaction + .message + .static_account_keys() + .iter() + .map(|key| (key, true)), TransactionStatusMeta::default(), 0, ) diff --git a/rpc/src/transaction_status_service.rs b/rpc/src/transaction_status_service.rs index 43ce83c0966de6..314f8b9a4f5fda 100644 --- a/rpc/src/transaction_status_service.rs +++ b/rpc/src/transaction_status_service.rs @@ -104,7 +104,6 @@ impl TransactionStatusService { rent_debits, .. } = committed_tx; - let tx_account_locks = transaction.get_account_locks_unchecked(); let fee = fee_details.total_fee(); let inner_instructions = inner_instructions.map(|inner_instructions| { @@ -164,12 +163,18 @@ impl TransactionStatusService { .expect("Expect database write to succeed: TransactionMemos"); } + let message = transaction.message(); + let keys_with_writable = message + .account_keys() + .iter() + .enumerate() + .map(|(index, key)| (key, message.is_writable(index))); + blockstore .write_transaction_status( slot, *transaction.signature(), - tx_account_locks.writable, - tx_account_locks.readonly, + keys_with_writable, transaction_status_meta, transaction_index, )