brought in a fix for keeping invalid blocks marked as such
From https://github.com/bitcoin/bitcoin/pull/12407
This commit is contained in:
parent
e6945bba74
commit
60af36c34b
2 changed files with 33 additions and 17 deletions
|
@ -1224,13 +1224,18 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChainState::InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) {
|
void CChainState::InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) {
|
||||||
if (!state.CorruptionPossible()) {
|
AssertLockHeld(cs_main);
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
|
||||||
m_failed_blocks.insert(pindex);
|
if (state.CorruptionPossible()) {
|
||||||
setDirtyBlockIndex.insert(pindex);
|
// No updates should happen if corruption is possible.
|
||||||
setBlockIndexCandidates.erase(pindex);
|
return;
|
||||||
InvalidChainFound(pindex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
|
m_failed_blocks.insert(pindex);
|
||||||
|
setDirtyBlockIndex.insert(pindex);
|
||||||
|
setBlockIndexCandidates.erase(pindex);
|
||||||
|
InvalidChainFound(pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txundo, int nHeight)
|
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txundo, int nHeight)
|
||||||
|
@ -2889,10 +2894,7 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the block itself as invalid.
|
// Mark the block itself as invalid.
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
InvalidBlockFound(pindex, state);
|
||||||
setDirtyBlockIndex.insert(pindex);
|
|
||||||
setBlockIndexCandidates.erase(pindex);
|
|
||||||
m_failed_blocks.insert(pindex);
|
|
||||||
|
|
||||||
// DisconnectTip will add transactions to disconnectpool; try to add these
|
// DisconnectTip will add transactions to disconnectpool; try to add these
|
||||||
// back to the mempool.
|
// back to the mempool.
|
||||||
|
@ -2908,8 +2910,6 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidChainFound(pindex);
|
|
||||||
|
|
||||||
// Only notify about a new block tip if the active chain was modified.
|
// Only notify about a new block tip if the active chain was modified.
|
||||||
if (pindex_was_in_chain) {
|
if (pindex_was_in_chain) {
|
||||||
uiInterface.NotifyBlockTip(IsInitialBlockDownload(), pindex->pprev);
|
uiInterface.NotifyBlockTip(IsInitialBlockDownload(), pindex->pprev);
|
||||||
|
@ -3553,9 +3553,8 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
|
||||||
|
|
||||||
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
if (!CheckBlock(block, state, chainparams.GetConsensus()) ||
|
||||||
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) {
|
||||||
if (state.IsInvalid() && !state.CorruptionPossible()) {
|
if (state.IsInvalid()) {
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
InvalidBlockFound(pindex, state);
|
||||||
setDirtyBlockIndex.insert(pindex);
|
|
||||||
}
|
}
|
||||||
return error("%s: %s", __func__, FormatStateMessage(state));
|
return error("%s: %s", __func__, FormatStateMessage(state));
|
||||||
}
|
}
|
||||||
|
@ -3599,7 +3598,16 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
if (ret) {
|
if (!ret) {
|
||||||
|
// Mark the block as invalid if we recognize it in mapBlockIndex.
|
||||||
|
// This doesn't happen within CheckBlock so we have to include a call
|
||||||
|
// here. It *does* happen within AcceptBlock below.
|
||||||
|
auto it = g_chainstate.mapBlockIndex.find(pblock->GetHash());
|
||||||
|
|
||||||
|
if (it != g_chainstate.mapBlockIndex.end()) {
|
||||||
|
g_chainstate.InvalidBlockFound(*it, state);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// Store to disk
|
// Store to disk
|
||||||
ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);
|
ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,6 +510,15 @@ public:
|
||||||
|
|
||||||
void UnloadBlockIndex();
|
void UnloadBlockIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Mark a single block as invalid, updating its status in `mapBlockIndex`.
|
||||||
|
** Perform other index-related bookkeeping.
|
||||||
|
**
|
||||||
|
** See also: InvalidateBlock, which should be called instead of this if the
|
||||||
|
** block being invalidated is on the active chain.
|
||||||
|
**/
|
||||||
|
void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace);
|
bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace);
|
||||||
bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool);
|
bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool);
|
||||||
|
@ -524,7 +533,6 @@ private:
|
||||||
*/
|
*/
|
||||||
void CheckBlockIndex(const Consensus::Params& consensusParams);
|
void CheckBlockIndex(const Consensus::Params& consensusParams);
|
||||||
|
|
||||||
void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state);
|
|
||||||
CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue