Skip to content

Commit 4b3e629

Browse files
pull-robotvinniefalco
authored andcommitted
Allow ledgers to be loaded from the command line.
Conflicts: src/ripple_data/protocol/BuildInfo.cpp
1 parent 568fae9 commit 4b3e629

File tree

11 files changed

+236
-72
lines changed

11 files changed

+236
-72
lines changed

src/ripple_app/data/DatabaseCon.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ DatabaseCon::DatabaseCon (const std::string& strName, const char* initStrings[],
2525
// responsibility to pass in the path. Add a member function to Application
2626
// or Config to compute this path.
2727
//
28-
boost::filesystem::path pPath = (getConfig ().RUN_STANDALONE &&
29-
((getConfig ().START_UP != Config::LOAD) && (getConfig ().START_UP != Config::REPLAY)))
30-
? "" // Use temporary files.
31-
: (getConfig ().DATA_DIR / strName); // Use regular db files.
28+
auto const startUp = getConfig ().START_UP;
29+
auto const useTempFiles // Use temporary files or regular DB files?
30+
= getConfig ().RUN_STANDALONE &&
31+
startUp != Config::LOAD &&
32+
startUp != Config::LOAD_FILE &&
33+
startUp != Config::REPLAY;
34+
boost::filesystem::path pPath = useTempFiles
35+
? "" : (getConfig ().DATA_DIR / strName);
3236

3337
mDatabase = new SqliteDatabase (pPath.string ().c_str ());
3438
mDatabase->connect ();

src/ripple_app/ledger/Ledger.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ Ledger::Ledger (const std::string& rawLedger, bool hasPrefix)
204204
initializeFees ();
205205
}
206206

207+
/** Used for ledgers loaded from JSON files */
208+
Ledger::Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime)
209+
: mTotCoins (0),
210+
mLedgerSeq (ledgerSeq),
211+
mCloseTime (closeTime),
212+
mParentCloseTime (0),
213+
mCloseResolution (LEDGER_TIME_ACCURACY),
214+
mCloseFlags (0),
215+
mClosed (false),
216+
mValidated (false),
217+
mValidHash (false),
218+
mAccepted (false),
219+
mImmutable (false),
220+
mTransactionMap (boost::make_shared <SHAMap> (
221+
smtTRANSACTION, std::ref (getApp().getFullBelowCache()))),
222+
mAccountStateMap (boost::make_shared <SHAMap> (
223+
smtSTATE, std::ref (getApp().getFullBelowCache())))
224+
{
225+
initializeFees ();
226+
}
227+
228+
207229
Ledger::~Ledger ()
208230
{
209231
if (mTransactionMap)
@@ -326,6 +348,12 @@ bool Ledger::hasAccount (const RippleAddress& accountID)
326348
return mAccountStateMap->hasItem (Ledger::getAccountRootIndex (accountID));
327349
}
328350

351+
bool Ledger::addSLE (SLE const& sle)
352+
{
353+
SHAMapItem item (sle.getIndex(), sle.getSerializer());
354+
return mAccountStateMap->addItem(item, false, false);
355+
}
356+
329357
AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID)
330358
{
331359
#ifdef BEAST_DEBUG

src/ripple_app/ledger/Ledger.h

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class Ledger
109109
int closeFlags, int closeResolution,
110110
std::uint32_t ledgerSeq, bool & loaded); // used for database ledgers
111111

112+
Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime);
113+
112114
Ledger (Blob const & rawLedger, bool hasPrefix);
113115

114116
Ledger (const std::string & rawLedger, bool hasPrefix);
@@ -188,6 +190,10 @@ class Ledger
188190
{
189191
mTotCoins -= fee;
190192
}
193+
void setTotalCoins (std::uint64_t totCoins)
194+
{
195+
mTotCoins = totCoins;
196+
}
191197
std::uint32_t getCloseTimeNC () const
192198
{
193199
return mCloseTime;
@@ -238,6 +244,9 @@ class Ledger
238244
mAccountStateMap->dropCache ();
239245
}
240246

247+
// returns false on error
248+
bool addSLE (SLE const& sle);
249+
241250
// ledger sync functions
242251
void setAcquiring (void);
243252
bool isAcquiring (void);

