More of the close time resolution code.

This commit is contained in:
JoelKatz
2012-07-11 18:25:47 -07:00
parent f71469f55c
commit 34935be1f4
2 changed files with 39 additions and 0 deletions

View File

@@ -1,6 +1,10 @@
#include "LedgerTiming.h"
#include <cassert>
// 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;
}

View File

@@ -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