From 34935be1f41e5345f585303f40f9fb0255587bfa Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 11 Jul 2012 18:25:47 -0700 Subject: [PATCH] More of the close time resolution code. --- src/LedgerTiming.cpp | 26 ++++++++++++++++++++++++++ src/LedgerTiming.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/LedgerTiming.cpp b/src/LedgerTiming.cpp index b6fb422379..b7a3b77344 100644 --- a/src/LedgerTiming.cpp +++ b/src/LedgerTiming.cpp @@ -1,6 +1,10 @@ #include "LedgerTiming.h" +#include + +// NOTE: Last time must be repeated +int ContinuousLedgerTiming::LedgerTimeResolution[] = { 10, 20, 30, 60, 90, 120, 120 }; // Called when a ledger is open and no close is in progress -- when a transaction is received and no close // is in process, or when a close completes. Returns the number of seconds the ledger should be be open. @@ -62,3 +66,25 @@ bool ContinuousLedgerTiming::haveConsensus( // no consensus yet return false; } + +int ContinuousLedgerTiming::getNextLedgerTimeResolution(int previousResolution, bool previousAgree, int ledgerSeq) +{ + assert(ledgerSeq); + if ((!previousAgree) && ((ledgerSeq % LEDGER_RES_DECREASE) == 0)) + { // reduce resolution + int i = 0; + while (LedgerTimeResolution[i] != previousResolution) + ++i; + return LedgerTimeResolution[(i != 0) ? (i - 1) : i]; + } + + if ((previousAgree) && ((ledgerSeq % LEDGER_RES_INCREASE) == 0)) + { // increase resolution + int i = 0; + while (LedgerTimeResolution[i] != previousResolution) + ++i; + return LedgerTimeResolution[i + 1]; + } + + return previousResolution; +} diff --git a/src/LedgerTiming.h b/src/LedgerTiming.h index de463a085e..2b580a6057 100644 --- a/src/LedgerTiming.h +++ b/src/LedgerTiming.h @@ -10,6 +10,15 @@ // The number of seconds we wait minimum to ensure participation # define LEDGER_MIN_CONSENSUS 2 +// Initial resolution of ledger close time +# define LEDGER_TIME_ACCURACY 30 + +// How often to increase resolution +# define LEDGER_RES_INCREASE 8 + +// How often to decrease resolution +# define LEDGER_RES_DECREASE 1 + // Avalanche tuning #define AV_INIT_CONSENSUS_PCT 50 // percentage of nodes on our UNL that must vote yes @@ -19,10 +28,13 @@ #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 + class ContinuousLedgerTiming { public: + static int LedgerTimeResolution[]; + // Returns the number of seconds the ledger was or should be open // Call when a consensus is reached and when any transaction is relayed to be added static int shouldClose( @@ -35,6 +47,7 @@ public: int currentAgree, int currentClosed, int previousAgreeTime, int currentAgreeTime); + static int getNextLedgerTimeResolution(int previousResolution, bool previousAgree, int ledgerSeq); }; #endif