Skip to content

Commit 6abe9f5

Browse files
committed
Allow blockfilter in conjunction with prune
1 parent a59e7ed commit 6abe9f5

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/index/base.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,43 @@ bool BaseIndex::Init()
6565
m_best_block_index = g_chainman.m_blockman.FindForkInGlobalIndex(::ChainActive(), locator);
6666
}
6767
m_synced = m_best_block_index.load() == ::ChainActive().Tip();
68+
if (!m_synced) {
69+
bool prune_violation = false;
70+
if (!m_best_block_index) {
71+
// index is not built yet
72+
// make sure we have all block data back to the genesis
73+
const CBlockIndex* block = ::ChainActive().Tip();
74+
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
75+
block = block->pprev;
76+
}
77+
prune_violation = block != ::ChainActive().Genesis();
78+
}
79+
// in case the index has a best block set and is not fully synced
80+
// check if we have the required blocks to continue building the index
81+
else {
82+
const CBlockIndex* block_to_test = m_best_block_index.load();
83+
if (!ChainActive().Contains(block_to_test)) {
84+
// if the bestblock is not part of the mainchain, find the fork
85+
// and make sure we have all data down to the fork
86+
block_to_test = ::ChainActive().FindFork(block_to_test);
87+
}
88+
const CBlockIndex* block = ::ChainActive().Tip();
89+
prune_violation = true;
90+
// check backwards from the tip if we have all block data until we reach the indexes bestblock
91+
while (block_to_test && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
92+
if (block_to_test == block) {
93+
prune_violation = false;
94+
break;
95+
}
96+
block = block->pprev;
97+
}
98+
}
99+
if (prune_violation) {
100+
// throw error and graceful shutdown if we can't build the index
101+
FatalError("%s: %s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)", __func__, GetName());
102+
return false;
103+
}
104+
}
68105
return true;
69106
}
70107

@@ -177,6 +214,10 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
177214
assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
178215

179216
// In the case of a reorg, ensure persisted block locator is not stale.
217+
// Pruning has a minimum of 288 blocks-to-keep and getting the index
218+
// out of sync may be possible but a users fault.
219+
// In case we reorg beyond the pruned depth, ReadBlockFromDisk would
220+
// throw and lead to a graceful shutdown
180221
m_best_block_index = new_tip;
181222
if (!Commit()) {
182223
// If commit fails, revert the best block index to avoid corruption.

src/init.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10231023
if (args.GetArg("-prune", 0)) {
10241024
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
10251025
return InitError(_("Prune mode is incompatible with -txindex."));
1026-
if (!g_enabled_filter_types.empty()) {
1027-
return InitError(_("Prune mode is incompatible with -blockfilterindex."));
1028-
}
10291026
}
10301027

10311028
// -bind and -whitebind can't be set when not listening

0 commit comments

Comments
 (0)