From e11c605c1d85363f6d57e61eef36dc4129afe70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20S=C3=A9chet?= Date: Sun, 27 May 2018 22:55:09 +0200 Subject: [PATCH] Use BlockStatus's modifier function to update status's value. Summary: As per title. Most of the code doesn't need to know about the internal layour of the status's field. Depends on D1461 Test Plan: make check Reviewers: #bitcoin_abc, schancel Reviewed By: #bitcoin_abc, schancel Subscribers: teamcity Differential Revision: https://reviews.bitcoinabc.org/D1462 --- src/chain.h | 12 ------------ src/validation.cpp | 18 +++++++++--------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/chain.h b/src/chain.h index b80b031190..4366893eeb 100644 --- a/src/chain.h +++ b/src/chain.h @@ -264,18 +264,6 @@ struct BlockStatus { return withFailed(false).withFailedParent(false); } - // To transition from this and the plain old intereger. - // TODO: delete. - BlockStatus &operator&=(uint32_t rhs) { - this->status &= rhs; - return *this; - } - - BlockStatus &operator|=(uint32_t rhs) { - this->status |= rhs; - return *this; - } - ADD_SERIALIZE_METHODS; template diff --git a/src/validation.cpp b/src/validation.cpp index ac0aac09f0..ca87e6dbd0 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1444,7 +1444,7 @@ static void InvalidChainFound(CBlockIndex *pindexNew) { static void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) { if (!state.CorruptionPossible()) { - pindex->nStatus |= BLOCK_FAILED_VALID; + pindex->nStatus = pindex->nStatus.withFailed(); setDirtyBlockIndex.insert(pindex); setBlockIndexCandidates.erase(pindex); InvalidChainFound(pindex); @@ -2304,7 +2304,7 @@ static bool ConnectBlock(const Config &config, const CBlock &block, // update nUndoPos in block index pindex->nUndoPos = _pos.nPos; - pindex->nStatus |= BLOCK_HAVE_UNDO; + pindex->nStatus = pindex->nStatus.withUndo(); } pindex->RaiseValidity(BlockValidity::SCRIPTS); @@ -2888,7 +2888,8 @@ static CBlockIndex *FindMostWorkChain() { // Remove the entire chain from the set. while (pindexTest != pindexFailed) { if (fInvalidChain) { - pindexFailed->nStatus |= BLOCK_FAILED_CHILD; + pindexFailed->nStatus = + pindexFailed->nStatus.withFailedParent(); } else if (fMissingData) { // If we're missing data, then add back to // mapBlocksUnlinked, so that if the block arrives in @@ -3176,14 +3177,14 @@ bool InvalidateBlock(const Config &config, CValidationState &state, AssertLockHeld(cs_main); // Mark the block itself as invalid. - pindex->nStatus |= BLOCK_FAILED_VALID; + pindex->nStatus = pindex->nStatus.withFailed(); setDirtyBlockIndex.insert(pindex); setBlockIndexCandidates.erase(pindex); DisconnectedBlockTransactions disconnectpool; while (chainActive.Contains(pindex)) { CBlockIndex *pindexWalk = chainActive.Tip(); - pindexWalk->nStatus |= BLOCK_FAILED_CHILD; + pindexWalk->nStatus = pindexWalk->nStatus.withFailedParent(); setDirtyBlockIndex.insert(pindexWalk); setBlockIndexCandidates.erase(pindexWalk); // ActivateBestChain considers blocks already in chainActive @@ -3307,7 +3308,7 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, pindexNew->nFile = pos.nFile; pindexNew->nDataPos = pos.nPos; pindexNew->nUndoPos = 0; - pindexNew->nStatus |= BLOCK_HAVE_DATA; + pindexNew->nStatus = pindexNew->nStatus.withData(); pindexNew->RaiseValidity(BlockValidity::TRANSACTIONS); setDirtyBlockIndex.insert(pindexNew); @@ -3954,7 +3955,7 @@ static bool AcceptBlock(const Config &config, if (!CheckBlock(config, block, state) || !ContextualCheckBlock(config, block, state, pindex->pprev)) { if (state.IsInvalid() && !state.CorruptionPossible()) { - pindex->nStatus |= BLOCK_FAILED_VALID; + pindex->nStatus = pindex->nStatus.withFailed(); setDirtyBlockIndex.insert(pindex); } return error("%s: %s (block %s)", __func__, FormatStateMessage(state), @@ -4107,8 +4108,7 @@ void PruneOneBlockFile(const int fileNumber) { for (const std::pair &it : mapBlockIndex) { CBlockIndex *pindex = it.second; if (pindex->nFile == fileNumber) { - pindex->nStatus &= ~BLOCK_HAVE_DATA; - pindex->nStatus &= ~BLOCK_HAVE_UNDO; + pindex->nStatus = pindex->nStatus.withData(false).withUndo(false); pindex->nFile = 0; pindex->nDataPos = 0; pindex->nUndoPos = 0;