Skip to content

Fix a bug in invalidateblock. Add Test rpcs, invalidateblock and submitheader.#881

Draft
jaoleal wants to merge 5 commits intogetfloresta:masterfrom
jaoleal:rpcsaga_testrpcs_invalidateblock_submitheader
Draft

Fix a bug in invalidateblock. Add Test rpcs, invalidateblock and submitheader.#881
jaoleal wants to merge 5 commits intogetfloresta:masterfrom
jaoleal:rpcsaga_testrpcs_invalidateblock_submitheader

Conversation

@jaoleal
Copy link
Copy Markdown
Member

@jaoleal jaoleal commented Mar 10, 2026

Description and Notes

While extending the features and tests over #862 I saw the necessity of such test rpcs.

I also found a bug when implementing the invalidate block rpc, a fix is introduced.

Note: im calling these test rpcs but its actually hidden rpcs. They are hidden on the CLI and are dangerous for the node state. Im not certain how we will treat these but right now they are being added as regular rpcs.

How to verify the changes you have done?

  1. Checkout to the first commit, its the one introducing tests to the invalidate_block() inner method on floresta.

  2. Running cargo test -p floresta-chain --features flat-chainstore test_invalidateblock_updatesvalidationindex should fail.

  3. Checkout to the next commit, the one introducing the fix. The previous command should pass.

  4. Run the new integration tests, submitheader.py and invalidateblock.py

@jaoleal jaoleal mentioned this pull request Mar 10, 2026
@jaoleal jaoleal force-pushed the rpcsaga_testrpcs_invalidateblock_submitheader branch from 83654b4 to bfc050c Compare March 10, 2026 20:01
@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Mar 10, 2026

Pushed docs for both invalidateblock and submitheader.

Comment thread tests/floresta-cli/invalidateblock.py
Comment thread tests/floresta-cli/invalidateblock.py
@moisesPompilio
Copy link
Copy Markdown
Collaborator

You forgot to add the documentation for invalidblock and submithead in floresta-cli.

@jaoleal jaoleal force-pushed the rpcsaga_testrpcs_invalidateblock_submitheader branch 2 times, most recently from f595f59 to 838fb14 Compare March 12, 2026 23:00
@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Mar 12, 2026

Applied @moisesPompilio suggestions:

  • submitheader now uses bitcoind.
  • Added more test cases for submitheader.
  • 5112101 Extends invalidateblock.py with a scenario that induces to a bug.
  • 838fb14 Adds the fix for the bug.

@jaoleal jaoleal force-pushed the rpcsaga_testrpcs_invalidateblock_submitheader branch from 838fb14 to a11e6f8 Compare March 16, 2026 19:21
@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Mar 16, 2026

Rebased and added entries with docs on floresta-cli

@luisschwab luisschwab added bug Something isn't working enhancement New feature or request labels Mar 17, 2026
self.bitcoind.rpc.generate_block(1)

block_hash = self.bitcoind.rpc.get_blockhash(1)
raw_block_hex = self.bitcoind.rpc.get_block(block_hash, 0)
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.

use getblockheader RPC

jaoleal added 5 commits March 18, 2026 03:19
Add test_invalidate_block_updates_validation_index that connects
FullyValid blocks, then invalidates one and asserts that
get_validation_index() still succeeds and points to a FullyValid
block.

This test fails without the fix in the next commit: invalidate_block
leaves validation_index pointing at a now-InvalidChain block, causing
get_validation_index() to return BadValidationIndex.
invalidate_block marks blocks as InvalidChain but the validation_index was not being updated on update_tip().
Since InvalidChain headers lose their stored height, get_validation_index() would fail with
BadValidationIndex when the p2p layer called it during its maintenance tick.
Add two new JSON-RPC methods:

- invalidateblock: marks a block and all descendants as invalid,
  rolling back the chain tip to the parent block.
- submitheader: decodes a hex-encoded 80-byte block header and
  submits it as a candidate chain tip via accept_header.

Also:
* Added RPC helpers in the Python test framework (floresta.py)
* Functional tests for both RPCs (invalidateblock.py, submitheader.py)
This commit extend invalidateblock.py to exercise the scenario where florestad
invalidates a block and, because `invalidateblock` does not trigger any acc
update, florestad will reject blocks that, even if they extend the new tip,
they do not extend the loaded acc. Florestad would eventualy catch correctly
the new tip only if the node was restarted or if the chain acquires more pow,
both cases triggers a reload of the acc.
The last commit states a case where floresta can be in a broken state,
because invalidateblock was not updating the acc. This commit fix that
by loading the accordingly acc for the new tip, when such is known.
@jaoleal jaoleal force-pushed the rpcsaga_testrpcs_invalidateblock_submitheader branch from a11e6f8 to 49f4afa Compare March 18, 2026 06:20
@jaoleal jaoleal added functional tests RPC Changes something with our JSON-RPC interface reliability Related to runtime reliability, stability and production readiness testing & validation labels Mar 27, 2026
@moisesPompilio moisesPompilio self-requested a review April 4, 2026 20:10
Comment on lines +29 to +36
def invalidate_block(self, blockhash: str):
"""Marks a block as invalid"""
return self.perform_request("invalidateblock", params=[blockhash])

def submit_header(self, hexdata: str):
"""Submits a raw block header as a candidate chain tip"""
return self.perform_request("submitheader", params=[hexdata])

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.

These RPCs could be moved to base.py, since both bitcoind and utreexod expose them

@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Apr 14, 2026

#831 (comment)

@jaoleal jaoleal marked this pull request as draft April 14, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request functional tests reliability Related to runtime reliability, stability and production readiness RPC Changes something with our JSON-RPC interface testing & validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants