diff --git a/doc/rippled-example.cfg b/doc/rippled-example.cfg index c8894379b..cc75f08d3 100644 --- a/doc/rippled-example.cfg +++ b/doc/rippled-example.cfg @@ -481,6 +481,13 @@ # # # +# [ledger_history_index] +# +# If set to greater than 0, the index number of the earliest ledger to +# acquire. +# +# +# # [fetch_depth] # # The number of past ledgers to serve to other peers that request historical diff --git a/src/ripple/app/ledger/LedgerMaster.cpp b/src/ripple/app/ledger/LedgerMaster.cpp index f0794ff47..422f29113 100644 --- a/src/ripple/app/ledger/LedgerMaster.cpp +++ b/src/ripple/app/ledger/LedgerMaster.cpp @@ -103,13 +103,14 @@ public: // How much history do we want to keep std::uint32_t const ledger_history_; + // Acquire past ledgers down to this ledger index + std::uint32_t const ledger_history_index_; int const ledger_fetch_size_; //-------------------------------------------------------------------------- - LedgerMasterImp (bool standalone, std::uint32_t fetch_depth, - std::uint32_t ledger_history, int ledger_fetch_size, Stoppable& parent, + LedgerMasterImp (Config const& config, Stoppable& parent, beast::insight::Collector::ptr const& collector, beast::Journal journal) : LedgerMaster (parent) , m_journal (journal) @@ -129,11 +130,21 @@ public: , mValidLedgerClose (0) , mValidLedgerSeq (0) , mBuildingLedgerSeq (0) - , standalone_ (standalone) - , fetch_depth_ (getApp().getSHAMapStore().clampFetchDepth (fetch_depth)) - , ledger_history_ (ledger_history) - , ledger_fetch_size_ (ledger_fetch_size) + , standalone_ (config.RUN_STANDALONE) + , fetch_depth_ (getApp ().getSHAMapStore ().clampFetchDepth (config.FETCH_DEPTH)) + , ledger_history_ (config.LEDGER_HISTORY) + , ledger_history_index_ (config.LEDGER_HISTORY_INDEX) + , ledger_fetch_size_ (config.getSize (siLedgerFetch)) { + if (ledger_history_index_ != 0 && + config.nodeDatabase["online_delete"].isNotEmpty () && + config.nodeDatabase["online_delete"].getIntValue () > 0) + { + std::stringstream ss; + ss << "[node_db] online_delete option and [ledger_history_index]" + " cannot be configured at the same time."; + throw std::runtime_error (ss.str ()); + } } ~LedgerMasterImp () @@ -947,7 +958,8 @@ public: } WriteLog (lsTRACE, LedgerMaster) << "tryAdvance discovered missing " << missing; if ((missing != RangeSet::absent) && (missing > 0) && - shouldAcquire(mValidLedgerSeq, ledger_history_, missing) && + shouldAcquire (mValidLedgerSeq, ledger_history_, + ledger_history_index_, missing) && ((mFillInProgress == 0) || (missing > mFillInProgress))) { WriteLog (lsTRACE, LedgerMaster) << "advanceThread should acquire"; @@ -1546,27 +1558,27 @@ LedgerMaster::~LedgerMaster () { } -bool LedgerMaster::shouldAcquire ( - std::uint32_t currentLedger, std::uint32_t ledgerHistory, std::uint32_t candidateLedger) +bool LedgerMaster::shouldAcquire (std::uint32_t currentLedger, + std::uint32_t ledgerHistory, std::uint32_t ledgerHistoryIndex, + std::uint32_t candidateLedger) { - bool ret; + bool ret (candidateLedger >= currentLedger || + (ledgerHistoryIndex != 0 && candidateLedger >= ledgerHistoryIndex) || + (currentLedger - candidateLedger) <= ledgerHistory); - if (candidateLedger >= currentLedger) - ret = true; - else - ret = (currentLedger - candidateLedger) <= ledgerHistory; - - WriteLog (lsTRACE, LedgerMaster) << "Missing ledger " << candidateLedger << (ret ? " should" : " should NOT") << " be acquired"; + WriteLog (lsTRACE, LedgerMaster) + << "Missing ledger " + << candidateLedger + << (ret ? " should" : " should NOT") + << " be acquired"; return ret; } std::unique_ptr -make_LedgerMaster (bool standalone, std::uint32_t fetch_depth, - std::uint32_t ledger_history, int ledger_fetch_size, beast::Stoppable& parent, +make_LedgerMaster (Config const& config, beast::Stoppable& parent, beast::insight::Collector::ptr const& collector, beast::Journal journal) { - return std::make_unique (standalone, fetch_depth, - ledger_history, ledger_fetch_size, parent, collector, journal); + return std::make_unique (config, parent, collector, journal); } } // ripple diff --git a/src/ripple/app/ledger/LedgerMaster.h b/src/ripple/app/ledger/LedgerMaster.h index f7e331d0d..ffc81ff5e 100644 --- a/src/ripple/app/ledger/LedgerMaster.h +++ b/src/ripple/app/ledger/LedgerMaster.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -149,8 +150,9 @@ public: virtual beast::PropertyStream::Source& getPropertySource () = 0; - static bool shouldAcquire (std::uint32_t currentLedgerID, - std::uint32_t ledgerHistory, std::uint32_t targetLedger); + static bool shouldAcquire (std::uint32_t currentLedgerID, + std::uint32_t ledgerHistory, std::uint32_t ledgerHistoryIndex, + std::uint32_t targetLedger); virtual void clearPriorLedgers (LedgerIndex seq) = 0; @@ -158,8 +160,7 @@ public: }; std::unique_ptr -make_LedgerMaster (bool standalone, std::uint32_t fetch_depth, - std::uint32_t ledger_history, int ledger_fetch_size, beast::Stoppable& parent, +make_LedgerMaster (Config const& config, beast::Stoppable& parent, beast::insight::Collector::ptr const& collector, beast::Journal journal); } // ripple diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index a21faa698..1449fee87 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -291,9 +291,7 @@ public: , m_pathRequests (new PathRequests ( m_logs.journal("PathRequest"), m_collectorManager->collector ())) - , m_ledgerMaster (make_LedgerMaster (getConfig ().RUN_STANDALONE, - getConfig ().FETCH_DEPTH, getConfig ().LEDGER_HISTORY, - getConfig ().getSize (siLedgerFetch), *m_jobQueue, + , m_ledgerMaster (make_LedgerMaster (getConfig (), *m_jobQueue, m_collectorManager->collector (), m_logs.journal("LedgerMaster"))) // VFALCO NOTE must come before NetworkOPs to prevent a crash due diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 784ca5bd0..487ef6611 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -344,6 +344,7 @@ int run (int argc, char** argv) { getConfig ().RUN_STANDALONE = true; getConfig ().LEDGER_HISTORY = 0; + getConfig ().LEDGER_HISTORY_INDEX = 0; } } diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index 4d5686d0b..168f7ce86 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -291,6 +291,7 @@ public: // Node storage configuration std::uint32_t LEDGER_HISTORY; + std::uint32_t LEDGER_HISTORY_INDEX; std::uint32_t FETCH_DEPTH; int NODE_SIZE; @@ -310,7 +311,7 @@ public: public: Config (); - int getSize (SizedItemName); + int getSize (SizedItemName) const; void setup (std::string const& strConf, bool bQuiet); void load (); }; diff --git a/src/ripple/core/ConfigSections.h b/src/ripple/core/ConfigSections.h index 3e3b7640b..8ebb357e4 100644 --- a/src/ripple/core/ConfigSections.h +++ b/src/ripple/core/ConfigSections.h @@ -43,6 +43,7 @@ struct ConfigSection #define SECTION_FEE_OWNER_RESERVE "fee_owner_reserve" #define SECTION_FETCH_DEPTH "fetch_depth" #define SECTION_LEDGER_HISTORY "ledger_history" +#define SECTION_LEDGER_HISTORY_INDEX "ledger_history_index" #define SECTION_INSIGHT "insight" #define SECTION_IPS "ips" #define SECTION_IPS_FIXED "ips_fixed" diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index b31d57975..11098dcb1 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -249,6 +249,7 @@ Config::Config () FEE_CONTRACT_OPERATION = DEFAULT_FEE_OPERATION; LEDGER_HISTORY = 256; + LEDGER_HISTORY_INDEX = 0; FETCH_DEPTH = 1000000000; // An explanation of these magical values would be nice. @@ -584,6 +585,11 @@ void Config::load () else LEDGER_HISTORY = beast::lexicalCastThrow (strTemp); } + if (getSingleSection(secConfig, SECTION_LEDGER_HISTORY_INDEX, strTemp)) + { + LEDGER_HISTORY_INDEX = beast::lexicalCastThrow (strTemp); + } + if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp)) { boost::to_lower (strTemp); @@ -628,7 +634,7 @@ void Config::load () } } -int Config::getSize (SizedItemName item) +int Config::getSize (SizedItemName item) const { SizedItem sizeTable[] = // tiny small medium large huge {