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 a214b7c
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 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 All @@ -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::<cf::AddressSignatures>(
(*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::<cf::AddressSignatures>(
(*address, slot, tx_index, signature),
&AddressSignatureMeta { writeable },
)
},
)
}

pub fn read_transaction_memos(
Expand Down

0 comments on commit a214b7c

Please sign in to comment.