Skip to content

Commit

Permalink
fix alt_block height
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Oct 31, 2024
1 parent 1cf86ed commit f65ff1b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion benches/criterion/cuprate-blockchain/benches/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn add_block_inner(c: &mut Criterion, function_name: &str, block: &VerifiedBlock

let start = Instant::now();
for block in &blocks {
let block = black_box(block);
black_box(block::add_block(block, &mut tables)).unwrap();
}
start.elapsed()
Expand Down Expand Up @@ -75,6 +76,18 @@ fn add_block_v16_tx0(c: &mut Criterion) {
fn add_alt_block_inner(c: &mut Criterion, function_name: &str, block: &VerifiedBlockInformation) {
let env = cuprate_criterion_blockchain::TmpEnv::new();

// We must have at least 1 block or else `add_alt_block` will panic.
{
let env_inner = env.env.env_inner();
let tx_rw = env_inner.tx_rw().unwrap();
let mut tables = env_inner.open_tables_mut(&tx_rw).unwrap();

let mut block = BLOCK_V1_TX2.clone();
block.height = 0;

block::add_block(&block, &mut tables).unwrap();
}

c.bench_function(function_name, |b| {
// We use `iter_custom` because we need to generate an
// appropriate amount of blocks and only time the `add_block`.
Expand All @@ -89,7 +102,7 @@ fn add_alt_block_inner(c: &mut Criterion, function_name: &str, block: &VerifiedB
txs: b.txs,
block_hash: b.block_hash,
pow_hash: b.pow_hash,
height: b.height,
height: b.height + 1,
weight: b.weight,
long_term_weight: b.long_term_weight,
cumulative_difficulty: b.cumulative_difficulty,
Expand All @@ -103,6 +116,7 @@ fn add_alt_block_inner(c: &mut Criterion, function_name: &str, block: &VerifiedB

let start = Instant::now();
for block in &blocks {
let block = black_box(block);
black_box(alt_block::add_alt_block(block, &mut tables)).unwrap();
}
start.elapsed()
Expand Down

0 comments on commit f65ff1b

Please sign in to comment.