Skip to content

Commit

Permalink
transaction_status_service: remove get_account_locks_unchecked (anza-…
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored and ray-kast committed Nov 27, 2024
1 parent 24c3f49 commit 4cd23ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
56 changes: 27 additions & 29 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (&'a Pubkey, bool)>,
status: TransactionStatusMeta,
transaction_index: usize,
) -> Result<()> {
Expand All @@ -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(())
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down
21 changes: 15 additions & 6 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
11 changes: 8 additions & 3 deletions rpc/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 4cd23ed

Please sign in to comment.