Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,309 Lines • ▼ Show 20 Lines | static bool FinalizeBlockInternal(const Config &config, CValidationState &state, | ||||
if (pindexFinalized && !AreOnTheSameFork(pindex, pindexFinalized)) { | if (pindexFinalized && !AreOnTheSameFork(pindex, pindexFinalized)) { | ||||
return state.DoS( | return state.DoS( | ||||
20, error("%s: Trying to finalize block %s which conflicts " | 20, error("%s: Trying to finalize block %s which conflicts " | ||||
"with already finalized block", | "with already finalized block", | ||||
__func__, pindex->GetBlockHash().ToString()), | __func__, pindex->GetBlockHash().ToString()), | ||||
REJECT_AGAINST_FINALIZED, "bad-fork-prior-finalized"); | REJECT_AGAINST_FINALIZED, "bad-fork-prior-finalized"); | ||||
} | } | ||||
// If there is no finalized block yet, finalize our candidate. | |||||
// If the block to finalize is on the same chain that the current | |||||
// finalized block pointer, ensure that its height make the | |||||
// finalization moves forward. | |||||
// Otherwise, the block is already finalized, there is nothing to do. | |||||
if (!pindexFinalized || | |||||
(pindexFinalized && AreOnTheSameFork(pindex, pindexFinalized) && | |||||
(pindex->nHeight > pindexFinalized->nHeight))) { | |||||
// Our candidate is valid, finalize it. | // Our candidate is valid, finalize it. | ||||
pindexFinalized = pindex; | pindexFinalized = pindex; | ||||
} | |||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Connect a new block to chainActive. pblock is either nullptr or a pointer to | * Connect a new block to chainActive. pblock is either nullptr or a pointer to | ||||
* a CBlock corresponding to pindexNew, to bypass loading it again from disk. | * a CBlock corresponding to pindexNew, to bypass loading it again from disk. | ||||
* | * | ||||
* The block is always added to connectTrace (either after loading from disk or | * The block is always added to connectTrace (either after loading from disk or | ||||
▲ Show 20 Lines • Show All 3,125 Lines • Show Last 20 Lines |