Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | bool DisconnectTip(const Config &config, CValidationState &state, | ||||
DisconnectedBlockTransactions *disconnectpool) | DisconnectedBlockTransactions *disconnectpool) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
// Manual block validity manipulation: | // Manual block validity manipulation: | ||||
bool PreciousBlock(const Config &config, CValidationState &state, | bool PreciousBlock(const Config &config, CValidationState &state, | ||||
CBlockIndex *pindex); | CBlockIndex *pindex); | ||||
bool UnwindBlock(const Config &config, CValidationState &state, | bool UnwindBlock(const Config &config, CValidationState &state, | ||||
CBlockIndex *pindex, bool invalidate); | CBlockIndex *pindex, bool invalidate); | ||||
bool ResetBlockFailureFlags(CBlockIndex *pindex); | void ResetBlockFailureFlags(CBlockIndex *pindex); | ||||
template <typename F> | template <typename F> | ||||
void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f); | void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f); | ||||
template <typename F, typename C> | template <typename F, typename C> | ||||
void UpdateFlags(CBlockIndex *pindex, F f, C fchild) | void UpdateFlags(CBlockIndex *pindex, F f, C fchild) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
template <typename F> | template <typename F> | ||||
void UpdateFlags(CBlockIndex *pindex, F f) | void UpdateFlags(CBlockIndex *pindex, F f) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** Remove parked status from a block and its descendants. */ | /** Remove parked status from a block and its descendants. */ | ||||
bool UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren); | void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren); | ||||
bool ReplayBlocks(const Consensus::Params ¶ms, CCoinsView *view); | bool ReplayBlocks(const Consensus::Params ¶ms, CCoinsView *view); | ||||
bool RewindBlockIndex(const Config &config); | bool RewindBlockIndex(const Config &config); | ||||
bool LoadGenesisBlock(const CChainParams &chainparams); | bool LoadGenesisBlock(const CChainParams &chainparams); | ||||
void PruneBlockIndexCandidates(); | void PruneBlockIndexCandidates(); | ||||
void UnloadBlockIndex(); | void UnloadBlockIndex(); | ||||
▲ Show 20 Lines • Show All 3,026 Lines • ▼ Show 20 Lines | |||||
template <typename F> | template <typename F> | ||||
void CChainState::UpdateFlags(CBlockIndex *pindex, F f) | void CChainState::UpdateFlags(CBlockIndex *pindex, F f) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | ||||
// Handy shorthand. | // Handy shorthand. | ||||
UpdateFlags(pindex, f, f); | UpdateFlags(pindex, f, f); | ||||
} | } | ||||
bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { | void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (pindexBestInvalid && | if (pindexBestInvalid && | ||||
(pindexBestInvalid->GetAncestor(pindex->nHeight) == pindex || | (pindexBestInvalid->GetAncestor(pindex->nHeight) == pindex || | ||||
pindex->GetAncestor(pindexBestInvalid->nHeight) == | pindex->GetAncestor(pindexBestInvalid->nHeight) == | ||||
pindexBestInvalid)) { | pindexBestInvalid)) { | ||||
// Reset the invalid block marker if it is about to be cleared. | // Reset the invalid block marker if it is about to be cleared. | ||||
pindexBestInvalid = nullptr; | pindexBestInvalid = nullptr; | ||||
} | } | ||||
// In case we are reconsidering something before the finalization point, | // In case we are reconsidering something before the finalization point, | ||||
// move the finalization point to the last common ancestor. | // move the finalization point to the last common ancestor. | ||||
if (pindexFinalized) { | if (pindexFinalized) { | ||||
pindexFinalized = LastCommonAncestor(pindex, pindexFinalized); | pindexFinalized = LastCommonAncestor(pindex, pindexFinalized); | ||||
} | } | ||||
UpdateFlags(pindex, [](const BlockStatus status) { | UpdateFlags(pindex, [](const BlockStatus status) { | ||||
return status.withClearedFailureFlags(); | return status.withClearedFailureFlags(); | ||||
}); | }); | ||||
return true; | |||||
} | } | ||||
bool ResetBlockFailureFlags(CBlockIndex *pindex) { | void ResetBlockFailureFlags(CBlockIndex *pindex) { | ||||
return g_chainstate.ResetBlockFailureFlags(pindex); | return g_chainstate.ResetBlockFailureFlags(pindex); | ||||
} | } | ||||
bool CChainState::UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren) { | void CChainState::UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (pindexBestParked && | if (pindexBestParked && | ||||
(pindexBestParked->GetAncestor(pindex->nHeight) == pindex || | (pindexBestParked->GetAncestor(pindex->nHeight) == pindex || | ||||
pindex->GetAncestor(pindexBestParked->nHeight) == pindexBestParked)) { | pindex->GetAncestor(pindexBestParked->nHeight) == pindexBestParked)) { | ||||
// Reset the parked block marker if it is about to be cleared. | // Reset the parked block marker if it is about to be cleared. | ||||
pindexBestParked = nullptr; | pindexBestParked = nullptr; | ||||
} | } | ||||
UpdateFlags(pindex, | UpdateFlags(pindex, | ||||
[](const BlockStatus status) { | [](const BlockStatus status) { | ||||
return status.withClearedParkedFlags(); | return status.withClearedParkedFlags(); | ||||
}, | }, | ||||
[fClearChildren](const BlockStatus status) { | [fClearChildren](const BlockStatus status) { | ||||
return fClearChildren ? status.withClearedParkedFlags() | return fClearChildren ? status.withClearedParkedFlags() | ||||
: status.withParkedParent(false); | : status.withParkedParent(false); | ||||
}); | }); | ||||
return true; | |||||
} | } | ||||
bool UnparkBlockAndChildren(CBlockIndex *pindex) { | void UnparkBlockAndChildren(CBlockIndex *pindex) { | ||||
return g_chainstate.UnparkBlockImpl(pindex, true); | return g_chainstate.UnparkBlockImpl(pindex, true); | ||||
} | } | ||||
bool UnparkBlock(CBlockIndex *pindex) { | void UnparkBlock(CBlockIndex *pindex) { | ||||
return g_chainstate.UnparkBlockImpl(pindex, false); | return g_chainstate.UnparkBlockImpl(pindex, false); | ||||
} | } | ||||
const CBlockIndex *GetFinalizedBlock() { | const CBlockIndex *GetFinalizedBlock() { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
return pindexFinalized; | return pindexFinalized; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,477 Lines • Show Last 20 Lines |