Skip to content

Conversation

l0rinc
Copy link
Contributor

@l0rinc l0rinc commented May 18, 2025

This is an alternative to #32457 which replaces the current benchmark block 413567 from 2016 with block 784588 from 2023.

Added bench/block_generator.{h,cpp} that builds a fully valid block at runtime and exposes a serialized and an in-memory block, so benchmarks can fetch whichever form they need:
- GetBlock() - in-memory CBlock;
- GetBlockData() - serialized DataStream.

  • Generation is steered by ScriptRecipe:
    • per-type probabilities for legacy, P2SH, v0/v1 witness, anchor, multisig, OP_RETURN, non-standard, …
    • a geometric base that controls input/output counts, witness-stack depth, amounts, versions, lock-times, sequences, …
      Presets kLegacy (pre-SegWit) and kWitness (Taproot-era) are included, callers can supply custom mixes.
  • Deterministic FastRandomContext yields identical output on every run while avoiding repetition and predictability bias.
  • Blocks are mined against the easiest allowed target, then run through CheckBlock() to ensure full validity.

This delivers diverse, up-to-date test data without adding another megabyte-scale binary to the repository and lets us retune workloads as network patterns evolve.

* Add `bench/block_generator.{h,cpp}` that builds a fully valid block at runtime and exposes:
    - `GetBlock()` - in-memory `CBlock`;
    - `GetBlockData()` - serialized `DataStream`;
  so benchmarks can fetch whichever form they need.
* Generation is steered by `ScriptRecipe`:
  - per-type probabilities for legacy, P2SH, v0/v1 witness, anchor, multisig, OP_RETURN, non-standard, …
  - a geometric base that controls input/output counts, witness-stack depth, amounts, versions, lock-times, sequences, …
  Presets `kLegacy` (pre-SegWit) and `kWitness` (Taproot-era) are included, callers can supply custom mixes.
* Deterministic `FastRandomContext` yields identical output on every run while avoiding repetition and predictability bias.
* Blocks are mined against the easiest allowed target, then run through `CheckBlock()` to ensure full validity.

This delivers diverse, up-to-date test data without adding another megabyte-scale binary to the repository and lets us retune workloads as network patterns evolve.
@DrahtBot
Copy link
Contributor

DrahtBot commented May 18, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32554.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK laanwj, yuvicc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32729 (test,refactor: extract script template helpers & widen sigop count coverage by l0rinc)
  • #31682 ([IBD] specialize CheckBlock's input & coinbase checks by l0rinc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj
Copy link
Member

laanwj commented May 19, 2025

Concept ACK

@l0rinc l0rinc marked this pull request as ready for review May 21, 2025 13:44
@l0rinc l0rinc changed the title RFC: bench: replace embedded raw block with configurable block generator bench: replace embedded raw block with configurable block generator May 21, 2025
@DrahtBot DrahtBot added the Tests label May 21, 2025
@yuvicc
Copy link
Contributor

yuvicc commented Jun 29, 2025

Concept ACK

This one is pretty useful as I can test with up-to date test_data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants