Skip to content

Commit

Permalink
Review feedback. Refactor common code.
Browse files Browse the repository at this point in the history
Co-authored-by: Lijun Wang <[email protected]>
  • Loading branch information
fkouteib and lijunwangs committed Oct 17, 2024
1 parent e312784 commit 2b0e46f
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2892,30 +2892,55 @@ 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<Item = (&'a Pubkey, bool)>,
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)?;
self.transaction_status_cf
.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<Item = (&'a Pubkey, bool)>,
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,
Expand Down

0 comments on commit 2b0e46f

Please sign in to comment.