src/ripple_app/ledger/LedgerTiming.h

+27-20
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,65 @@
2323
namespace ripple {
2424

2525
// The number of seconds a ledger may remain idle before closing
26-
# define LEDGER_IDLE_INTERVAL 15
26+
const int LEDGER_IDLE_INTERVAL = 15;
2727

2828
// The number of seconds a validation remains current after its ledger's close time
2929
// This is a safety to protect against very old validations and the time it takes to adjust
3030
// the close time accuracy window
31-
# define LEDGER_VAL_INTERVAL 300
31+
const int LEDGER_VAL_INTERVAL = 300;
3232

3333
// The number of seconds before a close time that we consider a validation acceptable
3434
// This protects against extreme clock errors
35-
# define LEDGER_EARLY_INTERVAL 180
35+
const int LEDGER_EARLY_INTERVAL = 180;
3636

3737
// The number of milliseconds we wait minimum to ensure participation
38-
# define LEDGER_MIN_CONSENSUS 2000
38+
const int LEDGER_MIN_CONSENSUS = 2000;
3939

4040
// The number of milliseconds we wait minimum to ensure others have computed the LCL
41-
# define LEDGER_MIN_CLOSE 2000
41+
const int LEDGER_MIN_CLOSE = 2000;
4242

4343
// Initial resolution of ledger close time
44-
# define LEDGER_TIME_ACCURACY 30
44+
const int LEDGER_TIME_ACCURACY = 30;
4545

4646
// How often to increase resolution
47-
# define LEDGER_RES_INCREASE 8
47+
const int LEDGER_RES_INCREASE = 8;
4848

4949
// How often to decrease resolution
50-
# define LEDGER_RES_DECREASE 1
50+
const int LEDGER_RES_DECREASE = 1;
5151

5252
// How often we check state or change positions (in milliseconds)
53-
# define LEDGER_GRANULARITY 1000
53+
const int LEDGER_GRANULARITY = 1000;
5454

5555
// The percentage of active trusted validators that must be able to
5656
// keep up with the network or we consider the network overloaded
57-
# define LEDGER_NET_RATIO 70
57+
const int LEDGER_NET_RATIO = 70;
5858

5959
// How long we consider a proposal fresh
60-
# define PROPOSE_FRESHNESS 20
60+
const int PROPOSE_FRESHNESS = 20;
6161

6262
// How often we force generating a new proposal to keep ours fresh
63-
# define PROPOSE_INTERVAL 12
63+
const int PROPOSE_INTERVAL = 12;
6464

6565
// Avalanche tuning
66-
# define AV_INIT_CONSENSUS_PCT 50 // percentage of nodes on our UNL that must vote yes
66+
// percentage of nodes on our UNL that must vote yes
67+
const int AV_INIT_CONSENSUS_PCT = 50;
6768

68-
# define AV_MID_CONSENSUS_TIME 50 // percentage of previous close time before we advance
69-
# define AV_MID_CONSENSUS_PCT 65 // percentage of nodes that most vote yes after advancing
69+
// percentage of previous close time before we advance
70+
const int AV_MID_CONSENSUS_TIME = 50;
7071

71-
# define AV_LATE_CONSENSUS_TIME 85 // percentage of previous close time before we advance
72-
# define AV_LATE_CONSENSUS_PCT 70 // percentage of nodes that most vote yes after advancing
72+
// percentage of nodes that most vote yes after advancing
73+
const int AV_MID_CONSENSUS_PCT = 65;
7374

74-
# define AV_STUCK_CONSENSUS_TIME 200
75-
# define AV_STUCK_CONSENSUS_PCT 95
75+
// percentage of previous close time before we advance
76+
const int AV_LATE_CONSENSUS_TIME = 85;
7677

77-
# define AV_CT_CONSENSUS_PCT 75
78+
// percentage of nodes that most vote yes after advancing
79+
const int AV_LATE_CONSENSUS_PCT = 70;
80+
81+
const int AV_STUCK_CONSENSUS_TIME = 200;
82+
const int AV_STUCK_CONSENSUS_PCT = 95;
83+
84+
const int AV_CT_CONSENSUS_PCT = 75;
7885

7986
class ContinuousLedgerTiming
8087
{

0 commit comments

Comments
 (0)