Skip to content

Commit

Permalink
harden invariant in ballot protocol
Browse files Browse the repository at this point in the history
for clarity and to avoid false negatives in static analyzer
  • Loading branch information
MonsieurNicolas committed Apr 1, 2022
1 parent 8e956b6 commit 97f75e8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/scp/BallotProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,21 @@ BallotProtocol::emitCurrentStateStatement()
void
BallotProtocol::checkInvariants()
{
switch (mPhase)
{
case SCP_PHASE_PREPARE:
break;
case SCP_PHASE_CONFIRM:
case SCP_PHASE_EXTERNALIZE:
dbgAssert(mCurrentBallot);
dbgAssert(mPrepared);
dbgAssert(mCommit);
dbgAssert(mHighBallot);
break;
default:
dbgAbort();
}

if (mCurrentBallot)
{
dbgAssert(mCurrentBallot->getBallot().counter != 0);
Expand All @@ -664,21 +679,6 @@ BallotProtocol::checkInvariants()
dbgAssert(areBallotsLessAndCompatible(mHighBallot->getBallot(),
mCurrentBallot->getBallot()));
}

switch (mPhase)
{
case SCP_PHASE_PREPARE:
break;
case SCP_PHASE_CONFIRM:
dbgAssert(mCommit);
break;
case SCP_PHASE_EXTERNALIZE:
dbgAssert(mCommit);
dbgAssert(mHighBallot);
break;
default:
dbgAbort();
}
}

std::set<SCPBallot>
Expand Down

0 comments on commit 97f75e8

Please sign in to comment.