From 97f75e88b4a30cb22410d81bd3f67befc8e3a9b0 Mon Sep 17 00:00:00 2001 From: MonsieurNicolas Date: Thu, 31 Mar 2022 18:10:22 -0700 Subject: [PATCH] harden invariant in ballot protocol for clarity and to avoid false negatives in static analyzer --- src/scp/BallotProtocol.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/scp/BallotProtocol.cpp b/src/scp/BallotProtocol.cpp index e96a7fc243..55a6da810f 100644 --- a/src/scp/BallotProtocol.cpp +++ b/src/scp/BallotProtocol.cpp @@ -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); @@ -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