diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index bc29b372b4077b..07d9a6d0cb5404 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, @@ -2925,20 +2950,19 @@ impl Blockstore { transaction_index: usize, db_write_batch: &mut WriteBatch<'_>, ) -> Result<()> { - let status = status.into(); - let transaction_index = u32::try_from(transaction_index) - .map_err(|_| BlockstoreError::TransactionIndexOverflow)?; - self.transaction_status_cf - .put_protobuf((signature, slot), &status)?; - - for (address, writeable) in keys_with_writable { - db_write_batch.put::( - (*address, slot, transaction_index, signature), - &AddressSignatureMeta { writeable }, - )?; - } - - Ok(()) + self.write_transaction_status_helper( + slot, + signature, + keys_with_writable, + status, + transaction_index, + |address, slot, tx_index, signature, writeable| { + db_write_batch.put::( + (*address, slot, tx_index, signature), + &AddressSignatureMeta { writeable }, + ) + }, + ) } pub fn read_transaction_memos(