Fix a bug in invalidateblock. Add Test rpcs, invalidateblock and submitheader.#881
Draft
jaoleal wants to merge 5 commits intogetfloresta:masterfrom
Draft
Fix a bug in invalidateblock. Add Test rpcs, invalidateblock and submitheader.#881jaoleal wants to merge 5 commits intogetfloresta:masterfrom
jaoleal wants to merge 5 commits intogetfloresta:masterfrom
Conversation
83654b4 to
bfc050c
Compare
Member
Author
|
Pushed docs for both |
Collaborator
|
You forgot to add the documentation for |
f595f59 to
838fb14
Compare
Member
Author
|
Applied @moisesPompilio suggestions: |
838fb14 to
a11e6f8
Compare
Member
Author
|
Rebased and added entries with docs on floresta-cli |
| 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) |
Collaborator
There was a problem hiding this comment.
use getblockheader RPC
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.
a11e6f8 to
49f4afa
Compare
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]) | ||
|
|
Collaborator
There was a problem hiding this comment.
These RPCs could be moved to base.py, since both bitcoind and utreexod expose them
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
How to verify the changes you have done?
Checkout to the first commit, its the one introducing tests to the
invalidate_block()inner method on floresta.Running
cargo test -p floresta-chain --features flat-chainstore test_invalidateblock_updatesvalidationindexshould fail.Checkout to the next commit, the one introducing the fix. The previous command should pass.
Run the new integration tests,
submitheader.pyandinvalidateblock.py