Skip to content

Conversation

mzumsande
Copy link
Contributor

@mzumsande mzumsande commented Jun 21, 2024

This was suggested by me in the discussion of #30288, which has more context.

If the snapshot is not an ancestor of the most-work header (m_best_header), syncing from that alternative chain leading to m_best_header should be prioritised. Therefore it's not useful loading the snapshot in this situation.
If the other chain turns out to be invalid or the chain with the snapshot retrieves additional headers so that it's the most-work one again (see functional test), m_best_header will change and loading the snapshot will be possible again.

Because of the work required to generate a conflicting headers chain, a situation with two conflicting chains should only be possible under extreme circumstances, such as major forks.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 21, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK fjahr, alfonsoromanz, achow101

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:

  • #30403 (test, assumeutxo: Remove resolved todo comments and add new test by fjahr)

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.

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

Concept ACK

@mzumsande
Copy link
Contributor Author

After merge of #30267: Rebased, addressed nit by fjahr, and marked as ready for review.

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

tACK 29ab88d

I reviewed the code and confirmed that the test fails as expected when the behavior change is not applied.

self.log.info("Test bitcoind should fail when the node knows the headers of another chain with more work.")
node0 = self.nodes[0]
node1 = self.nodes[1]
# create two blocks that form a longer chain
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Comment could be a little more detailed

Suggested change
# create two blocks that form a longer chain
# On node 0, create an alternative chain containing 2 new blocks, forking off the main chain at the block before the snapshot block. This simulates a longer chain than the main chain when submitting these two block headers to node 1 because it is only aware of the main chain headers up to the snapshot height.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, in a slightly modified way. The alternative chain is just created in python, node 0 is only used to fetch the previous block it builds on.

@mzumsande
Copy link
Contributor Author

29ab88d to ab478c5:
Addressed feedback by @fjahr (thanks!) and rebased.

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

re-ACK ab478c5

Confirmed only changes since last review were the rebase and addressing comments (per git range-diff master 29ab88dfe1c43af3620480c99cba844aa414023c ab478c5fa16427b496e8a93e4780770d4c270214).

@mzumsande mzumsande force-pushed the 202406_assumeutxo_bestheader branch from ab478c5 to b715a13 Compare July 8, 2024 20:31
@fjahr
Copy link
Contributor

fjahr commented Jul 8, 2024

re-ACK b715a13

Just addressed my latest re-nit.

Copy link
Contributor

@alfonsoromanz alfonsoromanz left a comment

Choose a reason for hiding this comment

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

tACK b715a13

The test passes successfully. I also verified that the test fails with no exception raised if the patch in src/validation.cpp is not applied, i.e

File "/Users/alfonso/dev/bitcoin/test/functional/feature_assumeutxo.py", line 238, in test_snapshot_not_on_most_work_chain
assert_raises_rpc_error(-32603, msg, node1.loadtxoutset, dump_output_path)
File "/Users/alfonso/dev/bitcoin/test/functional/test_framework/util.py", line 148, in assert_raises_rpc_error
assert try_rpc(code, message, fun, *args, **kwds), "No exception raised"
AssertionError: No exception raised

If the snapshot is not an ancestor of the most-work header (m_best_header),
syncing from that alternative chain should be prioritised.
Therefore don't accept loading a snapshot in this situation.

If that other chain turns out to be invalid, m_best_header
would be reset and loading the snapshot should be possible again.

Because of the work required to generate a conflicting headers chain,
this should only be possible under extreme circumstances, such as major forks.
@mzumsande mzumsande force-pushed the 202406_assumeutxo_bestheader branch from b715a13 to 55b6d7b Compare July 11, 2024 17:12
@mzumsande
Copy link
Contributor Author

b715a13 to 55b6d7b: rebased

@fjahr
Copy link
Contributor

fjahr commented Jul 11, 2024

re-ACK 55b6d7b

@DrahtBot DrahtBot requested a review from alfonsoromanz July 11, 2024 23:27
Copy link
Contributor

@alfonsoromanz alfonsoromanz left a comment

Choose a reason for hiding this comment

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

Re ACK 55b6d7b

@achow101
Copy link
Member

ACK 55b6d7b

@achow101 achow101 merged commit 0cac457 into bitcoin:master Jul 18, 2024
@mzumsande mzumsande deleted the 202406_assumeutxo_bestheader branch July 18, 2024 23:37
@Sjors
Copy link
Member

Sjors commented Jul 23, 2024

Post merge concept ACK

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 8, 2025
Summary:
If the snapshot is not an ancestor of the most-work header (m_best_header),
syncing from that alternative chain should be prioritised.
Therefore don't accept loading a snapshot in this situation.

If that other chain turns out to be invalid, m_best_header
would be reset and loading the snapshot should be possible again.

Because of the work required to generate a conflicting headers chain,
this should only be possible under extreme circumstances, such as major forks.

This is a backport of [[bitcoin/bitcoin#30320 | core#30320]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18059
@bitcoin bitcoin locked and limited conversation to collaborators Jul 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants