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 7df5259
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
4 changes: 0 additions & 4 deletions ledger/benches/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ fn bench_insert_data_shred_big(bench: &mut Bencher) {
}

#[bench]
#[ignore]
fn bench_write_transaction_memos(b: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Expand All @@ -177,7 +176,6 @@ fn bench_write_transaction_memos(b: &mut Bencher) {
}

#[bench]
#[ignore]
fn bench_add_transaction_memos_to_batch(b: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Expand All @@ -202,7 +200,6 @@ fn bench_add_transaction_memos_to_batch(b: &mut Bencher) {
}

#[bench]
#[ignore]
fn bench_write_transaction_status(b: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Expand Down Expand Up @@ -236,7 +233,6 @@ fn bench_write_transaction_status(b: &mut Bencher) {
}

#[bench]
#[ignore]
fn bench_add_transaction_status_to_batch(b: &mut Bencher) {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore =
Expand Down
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 7df5259

Please sign in to comment.