Skip to content

Commit 6355774

Browse files
committed
Removal of the fAlreadyChecked flag from the entire ActivateBestChain flow.
1 parent 362a598 commit 6355774

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/validation.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,11 +1425,11 @@ static int64_t nTimeTotal = 0;
14251425
/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
14261426
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
14271427
* can fail if those validity checks fail (among other reasons). */
1428-
static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck = false, bool fAlreadyChecked = false)
1428+
static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck = false)
14291429
{
14301430
AssertLockHeld(cs_main);
14311431
// Check it again in case a previous version let a bad block in
1432-
if (!fAlreadyChecked && !CheckBlock(block, state, !fJustCheck, !fJustCheck, !fJustCheck)) {
1432+
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck, !fJustCheck)) {
14331433
if (state.CorruptionPossible()) {
14341434
// We don't write down blocks to disk if they may have been
14351435
// corrupted, so this should be impossible unless we're having hardware
@@ -2055,15 +2055,12 @@ class ConnectTrace {
20552055
*
20562056
* The block is added to connectTrace if connection succeeds.
20572057
*/
2058-
bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, bool fAlreadyChecked, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool)
2058+
bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool)
20592059
{
20602060
AssertLockHeld(cs_main);
20612061
AssertLockHeld(mempool.cs);
20622062
assert(pindexNew->pprev == chainActive.Tip());
20632063

2064-
if (pblock == NULL)
2065-
fAlreadyChecked = false;
2066-
20672064
// Read block from disk.
20682065
int64_t nTime1 = GetTimeMicros();
20692066
std::shared_ptr<const CBlock> pthisBlock;
@@ -2084,7 +2081,7 @@ bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, const st
20842081
LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
20852082
{
20862083
CCoinsViewCache view(pcoinsTip);
2087-
bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, false, fAlreadyChecked);
2084+
bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, false);
20882085
GetMainSignals().BlockChecked(blockConnecting, state);
20892086
if (!rv) {
20902087
if (state.IsInvalid())
@@ -2205,12 +2202,10 @@ static void PruneBlockIndexCandidates()
22052202
* Try to make some progress towards making pindexMostWork the active block.
22062203
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
22072204
*/
2208-
static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool fAlreadyChecked, bool& fInvalidFound, ConnectTrace& connectTrace)
2205+
static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace)
22092206
{
22102207
AssertLockHeld(cs_main);
22112208
AssertLockHeld(mempool.cs);
2212-
if (pblock == NULL)
2213-
fAlreadyChecked = false;
22142209
const CBlockIndex* pindexOldTip = chainActive.Tip();
22152210
const CBlockIndex* pindexFork = chainActive.FindFork(pindexMostWork);
22162211

@@ -2246,7 +2241,7 @@ static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMo
22462241

22472242
// Connect new blocks.
22482243
for (CBlockIndex* pindexConnect : reverse_iterate(vpindexToConnect)) {
2249-
if (!ConnectTip(state, pindexConnect, (pindexConnect == pindexMostWork) ? pblock : std::shared_ptr<const CBlock>(), fAlreadyChecked, connectTrace, disconnectpool)) {
2244+
if (!ConnectTip(state, pindexConnect, (pindexConnect == pindexMostWork) ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
22502245
if (state.IsInvalid()) {
22512246
// The block violates a consensus rule.
22522247
if (!state.CorruptionPossible())
@@ -2295,7 +2290,7 @@ static bool ActivateBestChainStep(CValidationState& state, CBlockIndex* pindexMo
22952290
* that is already loaded (to avoid loading it again from disk).
22962291
*/
22972292

2298-
bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pblock, bool fAlreadyChecked)
2293+
bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pblock)
22992294
{
23002295
// Note that while we're often called here from ProcessNewBlock, this is
23012296
// far from a guarantee. Things in the P2P/RPC will often end up calling
@@ -2342,7 +2337,7 @@ bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pb
23422337

23432338
bool fInvalidFound = false;
23442339
std::shared_ptr<const CBlock> nullBlockPtr;
2345-
if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fAlreadyChecked, fInvalidFound, connectTrace))
2340+
if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connectTrace))
23462341
return false;
23472342
blocks_connected = true;
23482343

@@ -3378,7 +3373,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_pt
33783373
newHeight = pindex->nHeight;
33793374
}
33803375

3381-
if (!ActivateBestChain(state, pblock, checked))
3376+
if (!ActivateBestChain(state, pblock))
33823377
return error("%s : ActivateBestChain failed", __func__);
33833378

33843379
if (!fLiteMode) {

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ double ConvertBitsToDouble(unsigned int nBits);
209209
int64_t GetMasternodePayment();
210210

211211
/** Find the best known block, and make it the tip of the block chain */
212-
bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>(), bool fAlreadyChecked = false);
212+
bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
213213
CAmount GetBlockValue(int nHeight);
214214

215215
/** Create a new block index entry for a given block hash */

0 commit comments

Comments
 (0)