diff options
author | Ava Chow <github@achow101.com> | 2024-07-18 17:28:22 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-07-18 17:28:22 -0400 |
commit | 0cac45755e6b140621e24298c65d54d60767d6ea (patch) | |
tree | 5abed5a9028fcc7aa6b044106c3ea7331324aeae /src | |
parent | 6144aa21d0606e66ed6635975698e9a6456b5ca3 (diff) | |
parent | 55b6d7be68a6f6c3882588ffd5b9349d885ed953 (diff) |
Merge bitcoin/bitcoin#30320: assumeutxo: Don't load a snapshot if it's not in the best header chain
55b6d7be68a6f6c3882588ffd5b9349d885ed953 validation: Don't load a snapshot if it's not in the best header chain. (Martin Zumsande)
Pull request description:
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.
ACKs for top commit:
fjahr:
re-ACK 55b6d7be68a6f6c3882588ffd5b9349d885ed953
achow101:
ACK 55b6d7be68a6f6c3882588ffd5b9349d885ed953
alfonsoromanz:
Re ACK 55b6d7be68a6f6c3882588ffd5b9349d885ed953
Tree-SHA512: 4fbea5ab1038ae353fc949a186041cf9b397e7ce4ac59ff36f881c9437b4f22ada922490ead5b2661389eb1ca0f3d1e7e7e6a4261057678643e71594a691ac36
Diffstat (limited to 'src')
-rw-r--r-- | src/validation.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index c49ec404ca..67ed0ae710 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5668,6 +5668,10 @@ util::Result<void> ChainstateManager::ActivateSnapshot( return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())}; } + if (!m_best_header || m_best_header->GetAncestor(base_blockheight) != snapshot_start_block) { + return util::Error{_("A forked headers-chain with more work than the chain with the snapshot base block header exists. Please proceed to sync without AssumeUtxo.")}; + } + auto mempool{m_active_chainstate->GetMempool()}; if (mempool && mempool->size() > 0) { return util::Error{Untranslated("Can't activate a snapshot when mempool not empty")}; |