From 4b97f422f39ad5d8385c2dc0ee31221e7d93863c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 1 Mar 2013 13:46:13 -0800 Subject: [PATCH] Rework how we declare a close time consensus to prevent stalls. --- src/cpp/ripple/LedgerConsensus.cpp | 37 +++++++++++++++++++----------- src/cpp/ripple/LedgerTiming.h | 15 ++++++------ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index 53c6148150..b9816ede8f 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -762,47 +762,58 @@ void LedgerConsensus::updateOurPositions() int neededWeight; + if (mClosePercent < AV_MID_CONSENSUS_TIME) neededWeight = AV_INIT_CONSENSUS_PCT; else if (mClosePercent < AV_LATE_CONSENSUS_TIME) neededWeight = AV_MID_CONSENSUS_PCT; - else + else if (mClosePercent < AV_STUCK_CONSENSUS_TIME) neededWeight = AV_LATE_CONSENSUS_PCT; + else + neededWeight = AV_STUCK_CONSENSUS_PCT; uint32 closeTime = 0; mHaveCloseTimeConsensus = false; - int thresh = mPeerPositions.size(); - if (thresh == 0) + if (mPeerPositions.empty()) { // no other times mHaveCloseTimeConsensus = true; closeTime = roundCloseTime(mOurPosition->getCloseTime()); } else { + int threshVote = mPeerPositions.size(); // Threshold for non-zero vote + int threshConsensus = mPeerPositions.size(); // Threshold to declare consensus if (mProposing) { ++closeTimes[roundCloseTime(mOurPosition->getCloseTime())]; - ++thresh; + ++threshVote; + ++threshConsensus; } - thresh = ((thresh * neededWeight) + (neededWeight / 2)) / 100; - if (thresh == 0) - thresh = 1; - cLog(lsINFO) << "Proposers:" << mPeerPositions.size() << " nw:" << neededWeight << " thr:" << thresh; + threshVote = ((threshVote * neededWeight) + (neededWeight / 2)) / 100; + threshConsensus = ((threshConsensus * AV_CT_CONSENSUS_PCT) + (AV_CT_CONSENSUS_PCT / 2)) / 100; + + if (threshVote == 0) + threshVote = 1; + if (threshConsensus == 0) + threshConsensus = 1; + cLog(lsINFO) << "Proposers:" << mPeerPositions.size() << " nw:" << neededWeight + << " thrV:" << threshVote << " thrC:" << threshConsensus; for (std::map::iterator it = closeTimes.begin(), end = closeTimes.end(); it != end; ++it) { - cLog(lsDEBUG) << "CCTime: " << it->first << " has " << it->second << ", " << thresh << " required"; - if (it->second >= thresh) + cLog(lsDEBUG) << "CCTime: " << it->first << " has " << it->second << ", " << threshVote << " required"; + if (it->second >= threshVote) { cLog(lsDEBUG) << "Close time consensus reached: " << it->first; - mHaveCloseTimeConsensus = true; closeTime = it->first; - thresh = it->second; + threshVote = it->second; + if (threshVote >= threshConsensus) + mHaveCloseTimeConsensus = true; } } tLog(!mHaveCloseTimeConsensus, lsDEBUG) << "No CT consensus: Proposers:" << mPeerPositions.size() - << " Proposing:" << (mProposing ? "yes" : "no") << " Thresh:" << thresh << " Pos:" << closeTime; + << " Proposing:" << (mProposing ? "yes" : "no") << " Thresh:" << threshConsensus << " Pos:" << closeTime; } if (!changes && diff --git a/src/cpp/ripple/LedgerTiming.h b/src/cpp/ripple/LedgerTiming.h index db8fc8b942..c7539c081a 100644 --- a/src/cpp/ripple/LedgerTiming.h +++ b/src/cpp/ripple/LedgerTiming.h @@ -39,17 +39,18 @@ # define PROPOSE_INTERVAL 12 // Avalanche tuning -#define AV_INIT_CONSENSUS_PCT 50 // percentage of nodes on our UNL that must vote yes +# define AV_INIT_CONSENSUS_PCT 50 // percentage of nodes on our UNL that must vote yes -#define AV_MID_CONSENSUS_TIME 50 // percentage of previous close time before we advance -#define AV_MID_CONSENSUS_PCT 65 // percentage of nodes that most vote yes after advancing +# define AV_MID_CONSENSUS_TIME 50 // percentage of previous close time before we advance +# define AV_MID_CONSENSUS_PCT 65 // percentage of nodes that most vote yes after advancing -#define AV_LATE_CONSENSUS_TIME 85 // percentage of previous close time before we advance -#define AV_LATE_CONSENSUS_PCT 70 // percentage of nodes that most vote yes after advancing +# define AV_LATE_CONSENSUS_TIME 85 // percentage of previous close time before we advance +# define AV_LATE_CONSENSUS_PCT 70 // percentage of nodes that most vote yes after advancing -#define AV_STUCK_CONSENSUS_TIME 200 -#define AV_STUCK_CONSENSUS_PCT 95 +# define AV_STUCK_CONSENSUS_TIME 200 +# define AV_STUCK_CONSENSUS_PCT 95 +# define AV_CT_CONSENSUS_PCT 75 class ContinuousLedgerTiming {