Delay writing block indexes in invalidate/reconsider
This commit is contained in:
parent
9b0a8d3152
commit
0dd06b2515
1 changed files with 6 additions and 12 deletions
16
src/main.cpp
16
src/main.cpp
|
@ -2140,17 +2140,13 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
|
||||||
|
|
||||||
// Mark the block itself as invalid.
|
// Mark the block itself as invalid.
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
|
setDirtyBlockIndex.insert(pindex);
|
||||||
return state.Abort("Failed to update block index");
|
|
||||||
}
|
|
||||||
setBlockIndexCandidates.erase(pindex);
|
setBlockIndexCandidates.erase(pindex);
|
||||||
|
|
||||||
while (chainActive.Contains(pindex)) {
|
while (chainActive.Contains(pindex)) {
|
||||||
CBlockIndex *pindexWalk = chainActive.Tip();
|
CBlockIndex *pindexWalk = chainActive.Tip();
|
||||||
pindexWalk->nStatus |= BLOCK_FAILED_CHILD;
|
pindexWalk->nStatus |= BLOCK_FAILED_CHILD;
|
||||||
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexWalk))) {
|
setDirtyBlockIndex.insert(pindexWalk);
|
||||||
return state.Abort("Failed to update block index");
|
|
||||||
}
|
|
||||||
setBlockIndexCandidates.erase(pindexWalk);
|
setBlockIndexCandidates.erase(pindexWalk);
|
||||||
// ActivateBestChain considers blocks already in chainActive
|
// ActivateBestChain considers blocks already in chainActive
|
||||||
// unconditionally valid already, so force disconnect away from it.
|
// unconditionally valid already, so force disconnect away from it.
|
||||||
|
@ -2183,9 +2179,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
|
||||||
while (it != mapBlockIndex.end()) {
|
while (it != mapBlockIndex.end()) {
|
||||||
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
||||||
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
||||||
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
|
setDirtyBlockIndex.insert(it->second);
|
||||||
return state.Abort("Failed to update block index");
|
|
||||||
}
|
|
||||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
||||||
setBlockIndexCandidates.insert(it->second);
|
setBlockIndexCandidates.insert(it->second);
|
||||||
}
|
}
|
||||||
|
@ -2199,9 +2193,9 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
|
||||||
|
|
||||||
// Remove the invalidity flag from all ancestors too.
|
// Remove the invalidity flag from all ancestors too.
|
||||||
while (pindex != NULL) {
|
while (pindex != NULL) {
|
||||||
|
if (pindex->nStatus & BLOCK_FAILED_MASK) {
|
||||||
pindex->nStatus &= ~BLOCK_FAILED_MASK;
|
pindex->nStatus &= ~BLOCK_FAILED_MASK;
|
||||||
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
|
setDirtyBlockIndex.insert(pindex);
|
||||||
return state.Abort("Failed to update block index");
|
|
||||||
}
|
}
|
||||||
pindex = pindex->pprev;
|
pindex = pindex->pprev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue