More debug.

This commit is contained in:
JoelKatz
2012-07-13 10:25:04 -07:00
parent 34c5a22d81
commit db2e9f83dd
2 changed files with 36 additions and 8 deletions

View File

@@ -3,6 +3,10 @@
#include <cassert>
#include <boost/format.hpp>
#include "Log.h"
// NOTE: First and last times must be repeated
int ContinuousLedgerTiming::LedgerTimeResolution[] = { 10, 10, 20, 30, 60, 90, 120, 120 };
@@ -15,24 +19,32 @@ int ContinuousLedgerTiming::shouldClose(
int previousSeconds, // seconds the previous ledger took to reach consensus
int currentSeconds) // seconds since the previous ledger closed
{
Log(lsTRACE) << boost::str(boost::format("CLC::shouldClose Trans=%s, Prop: %d/%d, Secs: %d/%d") %
(anyTransactions ? "yes" : "no") % previousProposers % proposersClosed % previousSeconds % currentSeconds);
if (!anyTransactions)
{ // no transactions so far this interval
if (proposersClosed > (previousProposers / 4)) // did we miss a transaction?
{
Log(lsTRACE) << "no transactions, many proposers: now";
return currentSeconds;
}
if (previousSeconds > (LEDGER_IDLE_INTERVAL + 2)) // the last ledger was very slow to close
{
Log(lsTRACE) << "slow to close";
return previousSeconds - 1;
}
Log(lsTRACE) << "normal idle";
return LEDGER_IDLE_INTERVAL; // normal idle
}
if (previousSeconds == LEDGER_IDLE_INTERVAL) // coming out of idle, close now
{
Log(lsTRACE) << "leaving idle, close now";
return currentSeconds;
}
// If the network is slow, try to synchronize close times
if (previousSeconds > 8)
return (currentSeconds - currentSeconds % 4);
else if (previousSeconds > 4)
return (currentSeconds - currentSeconds % 2);
Log(lsTRACE) << "close now";
return currentSeconds; // this ledger should close now
}
@@ -46,24 +58,40 @@ bool ContinuousLedgerTiming::haveConsensus(
int previousAgreeTime, // how long it took to agree on the last ledger
int currentAgreeTime) // how long we've been trying to agree
{
Log(lsTRACE) << boost::str(boost::format("CLC::haveConsensus: prop=%d/%d agree=%d closed=%d time=%d/%d") %
previousProposers % currentProposers % currentAgree % currentClosed % previousAgreeTime % currentAgreeTime);
if (currentAgreeTime <= LEDGER_MIN_CONSENSUS)
{
Log(lsTRACE) << "too fast";
return false;
}
if (currentProposers < (previousProposers * 3 / 4))
{ // Less than 3/4 of the last ledger's proposers are present, we may need more time
if (currentAgreeTime < (previousAgreeTime + 2))
{
Log(lsTRACE) << "too fast, not enough proposers";
return false;
}
}
// If 80% of current proposers (plus us) agree on a set, we have consensus
if (((currentAgree * 100 + 100) / (currentProposers + 1)) > 80)
{
Log(lsTRACE) << "normal consensus";
return true;
}
// If 50% of the nodes on your UNL (minus us) have closed, you should close
if (((currentClosed * 100 - 100) / (currentProposers + 1)) > 50)
{
Log(lsTRACE) << "many closers";
return true;
}
// no consensus yet
Log(lsTRACE) << "no consensus";
return false;
}

View File

@@ -482,7 +482,7 @@ void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer closingLedger)
{
Log(lsINFO) << "Ledger close time for ledger " << closingLedger->getLedgerSeq();
Log(lsINFO) << "Consensus time for ledger " << closingLedger->getLedgerSeq();
Log(lsINFO) << " LCL is " << closingLedger->getParentHash().GetHex();
Ledger::pointer prevLedger = mLedgerMaster->getLedgerByHash(closingLedger->getParentHash());
@@ -502,7 +502,7 @@ int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer clo
mConsensus = boost::make_shared<LedgerConsensus>(
networkClosed, prevLedger, theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC());
Log(lsDEBUG) << "Pre-close time, initiating consensus engine";
Log(lsDEBUG) << "Initiating consensus engine";
return mConsensus->startup();
}