Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 3,294 Lines • ▼ Show 20 Lines | |||||
// Leverage RAII to run a functor at scope end | // Leverage RAII to run a functor at scope end | ||||
template <typename Func> struct Defer { | template <typename Func> struct Defer { | ||||
Func func; | Func func; | ||||
Defer(Func &&f) : func(std::move(f)) {} | Defer(Func &&f) : func(std::move(f)) {} | ||||
~Defer() { func(); } | ~Defer() { func(); } | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
bool Chainstate::UnwindBlock(const Config &config, BlockValidationState &state, | bool Chainstate::UnwindBlock(BlockValidationState &state, CBlockIndex *pindex, | ||||
CBlockIndex *pindex, bool invalidate) { | bool invalidate) { | ||||
// Genesis block can't be invalidated or parked | // Genesis block can't be invalidated or parked | ||||
assert(pindex); | assert(pindex); | ||||
if (pindex->nHeight == 0) { | if (pindex->nHeight == 0) { | ||||
return false; | return false; | ||||
} | } | ||||
CBlockIndex *to_mark_failed_or_parked = pindex; | CBlockIndex *to_mark_failed_or_parked = pindex; | ||||
bool pindex_was_in_chain = false; | bool pindex_was_in_chain = false; | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | bool Chainstate::UnwindBlock(BlockValidationState &state, CBlockIndex *pindex, | ||||
if (pindex_was_in_chain) { | if (pindex_was_in_chain) { | ||||
uiInterface.NotifyBlockTip( | uiInterface.NotifyBlockTip( | ||||
GetSynchronizationState(IsInitialBlockDownload()), | GetSynchronizationState(IsInitialBlockDownload()), | ||||
to_mark_failed_or_parked->pprev); | to_mark_failed_or_parked->pprev); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool Chainstate::InvalidateBlock(const Config &config, | bool Chainstate::InvalidateBlock(BlockValidationState &state, | ||||
BlockValidationState &state, | |||||
CBlockIndex *pindex) { | CBlockIndex *pindex) { | ||||
AssertLockNotHeld(m_chainstate_mutex); | AssertLockNotHeld(m_chainstate_mutex); | ||||
AssertLockNotHeld(::cs_main); | AssertLockNotHeld(::cs_main); | ||||
// See 'Note for backport of Core PR16849' in Chainstate::UnwindBlock | // See 'Note for backport of Core PR16849' in Chainstate::UnwindBlock | ||||
LOCK(m_chainstate_mutex); | LOCK(m_chainstate_mutex); | ||||
return UnwindBlock(config, state, pindex, true); | return UnwindBlock(state, pindex, true); | ||||
} | } | ||||
bool Chainstate::ParkBlock(const Config &config, BlockValidationState &state, | bool Chainstate::ParkBlock(BlockValidationState &state, CBlockIndex *pindex) { | ||||
CBlockIndex *pindex) { | |||||
AssertLockNotHeld(m_chainstate_mutex); | AssertLockNotHeld(m_chainstate_mutex); | ||||
AssertLockNotHeld(::cs_main); | AssertLockNotHeld(::cs_main); | ||||
// See 'Note for backport of Core PR16849' in Chainstate::UnwindBlock | // See 'Note for backport of Core PR16849' in Chainstate::UnwindBlock | ||||
LOCK(m_chainstate_mutex); | LOCK(m_chainstate_mutex); | ||||
return UnwindBlock(config, state, pindex, false); | return UnwindBlock(state, pindex, false); | ||||
} | } | ||||
template <typename F> | template <typename F> | ||||
bool Chainstate::UpdateFlagsForBlock(CBlockIndex *pindexBase, | bool Chainstate::UpdateFlagsForBlock(CBlockIndex *pindexBase, | ||||
CBlockIndex *pindex, F f) { | CBlockIndex *pindex, F f) { | ||||
BlockStatus newStatus = f(pindex->nStatus); | BlockStatus newStatus = f(pindex->nStatus); | ||||
if (pindex->nStatus != newStatus && | if (pindex->nStatus != newStatus && | ||||
(!pindexBase || | (!pindexBase || | ||||
▲ Show 20 Lines • Show All 2,980 Lines • Show Last 20 Lines |