Skip to content

Conversation

yuvicc
Copy link
Contributor

@yuvicc yuvicc commented May 22, 2025

Updated functional tests to replace direct use of invalidateblock with proper fork-based reorg behaviour. The direct invalidation approach bypasses important validation checks and has depth limitations(10 block) that don't match real-world reorg scenarios. For more details see #32531.

Fixes #32531

@DrahtBot
Copy link
Contributor

DrahtBot commented May 22, 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/32587.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Prabhat1308
Concept ACK BrandonOdiwuor, enirox001
Stale ACK instagibbs

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:

  • #28676 (Cluster mempool implementation by sdaftuar)

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.

@instagibbs
Copy link
Member

feel free to ping me when it's ready

@yuvicc
Copy link
Contributor Author

yuvicc commented May 22, 2025

feel free to ping me when it's ready

Sure!

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch 3 times, most recently from 7bbdba1 to 516c6ce Compare May 30, 2025 06:35
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/43164565056
LLM reason (✨ experimental): The CI failure is primarily due to errors from the lint check, specifically from ruff, which identified and flagged Python code issues such as unused imports and trailing whitespace.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from 516c6ce to b70c907 Compare June 2, 2025 16:19
@DrahtBot DrahtBot removed the CI failed label Jun 2, 2025
@yuvicc yuvicc marked this pull request as ready for review June 3, 2025 07:08
@yuvicc
Copy link
Contributor Author

yuvicc commented Jun 3, 2025

@instagibbs can you review this, will add other tests once this one gets ACK'ed

@yuvicc yuvicc changed the title [WIP] test: Fix reorg patterns in mempool tests to use proper fork-based approach test: Fix reorg patterns in mempool tests to use proper fork-based approach Jun 3, 2025
@DrahtBot DrahtBot added the Tests label Jun 3, 2025
@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from b70c907 to 9565415 Compare June 4, 2025 07:21
Copy link
Contributor

@Prabhat1308 Prabhat1308 left a comment

Choose a reason for hiding this comment

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

ACK with the approach . Left some nits

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from 9565415 to 45fad54 Compare June 10, 2025 13:39
@yuvicc
Copy link
Contributor Author

yuvicc commented Jun 10, 2025

Addressed some nits and rebased with master!

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch 2 times, most recently from 35414a8 to c98f361 Compare June 10, 2025 20:54
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

LGTM c98f361

feel free to add more cases

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from c98f361 to 3012d6d Compare June 15, 2025 17:12
@yuvicc yuvicc changed the title test: Fix reorg patterns in mempool tests to use proper fork-based approach test: Fix reorg patterns in tests to use proper fork-based approach Jun 16, 2025
@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch 2 times, most recently from e186193 to f079571 Compare June 18, 2025 07:25
@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from 01b98dc to 4ddc577 Compare July 5, 2025 04:54
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK 4ddc577

@DrahtBot DrahtBot mentioned this pull request Jul 11, 2025
8 tasks
@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from 4ddc577 to 3afc731 Compare July 12, 2025 06:24
@yuvicc
Copy link
Contributor Author

yuvicc commented Jul 12, 2025

update: rebased to master!

@instagibbs
Copy link
Member

reACK 3afc731

just a reminder that you don't need to rebase on master unless a silent merge conflict is detected or drahtbot yells at you about an issue merging

git range-diff master 4ddc577953a7407ea44a3e3d8d9a4635929307ca 3afc73134bf652d01e25232701c2ef192b3fea0b

@enirox001
Copy link
Contributor

enirox001 commented Jul 15, 2025

code review and tested-ACK

This PR is well designed: the refactoring to centralize fork creation and the switch to realistic reorg behavior both improve test clarity and fidelity.

  • da836ca: Cleanly moves create_empty_fork into blocktools.py, enabling reuse across functional tests.
  • 3afc731: Updates reorg logic in multiple tests to use actual fork submission rather than invalidateblock(), which better matches real‐world chain behavior.

One remaining question on duplication:

Across several test files, trigger_reorg is defined twice:

# Variation A: explicit node parameter
def trigger_reorg(fork_blocks, node):
    for block in fork_blocks:
        node.submitblock(block.serialize().hex())
    assert_equal(node.getbestblockhash(), fork_blocks[-1].hash)

# Variation B: hardcoded to self.nodes[0]
def trigger_reorg(self, fork_blocks):
    for block in fork_blocks:
        self.nodes[0].submitblock(block.serialize().hex())
    assert_equal(self.nodes[0].getbestblockhash(), fork_blocks[-1].hash)

Only the node lookup differs. Would it make sense to extract a single trigger_reorg(fork_blocks, node) utility in test_framework/blocktools.py and have all tests call that?

@yuvicc
Copy link
Contributor Author

yuvicc commented Jul 15, 2025

Across several test files, trigger_reorg is defined twice:

I am not sure if you have reviewed the code nicely, there isn't any duplication but rather a different approach using time-based timelock, see comment

Only the node lookup differs. Would it make sense to extract a single trigger_reorg(fork_blocks, node) utility in test_framework/blocktools.py and have all tests call that?

For now, I think we can keep like this. There are lot's of other tests as well which needs the reorg correction and can be done in a follow-up pr.

@enirox001
Copy link
Contributor

enirox001 commented Jul 15, 2025

Thanks for the clarification! You’re absolutely right - I should have reviewed the implementation details more carefully. I appreciate you pointing out that these are different approaches (including the time-based timelock approach) rather than simple duplication.

Also, you’re correct about my phrasing - “defined twice” was unclear when it’s actually “defined multiple times across files.”

Makes sense to address this in a follow-up PR along with other tests that need reorg corrections.

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from 3afc731 to a161f05 Compare July 17, 2025 11:29
@yuvicc
Copy link
Contributor Author

yuvicc commented Jul 17, 2025

update: in mempool_reorg.py: “slighty” -> “slightly” [correct spelling]

@instagibbs
Copy link
Member

reACK a161f05

spelling fix

@fanquake fanquake requested review from glozow and removed request for BrandonOdiwuor and Prabhat1308 July 17, 2025 12:20
@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from a161f05 to f56bb5e Compare July 18, 2025 16:50
@yuvicc
Copy link
Contributor Author

yuvicc commented Jul 18, 2025

Rebased -> master@672c85cb1ea0d76ef9e596b2a964b2311b11b815

@instagibbs
Copy link
Member

think you need to fix issues first

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/46275827051
LLM reason (✨ experimental): The CI failure is caused by errors detected by clang-tidy in the Python linter, specifically undefined names create_block and create_coinbase.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@yuvicc yuvicc force-pushed the 2025-05-update_test_reorg_behaviour branch from f56bb5e to cec7ce0 Compare July 18, 2025 19:23
@yuvicc
Copy link
Contributor Author

yuvicc commented Jul 18, 2025

Fixed conflicts and rebased to master.

Copy link
Contributor

@Prabhat1308 Prabhat1308 left a comment

Choose a reason for hiding this comment

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

ACK cec7ce0

changes since I last reviewed

  • the PR has been extended to 5 more tests other than mempool_reorg.py
  • Tested and reviewed the added tests.

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.

avoid using invalidateblock to directly test reorg behavior
8 participants