Skip to content

test: deduplicate reorg test code - #33959

Open
yuvicc wants to merge 2 commits into
bitcoin:masterfrom
yuvicc:2025-11-followup_fix_reorgs_tests
Open

yuvicc wants to merge 2 commits into
bitcoin:masterfrom
yuvicc:2025-11-followup_fix_reorgs_tests

Conversation

@yuvicc

@yuvicc yuvicc commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor

Follow-up to #32587.

trigger_reorg() was copy-pasted across several functional tests. This moves it into blocktools.py, together with the fork construction, as two helpers: create_empty_fork() and trigger_reorg().

The remaining tests that still simulated reorgs with the invalidateblock RPC are converted to use them, since invalidateblock takes a different codepath than a reorg caused by a competing chain arriving.

@DrahtBot DrahtBot added the Tests label Nov 27, 2025
@DrahtBot

DrahtBot commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes 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.

@fanquake
fanquake requested a review from instagibbs November 27, 2025 15:17
@fanquake fanquake changed the title test: use ForkGenerator to deduplicate reorg test code (#32587 follow-up) test: use ForkGenerator to deduplicate reorg test code Nov 27, 2025
@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from 4ee9b46 to b6150c2 Compare December 13, 2025 11:04
@maflcko

maflcko commented May 21, 2026

Copy link
Copy Markdown
Member

are you still working on this, or can it be closed?

@yuvicc

yuvicc commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

are you still working on this, or can it be closed?

Yes resumed the work, will push the update soon!

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from b6150c2 to 6dd6819 Compare June 12, 2026 07:45
@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from 6dd6819 to 5947686 Compare June 12, 2026 12:17
@yuvicc
yuvicc marked this pull request as ready for review June 12, 2026 12:23
@yuvicc

yuvicc commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR description and ready for review

@sedited

sedited commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@instagibbs do you want to take a look here?

@instagibbs

Copy link
Copy Markdown
Member

I think this might be a bit of overengineering. Centralizing code is nice, but really I don't see the value of the added abstraction aside from centralizing trigger_reorg?

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from 5947686 to 2edf797 Compare July 27, 2026 04:15
@yuvicc

yuvicc commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed @instagibbs suggestion to only keep trigger_reorg method in blocktools.py.

Comment thread test/functional/p2p_sendheaders.py Resolved
Comment thread test/functional/wallet_balance.py Resolved
Comment thread test/functional/wallet_balance.py Resolved
@@ -47,8 +44,7 @@ def transaction_graph_test(self, size, *, n_tx_to_mine, fee=100_000):
"""
wallet = MiniWallet(self.nodes[0])

# Prep for fork with empty blocks to not use invalidateblock directly
# for reorg case. The rpc has different codepath

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.

wondering if there's a good place to add this removed comment to have people not reintroduce this pattern

@yuvicc yuvicc Jul 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can add in create_empty_fork docstring?

Details
def create_empty_fork(node, fork_length=FORK_LENGTH):
    '''
        Creates a fork using node's chaintip as the starting point.
        Returns a list of blocks to submit in order.

        Prefer this over calling the invalidateblock RPC to simulate a reorg:
        invalidateblock takes a different codepath than a reorg caused by a
        competing chain arriving, so tests using it are not exercising the
        behaviour they mean to.
    '''

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from 2edf797 to 56e96c0 Compare July 30, 2026 04:06
@yuvicc yuvicc changed the title test: use ForkGenerator to deduplicate reorg test code test: deduplicate reorg test code and update remaining tests to fork-based reorgs Jul 30, 2026
@yuvicc yuvicc changed the title test: deduplicate reorg test code and update remaining tests to fork-based reorgs test: deduplicate reorg test code Jul 30, 2026
@yuvicc

yuvicc commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review @instagibbs
I've removed Forkgenerator class and only kept trigger_reorg in blocktools and addressed some comments.

I have also updated PR title and the description.

@sedited

sedited commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Ping for rebase @yuvicc

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from 56e96c0 to ee536ff Compare October 28, 2026 05:48
@yuvicc

yuvicc commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to master

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from ee536ff to e6e14d3 Compare November 3, 2026 10:34
@yuvicc

yuvicc commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased

@yuvicc
yuvicc force-pushed the 2025-11-followup_fix_reorgs_tests branch from e6e14d3 to d72c022 Compare November 4, 2026 17:23
@yuvicc

yuvicc commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed ralph llvm review nit: removed unused block-hash indexing in wallet_rescan_unconfirmed.py.

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.

5 participants