Configurable fetch depth.

This commit is contained in:
JoelKatz
2014-02-13 15:37:28 -08:00
committed by Vinnie Falco
parent f2beb82b97
commit 996326a00e
8 changed files with 86 additions and 22 deletions

View File

@@ -494,6 +494,20 @@
#
#
#
# [fetch_depth]
#
# The number of past ledgers to serve to other peers that request historical
# ledger data (or "full" for no limit).
#
# Servers that require low latency and high local performance may wish to
# restrict the historical ledgers they are willing to serve. Setting this
# below 32 can harm network stability as servers require easy access to
# recent history to stay in sync. Values below 128 are not recommended.
#
# The default is: full
#
#
#
# [validation_seed]
#
# To perform validation, this section should contain either a validation seed

View File

@@ -1445,6 +1445,13 @@ private:
uMin = 0;
uMax = 0;
}
else
{
// Don't advertise ledgers we're not willing to serve
uint32 early = getApp().getLedgerMaster().getEarliestFetch ();
if (uMin < early)
uMin = early;
}
s.set_firstseq (uMin);
s.set_lastseq (uMax);
getApp ().getPeers ().foreach (send_always (

View File

@@ -424,6 +424,14 @@ public:
return true;
}
uint32 getEarliestFetch ()
{
uint32 e = getClosedLedger()->getLedgerSeq();
if (e > getConfig().FETCH_DEPTH)
e -= getConfig().FETCH_DEPTH;
return e;
}
void tryFill (Job& job, Ledger::pointer ledger)
{
uint32 seq = ledger->getLedgerSeq ();

View File

@@ -73,6 +73,8 @@ public:
virtual void setMinValidations (int v) = 0;
virtual uint32 getEarliestFetch () = 0;
virtual void pushLedger (Ledger::pointer newLedger) = 0;
virtual void pushLedger (Ledger::pointer newLCL, Ledger::pointer newOL) = 0;
virtual void storeLedger (Ledger::pointer) = 0;

View File

@@ -130,6 +130,7 @@ Config::Config ()
FEE_CONTRACT_OPERATION = DEFAULT_FEE_OPERATION;
LEDGER_HISTORY = 256;
FETCH_DEPTH = 1000000000;
PATH_SEARCH_OLD = DEFAULT_PATH_SEARCH_OLD;
PATH_SEARCH = DEFAULT_PATH_SEARCH;
@@ -533,13 +534,25 @@ void Config::load ()
{
boost::to_lower (strTemp);
if (strTemp == "none")
LEDGER_HISTORY = 0;
else if (strTemp == "full")
if (strTemp == "full")
LEDGER_HISTORY = 1000000000u;
else
LEDGER_HISTORY = lexicalCastThrow <uint32> (strTemp);
}
if (SectionSingleB (secConfig, SECTION_FETCH_DEPTH, strTemp))
{
boost::to_lower (strTemp);
if (strTemp == "none")
FETCH_DEPTH = 0;
else if (strTemp == "full")
FETCH_DEPTH = 1000000000u;
else
FETCH_DEPTH = lexicalCastThrow <uint32> (strTemp);
if (FETCH_DEPTH < 10)
FETCH_DEPTH = 10;
}
if (SectionSingleB (secConfig, SECTION_PATH_SEARCH_OLD, strTemp))
PATH_SEARCH_OLD = lexicalCastThrow <int> (strTemp);

View File

@@ -446,6 +446,7 @@ public:
// Node storage configuration
uint32 LEDGER_HISTORY;
uint32 FETCH_DEPTH;
int NODE_SIZE;
// Client behavior

View File

@@ -46,6 +46,7 @@ struct ConfigSection
#define SECTION_FEE_OPERATION "fee_operation"
#define SECTION_FEE_ACCOUNT_RESERVE "fee_account_reserve"
#define SECTION_FEE_OWNER_RESERVE "fee_owner_reserve"
#define SECTION_FETCH_DEPTH "fetch_depth"
#define SECTION_LEDGER_HISTORY "ledger_history"
#define SECTION_INSIGHT "insight"
#define SECTION_IPS "ips"

View File

@@ -2327,6 +2327,11 @@ private:
}
else if (packet.has_ledgerseq ())
{
if (packet.ledgerseq() < getApp().getLedgerMaster().getEarliestFetch())
{
m_journal.debug << "Peer requests early ledger";
return;
}
ledger = getApp().getLedgerMaster ().getLedgerBySeq (packet.ledgerseq ());
if (m_journal.debug)
m_journal.debug << "Don't have ledger " << packet.ledgerseq ();
@@ -2359,6 +2364,12 @@ private:
return;
}
if (!packet.has_ledgerseq() && (ledger->getLedgerSeq() < getApp().getLedgerMaster().getEarliestFetch()))
{
m_journal.debug << "Peer requests early ledger";
return;
}
// Fill out the reply
uint256 lHash = ledger->getHash ();
reply.set_ledgerhash (lHash.begin (), lHash.size ());
@@ -2545,6 +2556,13 @@ private:
return;
}
if (haveLedger->getLedgerSeq() < getApp().getLedgerMaster().getEarliestFetch())
{
m_journal.debug << "Peer requests fetch pack that is too early";
charge (Resource::feeInvalidRequest);
return;
}
Ledger::pointer wantLedger = getApp().getOPs ().getLedgerByHash (haveLedger->getParentHash ());
if (!wantLedger)