Skip to content

Commit 8d11f13

Browse files
committed
Fix consensus bug: switch to wrong ledger when wrong validation received after right validation cleared
1 parent 1e455bf commit 8d11f13

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

src/peersafe/consensus/pop/impl/PopConsensus.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,20 @@ PopConsensus::checkLedger()
544544

545545
if (netLgr != prevLedgerID_)
546546
{
547-
JLOG(j_.warn()) << "View of consensus changed during "
548-
<< to_string(phase_) << " status=" << to_string(phase_)
549-
<< ", "
550-
<< " mode=" << to_string(mode_.get());
551-
JLOG(j_.warn()) << prevLedgerID_ << " to " << netLgr;
552-
JLOG(j_.warn()) << previousLedger_.getJson();
553-
JLOG(j_.debug()) << "State on consensus change " << getJson(true);
547+
//if (adaptor_.proposersValidated(netLgr) < adaptor_.getQuorum())
548+
// return;
549+
554550
handleWrongLedger(netLgr);
551+
if (prevLedgerID_ == netLgr)
552+
{
553+
JLOG(j_.warn())
554+
<< "View of consensus changed during " << to_string(phase_)
555+
<< " status=" << to_string(phase_) << ", "
556+
<< " mode=" << to_string(mode_.get());
557+
JLOG(j_.warn()) << prevLedgerID_ << " to " << netLgr;
558+
JLOG(j_.warn()) << previousLedger_.getJson();
559+
JLOG(j_.debug()) << "State on consensus change " << getJson(true);
560+
}
555561
}
556562
else if (previousLedger_.id() != prevLedgerID_)
557563
handleWrongLedger(netLgr);
@@ -563,6 +569,20 @@ PopConsensus::handleWrongLedger(typename Ledger_t::ID const& lgrId)
563569
{
564570
assert(lgrId != prevLedgerID_ || previousLedger_.id() != lgrId);
565571

572+
auto newLedger = adaptor_.acquireLedger(lgrId);
573+
if (!newLedger)
574+
return;
575+
576+
// check compatibility with newest valid ledger.
577+
if (!adaptor_.app_.getLedgerMaster().isCompatible(
578+
*(newLedger->ledger_),
579+
j_.warn(),
580+
"Not switching preferedLedger,"))
581+
{
582+
return;
583+
}
584+
585+
566586
// Stop proposing because we are out of sync
567587
leaveConsensus();
568588

@@ -578,8 +598,8 @@ PopConsensus::handleWrongLedger(typename Ledger_t::ID const& lgrId)
578598
return;
579599

580600
// we need to switch the ledger we're working from
581-
if (auto newLedger = adaptor_.acquireLedger(prevLedgerID_))
582-
{
601+
// if (auto newLedger = adaptor_.acquireLedger(lgrId))
602+
// {
583603
JLOG(j_.warn()) << "Have the consensus ledger when handleWrongLedger " << newLedger->seq()
584604
<< ":" << prevLedgerID_;
585605

@@ -592,11 +612,11 @@ PopConsensus::handleWrongLedger(typename Ledger_t::ID const& lgrId)
592612

593613
startRoundInternal(
594614
now_, lgrId, *newLedger, ConsensusMode::switchedLedger);
595-
}
596-
else
597-
{
598-
mode_.set(ConsensusMode::wrongLedger, adaptor_);
599-
}
615+
// }
616+
// else
617+
// {
618+
// mode_.set(ConsensusMode::wrongeLdger, adaptor_);
619+
// }
600620
}
601621

602622
void

src/ripple/app/ledger/impl/LedgerMaster.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ LedgerMaster::onConsensusReached(
284284

285285
if (waitingConsensusReach &&
286286
previousLedger &&
287-
previousLedger->info().seq != mValidLedgerSeq)
287+
previousLedger->info().seq != mValidLedgerSeq &&
288+
isCompatible(*previousLedger, m_journal.warn(), "Not switching when waitingConsensusReach,"))
288289
{
289290
setFullLedger(previousLedger, false, true);
290291
setPubLedger(previousLedger);

src/ripple/protocol/impl/BuildInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace BuildInfo {
3333
// and follow the format described at http://semver.org/
3434
//------------------------------------------------------------------------------
3535
// clang-format off
36-
char const* const versionString = "3.3.0"
36+
char const* const versionString = "3.3.1"
3737
// clang-format on
3838

3939
#if defined(DEBUG) || defined(SANITIZER)

0 commit comments

Comments
 (0)