Skip to content

Commit

Permalink
Use BlockStatus's modifier function to update status's value.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
deadalnix committed May 29, 2018
1 parent f942c80 commit e11c605
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
12 changes: 0 additions & 12 deletions src/chain.h
Expand Up @@ -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 <typename Stream, typename Operation>
Expand Down
18 changes: 9 additions & 9 deletions src/validation.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -4107,8 +4108,7 @@ void PruneOneBlockFile(const int fileNumber) {
for (const std::pair<const uint256, CBlockIndex *> &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;
Expand Down

0 comments on commit e11c605

Please sign in to comment.