mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge pull request #5316
f86a24bMove `setmocktime` to hidden category (Wladimir J. van der Laan)bd9aebfIntroduce a hidden category (Pieter Wuille)0dd06b2Delay writing block indexes in invalidate/reconsider (Pieter Wuille)9b0a8d3Add 'invalidateblock' and 'reconsiderblock' RPC commands. (Pieter Wuille)
This commit is contained in:
67
src/main.cpp
67
src/main.cpp
@@ -2135,6 +2135,73 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
// Mark the block itself as invalid.
|
||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
setBlockIndexCandidates.erase(pindex);
|
||||
|
||||
while (chainActive.Contains(pindex)) {
|
||||
CBlockIndex *pindexWalk = chainActive.Tip();
|
||||
pindexWalk->nStatus |= BLOCK_FAILED_CHILD;
|
||||
setDirtyBlockIndex.insert(pindexWalk);
|
||||
setBlockIndexCandidates.erase(pindexWalk);
|
||||
// ActivateBestChain considers blocks already in chainActive
|
||||
// unconditionally valid already, so force disconnect away from it.
|
||||
if (!DisconnectTip(state)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
|
||||
// add them again.
|
||||
BlockMap::iterator it = mapBlockIndex.begin();
|
||||
while (it != mapBlockIndex.end()) {
|
||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
||||
setBlockIndexCandidates.insert(pindex);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
InvalidChainFound(pindex);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
int nHeight = pindex->nHeight;
|
||||
|
||||
// Remove the invalidity flag from this block and all its descendants.
|
||||
BlockMap::iterator it = mapBlockIndex.begin();
|
||||
while (it != mapBlockIndex.end()) {
|
||||
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
||||
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(it->second);
|
||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
||||
setBlockIndexCandidates.insert(it->second);
|
||||
}
|
||||
if (it->second == pindexBestInvalid) {
|
||||
// Reset invalid block marker if it was pointing to one of those.
|
||||
pindexBestInvalid = NULL;
|
||||
}
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
// Remove the invalidity flag from all ancestors too.
|
||||
while (pindex != NULL) {
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK) {
|
||||
pindex->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
}
|
||||
pindex = pindex->pprev;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
||||
{
|
||||
// Check for duplicate
|
||||
|
||||
Reference in New Issue
Block a user