Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 5,000 Lines • ▼ Show 20 Lines | bool CChainState::RewindBlockIndex(const Config &config) { | ||||
} | } | ||||
const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
int nHeight = chainActive.Height() + 1; | int nHeight = chainActive.Height() + 1; | ||||
// nHeight is now the height of the first insufficiently-validated block, or | // nHeight is now the height of the first insufficiently-validated block, or | ||||
// tipheight + 1 | // tipheight + 1 | ||||
CValidationState state; | CValidationState state; | ||||
CBlockIndex *pindex = chainActive.Tip(); | CBlockIndex *tip = chainActive.Tip(); | ||||
while (chainActive.Height() >= nHeight) { | // Loop until the tip is below nHeight, or we reach a pruned block. | ||||
while (true) { | |||||
// Make sure nothing changed from under us (this won't happen because | |||||
// RewindBlockIndex runs before importing/network are active) | |||||
assert(tip == chainActive.Tip()); | |||||
if (tip == nullptr || tip->nHeight < nHeight) break; | |||||
deadalnix: Braces | |||||
fpelliccioniAuthorUnsubmitted Done Inline ActionsOh I thought arc lint do the work for me ;P fpelliccioni: Oh I thought `arc lint` do the work for me ;P | |||||
if (fPruneMode && !chainActive.Tip()->nStatus.hasData()) { | if (fPruneMode && !chainActive.Tip()->nStatus.hasData()) { | ||||
// If pruning, don't try rewinding past the HAVE_DATA point; since | // If pruning, don't try rewinding past the HAVE_DATA point; since | ||||
// older blocks can't be served anyway, there's no need to walk | // older blocks can't be served anyway, there's no need to walk | ||||
// further, and trying to DisconnectTip() will fail (and require a | // further, and trying to DisconnectTip() will fail (and require a | ||||
// needless reindex/redownload of the blockchain). | // needless reindex/redownload of the blockchain). | ||||
break; | break; | ||||
} | } | ||||
// Disconnect block | |||||
if (!DisconnectTip(config, state, nullptr)) { | if (!DisconnectTip(config, state, nullptr)) { | ||||
return error("RewindBlockIndex: unable to disconnect block at " | return error("RewindBlockIndex: unable to disconnect block at " | ||||
"height %i (%s)", | "height %i (%s)", | ||||
pindex->nHeight, FormatStateMessage(state)); | tip->nHeight, FormatStateMessage(state)); | ||||
} | } | ||||
// Reduce validity flag and have-data flags. | |||||
// We do this after actual disconnecting, otherwise we'll end up writing | |||||
// the lack of data to disk before writing the chainstate, resulting in | |||||
// a failure to continue if interrupted. Note: If we encounter an | |||||
deadalnixUnsubmitted Not Done Inline ActionsPut the note on a new line in this comment. deadalnix: Put the note on a new line in this comment. | |||||
// insufficiently validated block that is on chainActive, it must be | |||||
// because we are a pruning node, and this block or some successor | |||||
// doesn't HAVE_DATA, so we were unable to rewind all the way. Blocks | |||||
// remaining on chainActive at this point must not have their validity | |||||
// reduced. | |||||
EraseBlockData(tip); | |||||
markblundebergUnsubmitted Not Done Inline ActionsDo we really need this? It seems it is being done in Core for the purpose of witness scrubbing, which doesn't apply to us. markblundeberg: Do we really need this? It seems it is being done in Core for the purpose of witness scrubbing… | |||||
tip = tip->pprev; | |||||
// Occasionally flush state to disk. | // Occasionally flush state to disk. | ||||
if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { | if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { | ||||
LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", | LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 808 Lines • Show Last 20 Lines |
Braces