aboutsummaryrefslogtreecommitdiff
path: root/src/index/base.cpp
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2022-05-22 20:29:45 +0200
committerMartin Zumsande <mzumsande@gmail.com>2023-05-17 11:14:10 -0400
commit60bec3c82d09ec208bf0028ad32499e251ad205e (patch)
tree6751884ffbb11d5d4a68b7d3805a6440fbc01a60 /src/index/base.cpp
parent594f05db19fa2eaf6705f13bb0e147bce6ac21e5 (diff)
index: Use first block from locator instead of looking for fork point
The index sync code has logic to go back the chain to the forking point, while also updating index-specific state, which is necessary to prevent possible corruption of the coinstatsindex. Also add a test for this (a reorg happens while the index is deactivated) that would not pass before this change.
Diffstat (limited to 'src/index/base.cpp')
-rw-r--r--src/index/base.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 3e05c9b965..67c7156c55 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -92,7 +92,13 @@ bool BaseIndex::Init()
if (locator.IsNull()) {
SetBestBlockIndex(nullptr);
} else {
- SetBestBlockIndex(m_chainstate->FindForkInGlobalIndex(locator));
+ // Setting the best block to the locator's top block. If it is not part of the
+ // best chain, we will rewind to the fork point during index sync
+ const CBlockIndex* locator_index{m_chainstate->m_blockman.LookupBlockIndex(locator.vHave.at(0))};
+ if (!locator_index) {
+ return InitError(strprintf(Untranslated("%s: best block of the index not found. Please rebuild the index."), GetName()));
+ }
+ SetBestBlockIndex(locator_index);
}
// Note: this will latch to true immediately if the user starts up with an empty