From 601db4491ac86e1ba1503437ff403ac5dda57b12 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 14 Nov 2012 08:47:36 -0800 Subject: [PATCH] Track when we have to abandon the consensus process because the network has moved on. Issue partial validation if appropriate later. Change the consensus abort threshold to 80% of trusted nodes. (Maybe there should be a delay?) --- src/cpp/ripple/LedgerConsensus.cpp | 8 ++++---- src/cpp/ripple/LedgerConsensus.h | 2 +- src/cpp/ripple/LedgerTiming.cpp | 11 +++++++---- src/cpp/ripple/LedgerTiming.h | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index 8eeff15710..8daade3bdf 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -267,7 +267,7 @@ bool LCTransaction::updateVote(int percentTime, bool proposing) LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime) : mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger), - mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), + mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), mConsensusFail(false), mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false), mConsensusStartTime(boost::posix_time::microsec_clock::universal_time()) { @@ -800,7 +800,7 @@ bool LedgerConsensus::haveConsensus(bool forReal) cLog(lsDEBUG) << "Checking for TX consensus: agree=" << agree << ", disagree=" << disagree; return ContinuousLedgerTiming::haveConsensus(mPreviousProposers, agree + disagree, agree, currentValidations, - mPreviousMSeconds, mCurrentMSeconds, forReal); + mPreviousMSeconds, mCurrentMSeconds, forReal, mConsensusFail); } SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool doAcquire) @@ -1224,7 +1224,7 @@ void LedgerConsensus::accept(SHAMap::ref set) } statusChange(ripple::neACCEPTED_LEDGER, *newLCL); - if (mValidating) + if (mValidating && !mConsensusFail) { uint256 signingHash; SerializedValidation::pointer v = boost::make_shared @@ -1271,7 +1271,7 @@ void LedgerConsensus::accept(SHAMap::ref set) cLog(lsINFO) << "Applying transactions from current ledger"; applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, newLCL, failedTransactions, true); - theApp->getMasterLedger().pushLedger(newLCL, newOL, true); + theApp->getMasterLedger().pushLedger(newLCL, newOL, !mConsensusFail); mNewLedgerHash = newLCL->getHash(); mState = lcsACCEPTED; sl.unlock(); diff --git a/src/cpp/ripple/LedgerConsensus.h b/src/cpp/ripple/LedgerConsensus.h index 9f16e9df81..3b66fa9f42 100644 --- a/src/cpp/ripple/LedgerConsensus.h +++ b/src/cpp/ripple/LedgerConsensus.h @@ -91,7 +91,7 @@ protected: LedgerAcquire::pointer mAcquiringLedger; LedgerProposal::pointer mOurPosition; RippleAddress mValPublic, mValPrivate; - bool mProposing, mValidating, mHaveCorrectLCL; + bool mProposing, mValidating, mHaveCorrectLCL, mConsensusFail; int mCurrentMSeconds, mClosePercent, mCloseResolution; bool mHaveCloseTimeConsensus; diff --git a/src/cpp/ripple/LedgerTiming.cpp b/src/cpp/ripple/LedgerTiming.cpp index 6119123a4f..dd92c953cf 100644 --- a/src/cpp/ripple/LedgerTiming.cpp +++ b/src/cpp/ripple/LedgerTiming.cpp @@ -63,7 +63,8 @@ bool ContinuousLedgerTiming::haveConsensus( int currentFinished, // proposers who have validated a ledger after this one int previousAgreeTime, // how long it took to agree on the last ledger int currentAgreeTime, // how long we've been trying to agree - bool forReal) // deciding whether to stop consensus process + bool forReal, // deciding whether to stop consensus process + bool& failed) // we can't reach a consensus { cLog(lsTRACE) << boost::str(boost::format("CLC::haveConsensus: prop=%d/%d agree=%d validated=%d time=%d/%d%s") % currentProposers % previousProposers % currentAgree % currentFinished % currentAgreeTime % previousAgreeTime % @@ -85,13 +86,15 @@ bool ContinuousLedgerTiming::haveConsensus( if (((currentAgree * 100 + 100) / (currentProposers + 1)) > 80) { tLog(forReal, lsINFO) << "normal consensus"; + failed = false; return true; } - // If 50% of the nodes on your UNL have moved on, you should declare consensus - if (((currentFinished * 100) / (currentProposers + 1)) > 50) + // If 80% of the nodes on your UNL have moved on, you should declare consensus + if (((currentFinished * 100) / (currentProposers + 1)) > 80) { - tLog(forReal, lsWARNING) << "We see no consensus, but 50% of nodes have moved on"; + tLog(forReal, lsWARNING) << "We see no consensus, but 80% of nodes have moved on"; + failed = true; return true; } diff --git a/src/cpp/ripple/LedgerTiming.h b/src/cpp/ripple/LedgerTiming.h index 6cf535c40c..821eb60730 100644 --- a/src/cpp/ripple/LedgerTiming.h +++ b/src/cpp/ripple/LedgerTiming.h @@ -66,7 +66,7 @@ public: int previousProposers, int currentProposers, int currentAgree, int currentClosed, int previousAgreeTime, int currentAgreeTime, - bool forReal); + bool forReal, bool& failed); static int getNextLedgerTimeResolution(int previousResolution, bool previousAgree, int ledgerSeq); };