mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 07:15:29 +01:00
Allow blockfilter in conjunction with prune
This commit is contained in:
parent
a59e7ed0bc
commit
6abe9f5b11
2 changed files with 41 additions and 3 deletions
|
@ -65,6 +65,43 @@ bool BaseIndex::Init()
|
||||||
m_best_block_index = g_chainman.m_blockman.FindForkInGlobalIndex(::ChainActive(), locator);
|
m_best_block_index = g_chainman.m_blockman.FindForkInGlobalIndex(::ChainActive(), locator);
|
||||||
}
|
}
|
||||||
m_synced = m_best_block_index.load() == ::ChainActive().Tip();
|
m_synced = m_best_block_index.load() == ::ChainActive().Tip();
|
||||||
|
if (!m_synced) {
|
||||||
|
bool prune_violation = false;
|
||||||
|
if (!m_best_block_index) {
|
||||||
|
// index is not built yet
|
||||||
|
// make sure we have all block data back to the genesis
|
||||||
|
const CBlockIndex* block = ::ChainActive().Tip();
|
||||||
|
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
|
||||||
|
block = block->pprev;
|
||||||
|
}
|
||||||
|
prune_violation = block != ::ChainActive().Genesis();
|
||||||
|
}
|
||||||
|
// in case the index has a best block set and is not fully synced
|
||||||
|
// check if we have the required blocks to continue building the index
|
||||||
|
else {
|
||||||
|
const CBlockIndex* block_to_test = m_best_block_index.load();
|
||||||
|
if (!ChainActive().Contains(block_to_test)) {
|
||||||
|
// if the bestblock is not part of the mainchain, find the fork
|
||||||
|
// and make sure we have all data down to the fork
|
||||||
|
block_to_test = ::ChainActive().FindFork(block_to_test);
|
||||||
|
}
|
||||||
|
const CBlockIndex* block = ::ChainActive().Tip();
|
||||||
|
prune_violation = true;
|
||||||
|
// check backwards from the tip if we have all block data until we reach the indexes bestblock
|
||||||
|
while (block_to_test && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
|
||||||
|
if (block_to_test == block) {
|
||||||
|
prune_violation = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
block = block->pprev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (prune_violation) {
|
||||||
|
// throw error and graceful shutdown if we can't build the index
|
||||||
|
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());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +214,10 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
|
||||||
assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
|
assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
|
||||||
|
|
||||||
// In the case of a reorg, ensure persisted block locator is not stale.
|
// In the case of a reorg, ensure persisted block locator is not stale.
|
||||||
|
// Pruning has a minimum of 288 blocks-to-keep and getting the index
|
||||||
|
// out of sync may be possible but a users fault.
|
||||||
|
// In case we reorg beyond the pruned depth, ReadBlockFromDisk would
|
||||||
|
// throw and lead to a graceful shutdown
|
||||||
m_best_block_index = new_tip;
|
m_best_block_index = new_tip;
|
||||||
if (!Commit()) {
|
if (!Commit()) {
|
||||||
// If commit fails, revert the best block index to avoid corruption.
|
// If commit fails, revert the best block index to avoid corruption.
|
||||||
|
|
|
@ -1023,9 +1023,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||||
if (args.GetArg("-prune", 0)) {
|
if (args.GetArg("-prune", 0)) {
|
||||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
|
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX))
|
||||||
return InitError(_("Prune mode is incompatible with -txindex."));
|
return InitError(_("Prune mode is incompatible with -txindex."));
|
||||||
if (!g_enabled_filter_types.empty()) {
|
|
||||||
return InitError(_("Prune mode is incompatible with -blockfilterindex."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -bind and -whitebind can't be set when not listening
|
// -bind and -whitebind can't be set when not listening
|
||||||
|
|
Loading…
Add table
Reference in a new issue