Skip to content

test(consensus): test BlockTooBig#867

Open
JoseSK999 wants to merge 2 commits intogetfloresta:masterfrom
JoseSK999:block-too-big-test
Open

test(consensus): test BlockTooBig#867
JoseSK999 wants to merge 2 commits intogetfloresta:masterfrom
JoseSK999:block-too-big-test

Conversation

@JoseSK999
Copy link
Copy Markdown
Member

@JoseSK999 JoseSK999 commented Mar 5, 2026

Description and Notes

First commit adds some test helpers to make them simpler, second adds the test. I recommend review by commit, although this PR is small.

I've constructed a transaction that, when inserted in block 866,342 makes it have 4,000,001 WUs. Then we update the witness commitment and the merkle root, and then check we get BlockTooBig.

For this I had to implement the update_witness_commitment helper. Note that the block we are testing has witnesses, so the witness commitment is enforced by consensus, and inserting a legacy transaction adds a zero wtxid that the commitment must now account for.

How to verify the changes you have done?

Just take a look at test_block_too_big.

@JoseSK999 JoseSK999 self-assigned this Mar 5, 2026
@JoseSK999 JoseSK999 added chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability labels Mar 5, 2026
jaoleal

This comment was marked as duplicate.

@jaoleal
Copy link
Copy Markdown
Member

jaoleal commented Mar 9, 2026

Sometimes github is strange, it duplicated my review and now theres only one... The one that I marked as duplicate.

@JoseSK999 JoseSK999 force-pushed the block-too-big-test branch from 39bec94 to dc543b1 Compare March 9, 2026 17:18
@JoseSK999
Copy link
Copy Markdown
Member Author

Pushed dc543b1

  • Refactored the test setup into a helper function called build_oversized_866_342 @jaoleal

@jaoleal jaoleal requested a review from Davidson-Souza March 9, 2026 18:11
@jaoleal
Copy link
Copy Markdown
Member

jaoleal commented Mar 9, 2026

ACK dc543b1

Comment thread crates/floresta-chain/src/pruned_utreexo/consensus.rs
Comment thread crates/floresta-chain/src/pruned_utreexo/consensus.rs
Comment thread crates/floresta-chain/src/pruned_utreexo/consensus.rs
Comment on lines +700 to +703
fn decode_block(file_path: &str) -> Block {
let block_file = File::open(file_path).unwrap();
let block_bytes = zstd::decode_all(block_file).unwrap();
deserialize(&block_bytes).unwrap()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: Bitcoin Core leaves those test assets in another repo, called qa-assets. Leaving in the same tee has the disadvantage of bloating our tree with those test data, even though some people may not use it. Wdyt about moving these to our own floresta-qa-assets?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Davidson-Souza you mean the data under floresta-chain/testdata?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea that i got was is that davidson wants a floresta-qa-assets to gather test utils/data

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh like a separate test utils crate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, floresta-qa-assets. Our tree is getting a bit bloated and that makes cloning harder than it needs to be.

@JoseSK999 JoseSK999 force-pushed the block-too-big-test branch from dc543b1 to 20eb38b Compare March 10, 2026 20:07
@JoseSK999
Copy link
Copy Markdown
Member Author

Pushed 20eb38b

  • mutate_block is now deterministic
  • Copy-pasted the witness-commitment structure from BIP141 into a comment

@JoseSK999 JoseSK999 force-pushed the block-too-big-test branch from 20eb38b to 877ddf0 Compare March 10, 2026 20:25
@JoseSK999
Copy link
Copy Markdown
Member Author

Clippy didn't like the childish seed, fixed

@github-project-automation github-project-automation bot moved this to Backlog in Floresta Mar 19, 2026
@JoseSK999 JoseSK999 moved this from Backlog to Needs review in Floresta Mar 19, 2026
@JoseSK999 JoseSK999 added this to the Q2/2026 milestone Mar 19, 2026
@csgui csgui added reliability Related to runtime reliability, stability and production readiness testing & validation and removed chore Cleaning, refactoring, reducing complexity code quality Generally improves code readability and maintainability reliability Related to runtime reliability, stability and production readiness labels Mar 20, 2026
Comment thread crates/floresta-chain/src/pruned_utreexo/consensus.rs
/// Modifies historical block at height 866,342 by adding one extra transaction so that the
/// updated block weight is 4,000,001 WUs. The block merkle roots are updated accordingly.
fn build_oversized_866_342() -> Block {
let mut block = decode_block("./testdata/block_866342/raw.zst");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider remove hard coded file location to avoid test failures on other machines.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? This unit test is executed with the working directory set to the root of floresta-chain, so the path should always be found correctly.

Copy link
Copy Markdown
Collaborator

@csgui csgui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. Loved the 0xbebe_cafe

@Davidson-Souza
Copy link
Copy Markdown
Member

Can't test_input_value_above_max_money use the txout! macro?

I've constructed a transaction that, when inserted in block 866,342 makes it have 4,000,001 WUs. Then we update the witness commitment and the merkle root, and then check we get `BlockTooBig`.

For this I had to implement the `update_witness_commitment` helper. Note that the block we are testing has witnesses, so the witness commitment is enforced by consensus, and inserting a legacy transaction adds a zero `wtxid` that the commitment must now account for.
@JoseSK999 JoseSK999 force-pushed the block-too-big-test branch from 877ddf0 to 5bda1d5 Compare April 17, 2026 01:44
@JoseSK999
Copy link
Copy Markdown
Member Author

Can't test_input_value_above_max_money use the txout! macro?

Yes! Pushed 5bda1d5 using it

Copy link
Copy Markdown
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5bda1d5

@JoseSK999
Copy link
Copy Markdown
Member Author

Btw update_witness_commitment will also be useful for other future tests messing with a valid block while keeping the witness commitment valid (so we exercise diff error paths).

Copy link
Copy Markdown
Member

@luisschwab luisschwab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5bda1d5

let mut rng = OsRng;
/// Modifies a block to have a different output script (txdata is tampered with).
fn mutate_block(block: &mut Block) {
let mut rng = StdRng::seed_from_u64(0x_bebe_cafe);
Copy link
Copy Markdown
Member

@luisschwab luisschwab Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

5 participants