Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
consensus changes: faster catch up, delay when out of sync
Browse files Browse the repository at this point in the history
* Consider there is consensus when we detect that we've fallen behind (old code was waiting to reach consensus with other part of the network); this increases the chance that we catch up to the network.
* If we can't catch up to the last closed ledger in SQL consider ourselves syncing
  • Loading branch information
MonsieurNicolas committed Nov 18, 2014
1 parent a4d6790 commit 067d715
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ripple_app/consensus/LedgerConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LedgerConsensusImp
(boost::posix_time::microsec_clock::universal_time ())
{
WriteLog (lsDEBUG, LedgerConsensus) << "Creating consensus object";
WriteLog (lsTRACE, LedgerConsensus)
WriteLog (lsDEBUG, LedgerConsensus)
<< "LCL:" << previousLedger->getHash () << ", ct=" << closeTime;
mPreviousProposers = getApp().getOPs ().getPreviousProposers ();
mPreviousMSeconds = getApp().getOPs ().getPreviousConvergeTime ();
Expand Down
5 changes: 4 additions & 1 deletion src/ripple_app/ledger/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,11 @@ class LedgerMasterImp

InboundLedger::pointer l =
getApp().getInboundLedgers().findCreate(hash, 0, InboundLedger::fcGENERIC);
if (l && l->isComplete() && !l->isFailed())
if (l && l->isComplete() && !l->isFailed()) {
WriteLog (lsDEBUG, LedgerMaster) <<
"checkAccept has complete ledger " << to_string (hash);
ledger = l->getLedger();
}
else
{
WriteLog (lsDEBUG, LedgerMaster) <<
Expand Down
40 changes: 25 additions & 15 deletions src/ripple_app/ledger/LedgerTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool ContinuousLedgerTiming::haveConsensus (
bool forReal, // deciding whether to stop consensus process
bool& failed) // we can't reach a consensus
{
WriteLog (lsTRACE, LedgerTiming) <<
WriteLog (lsDEBUG, LedgerTiming) <<
"CLC::haveConsensus: prop=" << currentProposers <<
"/" << previousProposers <<
" agree=" << currentAgree << " validated=" << currentFinished <<
Expand All @@ -131,39 +131,49 @@ bool ContinuousLedgerTiming::haveConsensus (
return true;
}

if(currentAgreeTime <= LEDGER_MIN_CONSENSUS_TIME)
// move on asap if we are behind
// If 80% of the nodes on your UNL have moved on, you should declare consensus
if (((currentFinished * 100) / (currentProposers + 1)) > 80)
{
CondLog (forReal, lsWARNING, LedgerTiming) <<
"We see no consensus, but 80% of nodes have moved on";
failed = true;
return true;
}

if (currentAgreeTime <= LEDGER_MIN_CONSENSUS_TIME)
{
return false;
}

if (currentProposers < (previousProposers * 3 / 4))
{
/* SANITY: probably need to not allow for this and replace the code with :
CondLog (forReal, lsDEBUG, LedgerTiming) << "cannot enter consensus: too few proposers";
return false;
*/

// Less than 3/4 of the last ledger's proposers are present, we may need more time
if(currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS_TIME))
if (currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS_TIME))
{
WriteLog(lsTRACE, LedgerTiming) <<
CondLog (forReal, lsDEBUG, LedgerTiming) <<
"too fast, not enough proposers";
return false;
}
CondLog (forReal, lsDEBUG, LedgerTiming) <<
"Ignoring lack of proposers as we're " << (currentAgreeTime - previousAgreeTime) << " ms passed last concensus";
}

// If 80% of current proposers (plus us) agree on a set, we have consensus
if (((currentAgree * 100 + 100) / (currentProposers + 1)) > 80)
{
WriteLog(lsTRACE, LedgerTiming) << "normal consensus";
CondLog (forReal, lsINFO, LedgerTiming) << "normal consensus";
failed = false;
return true;
}

// If 80% of the nodes on your UNL have moved on, you should declare consensus
if (((currentFinished * 100) / (currentProposers + 1)) > 80)
{
WriteLog(lsTRACE, LedgerTiming) <<
"We see no consensus, but 80% of nodes have moved on";
failed = true;
return true;
}

// no consensus yet
WriteLog(lsTRACE, LedgerTiming) << "no consensus";
CondLog (forReal, lsDEBUG, LedgerTiming) << "no consensus";
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions src/ripple_app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,15 @@ int NetworkOPsImp::beginConsensus (uint256 const& networkClosed, Ledger::pointer

return 3;
}
else if (!stellar::gLedgerMaster->ensureSync(prevLedger, true))
{
if (mMode == omTRACKING || mMode == omFULL)
{
m_journal.warning << "Don't have LCL in database, going back to syncing";
setMode (omSYNCING);
}
return 3;
}

assert (prevLedger->getHash () == closingLedger->getParentHash ());
assert (closingLedger->getParentHash () == m_ledgerMaster.getClosedLedger ()->getHash ());
Expand Down
2 changes: 1 addition & 1 deletion src/ripple_core/functional/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Config::Config ()

TRANSACTION_FEE_BASE = DEFAULT_FEE_DEFAULT;

NETWORK_QUORUM = 0; // Don't need to see other nodes
NETWORK_QUORUM = 1;
VALIDATION_QUORUM = 1; // Only need one node to vouch

FEE_ACCOUNT_RESERVE = DEFAULT_FEE_ACCOUNT_RESERVE;
Expand Down

0 comments on commit 067d715

Please sign in to comment.