From 2b0e46f18aa4e5e4076d64dc5315d9c75866f18f Mon Sep 17 00:00:00 2001 From: Faycel Kouteib Date: Wed, 16 Oct 2024 18:09:53 -0700 Subject: [PATCH] Review feedback. Refactor common code. Co-authored-by: Lijun Wang <83639177+lijunwangs@users.noreply.github.com> --- ledger/src/blockstore.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index bc29b372b4077b..c07db76536de16 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -2892,14 +2892,19 @@ impl Blockstore { } } - pub fn write_transaction_status<'a>( + #[inline] + fn write_transaction_status_helper<'a, F>( &self, slot: Slot, signature: Signature, keys_with_writable: impl Iterator, status: TransactionStatusMeta, transaction_index: usize, - ) -> Result<()> { + mut write_fn: F, + ) -> Result<()> + where + F: FnMut(&Pubkey, Slot, u32, Signature, bool) -> Result<()>, + { let status = status.into(); let transaction_index = u32::try_from(transaction_index) .map_err(|_| BlockstoreError::TransactionIndexOverflow)?; @@ -2907,15 +2912,35 @@ impl Blockstore { .put_protobuf((signature, slot), &status)?; for (address, writeable) in keys_with_writable { - self.address_signatures_cf.put( - (*address, slot, transaction_index, signature), - &AddressSignatureMeta { writeable }, - )?; + write_fn(address, slot, transaction_index, signature, writeable)?; } Ok(()) } + pub fn write_transaction_status<'a>( + &self, + slot: Slot, + signature: Signature, + keys_with_writable: impl Iterator, + status: TransactionStatusMeta, + transaction_index: usize, + ) -> Result<()> { + self.write_transaction_status_helper( + slot, + signature, + keys_with_writable, + status, + transaction_index, + |address, slot, tx_index, signature, writeable| { + self.address_signatures_cf.put( + (*address, slot, tx_index, signature), + &AddressSignatureMeta { writeable }, + ) + }, + ) + } + pub fn add_transaction_status_to_batch<'a>( &self, slot: Slot,