Devirtualize LedgerMaster.

This commit is contained in:
Edward Hennis
2015-12-01 19:30:16 -05:00
committed by Nik Bougalis
parent 44fcab1081
commit e1018546ac
7 changed files with 1559 additions and 1527 deletions

View File

@@ -1354,8 +1354,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\impl\LedgerCleaner.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerConsensusImp.cpp"> <ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerConsensusImp.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
@@ -1404,6 +1402,8 @@
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\Ledger.h"> <ClInclude Include="..\..\src\ripple\app\ledger\Ledger.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerCleaner.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerConsensus.h"> <ClInclude Include="..\..\src\ripple\app\ledger\LedgerConsensus.h">
</ClInclude> </ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\LedgerHistory.cpp"> <ClCompile Include="..\..\src\ripple\app\ledger\LedgerHistory.cpp">

View File

@@ -2088,9 +2088,6 @@
<ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerCleaner.cpp"> <ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerCleaner.cpp">
<Filter>ripple\app\ledger\impl</Filter> <Filter>ripple\app\ledger\impl</Filter>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\impl\LedgerCleaner.h">
<Filter>ripple\app\ledger\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerConsensusImp.cpp"> <ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerConsensusImp.cpp">
<Filter>ripple\app\ledger\impl</Filter> <Filter>ripple\app\ledger\impl</Filter>
</ClCompile> </ClCompile>
@@ -2136,6 +2133,9 @@
<ClInclude Include="..\..\src\ripple\app\ledger\Ledger.h"> <ClInclude Include="..\..\src\ripple\app\ledger\Ledger.h">
<Filter>ripple\app\ledger</Filter> <Filter>ripple\app\ledger</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerCleaner.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerConsensus.h"> <ClInclude Include="..\..\src\ripple\app\ledger\LedgerConsensus.h">
<Filter>ripple\app\ledger</Filter> <Filter>ripple\app\ledger</Filter>
</ClInclude> </ClInclude>

View File

@@ -28,6 +28,7 @@
#include <memory> #include <memory>
namespace ripple { namespace ripple {
namespace detail {
/** Check the ledger/transaction databases to make sure they have continuity */ /** Check the ledger/transaction databases to make sure they have continuity */
class LedgerCleaner class LedgerCleaner
@@ -58,6 +59,7 @@ std::unique_ptr<LedgerCleaner>
make_LedgerCleaner (Application& app, make_LedgerCleaner (Application& app,
beast::Stoppable& parent, beast::Journal journal); beast::Stoppable& parent, beast::Journal journal);
} // detail
} // ripple } // ripple
#endif #endif

View File

@@ -22,8 +22,12 @@
#include <ripple/app/main/Application.h> #include <ripple/app/main/Application.h>
#include <ripple/app/ledger/Ledger.h> #include <ripple/app/ledger/Ledger.h>
#include <ripple/app/ledger/LedgerCleaner.h>
#include <ripple/app/ledger/LedgerHistory.h>
#include <ripple/app/ledger/LedgerHolder.h> #include <ripple/app/ledger/LedgerHolder.h>
#include <ripple/app/misc/CanonicalTXSet.h>
#include <ripple/basics/chrono.h> #include <ripple/basics/chrono.h>
#include <ripple/basics/RangeSet.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/RippleLedgerHash.h> #include <ripple/protocol/RippleLedgerHash.h>
#include <ripple/protocol/STValidation.h> #include <ripple/protocol/STValidation.h>
@@ -58,8 +62,12 @@ struct LedgerReplay
class LedgerMaster class LedgerMaster
: public beast::Stoppable : public beast::Stoppable
{ {
protected: public:
explicit LedgerMaster (Stoppable& parent); explicit
LedgerMaster(Application& app, Stopwatch& stopwatch,
Stoppable& parent,
beast::insight::Collector::ptr const& collector,
beast::Journal journal);
public: public:
using callback = std::function <void (Ledger::ref)>; using callback = std::function <void (Ledger::ref)>;
@@ -67,157 +75,245 @@ public:
public: public:
virtual ~LedgerMaster () = default; virtual ~LedgerMaster () = default;
virtual LedgerIndex getCurrentLedgerIndex () = 0; LedgerIndex getCurrentLedgerIndex ();
virtual LedgerIndex getValidLedgerIndex () = 0; LedgerIndex getValidLedgerIndex ();
virtual bool isCompatible (Ledger::pointer, bool isCompatible (Ledger::pointer,
beast::Journal::Stream, const char* reason) = 0; beast::Journal::Stream, const char* reason);
virtual std::recursive_mutex& peekMutex () = 0; std::recursive_mutex& peekMutex ();
// The current ledger is the ledger we believe new transactions should go in // The current ledger is the ledger we believe new transactions should go in
virtual std::shared_ptr<ReadView const> getCurrentLedger () = 0; std::shared_ptr<ReadView const> getCurrentLedger ();
// The finalized ledger is the last closed/accepted ledger // The finalized ledger is the last closed/accepted ledger
virtual Ledger::pointer getClosedLedger () = 0; Ledger::pointer getClosedLedger ();
// The validated ledger is the last fully validated ledger // The validated ledger is the last fully validated ledger
virtual Ledger::pointer getValidatedLedger () = 0; Ledger::pointer getValidatedLedger ();
// The Rules are in the last fully validated ledger if there is one. // The Rules are in the last fully validated ledger if there is one.
virtual Rules getValidatedRules() = 0; Rules getValidatedRules();
// This is the last ledger we published to clients and can lag the validated // This is the last ledger we published to clients and can lag the validated
// ledger // ledger
virtual Ledger::pointer getPublishedLedger () = 0; Ledger::pointer getPublishedLedger ();
virtual bool isValidLedger(LedgerInfo const&) = 0; bool isValidLedger(LedgerInfo const&);
virtual std::chrono::seconds getPublishedLedgerAge () = 0; std::chrono::seconds getPublishedLedgerAge ();
virtual std::chrono::seconds getValidatedLedgerAge () = 0; std::chrono::seconds getValidatedLedgerAge ();
virtual bool isCaughtUp(std::string& reason) = 0; bool isCaughtUp(std::string& reason);
virtual int getMinValidations () = 0; int getMinValidations ();
virtual void setMinValidations (int v, bool strict) = 0; void setMinValidations (int v, bool strict);
virtual std::uint32_t getEarliestFetch () = 0; std::uint32_t getEarliestFetch ();
virtual bool storeLedger (Ledger::pointer) = 0; bool storeLedger (Ledger::pointer);
virtual void forceValid (Ledger::pointer) = 0; void forceValid (Ledger::pointer);
virtual void setFullLedger ( void setFullLedger (
Ledger::pointer ledger, bool isSynchronous, bool isCurrent) = 0; Ledger::pointer ledger, bool isSynchronous, bool isCurrent);
virtual void switchLCL (Ledger::pointer lastClosed) = 0; void switchLCL (Ledger::pointer lastClosed);
virtual void failedSave(std::uint32_t seq, uint256 const& hash) = 0; void failedSave(std::uint32_t seq, uint256 const& hash);
virtual std::string getCompleteLedgers () = 0; std::string getCompleteLedgers ();
virtual void applyHeldTransactions () = 0; /** Apply held transactions to the open ledger
This is normally called as we close the ledger.
The open ledger remains open to handle new transactions
until a new open ledger is built.
*/
void applyHeldTransactions ();
/** Get a ledger's hash by sequence number using the cache /** Get a ledger's hash by sequence number using the cache
*/ */
virtual uint256 getHashBySeq (std::uint32_t index) = 0; uint256 getHashBySeq (std::uint32_t index);
/** Walk to a ledger's hash using the skip list /** Walk to a ledger's hash using the skip list
*/ */
virtual uint256 walkHashBySeq (std::uint32_t index) = 0; uint256 walkHashBySeq (std::uint32_t index);
virtual uint256 walkHashBySeq ( uint256 walkHashBySeq (
std::uint32_t index, Ledger::ref referenceLedger) = 0; std::uint32_t index, Ledger::ref referenceLedger);
virtual Ledger::pointer getLedgerBySeq (std::uint32_t index) = 0; Ledger::pointer getLedgerBySeq (std::uint32_t index);
virtual Ledger::pointer getLedgerByHash (uint256 const& hash) = 0; Ledger::pointer getLedgerByHash (uint256 const& hash);
virtual void setLedgerRangePresent ( void setLedgerRangePresent (
std::uint32_t minV, std::uint32_t maxV) = 0; std::uint32_t minV, std::uint32_t maxV);
virtual uint256 getLedgerHash( uint256 getLedgerHash(
std::uint32_t desiredSeq, Ledger::ref knownGoodLedger) = 0; std::uint32_t desiredSeq, Ledger::ref knownGoodLedger);
virtual boost::optional <NetClock::time_point> getCloseTimeBySeq ( boost::optional <NetClock::time_point> getCloseTimeBySeq (
LedgerIndex ledgerIndex) = 0; LedgerIndex ledgerIndex);
virtual boost::optional <NetClock::time_point> getCloseTimeByHash ( boost::optional <NetClock::time_point> getCloseTimeByHash (
LedgerHash const& ledgerHash) = 0; LedgerHash const& ledgerHash);
virtual void addHeldTransaction (std::shared_ptr<Transaction> const& trans) = 0; void addHeldTransaction (std::shared_ptr<Transaction> const& trans);
virtual void fixMismatch (Ledger::ref ledger) = 0; void fixMismatch (Ledger::ref ledger);
virtual bool haveLedger (std::uint32_t seq) = 0; bool haveLedger (std::uint32_t seq);
virtual void clearLedger (std::uint32_t seq) = 0; void clearLedger (std::uint32_t seq);
virtual bool getValidatedRange ( bool getValidatedRange (
std::uint32_t& minVal, std::uint32_t& maxVal) = 0; std::uint32_t& minVal, std::uint32_t& maxVal);
virtual bool getFullValidatedRange ( bool getFullValidatedRange (
std::uint32_t& minVal, std::uint32_t& maxVal) = 0; std::uint32_t& minVal, std::uint32_t& maxVal);
virtual void tune (int size, int age) = 0; void tune (int size, int age);
virtual void sweep () = 0; void sweep ();
virtual float getCacheHitRate () = 0; float getCacheHitRate ();
virtual void checkAccept (Ledger::ref ledger) = 0; void checkAccept (Ledger::ref ledger);
virtual void checkAccept (uint256 const& hash, std::uint32_t seq) = 0; void checkAccept (uint256 const& hash, std::uint32_t seq);
virtual void consensusBuilt (Ledger::ref ledger, Json::Value consensus) = 0; void consensusBuilt (Ledger::ref ledger, Json::Value consensus);
virtual LedgerIndex getBuildingLedger () = 0; LedgerIndex getBuildingLedger ();
virtual void setBuildingLedger (LedgerIndex index) = 0; void setBuildingLedger (LedgerIndex index);
virtual void tryAdvance () = 0; void tryAdvance ();
virtual void newPathRequest () = 0; void newPathRequest ();
virtual bool isNewPathRequest () = 0; bool isNewPathRequest ();
virtual void newOrderBookDB () = 0; void newOrderBookDB ();
virtual bool fixIndex ( bool fixIndex (
LedgerIndex ledgerIndex, LedgerHash const& ledgerHash) = 0; LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
virtual void doLedgerCleaner(Json::Value const& parameters) = 0; void doLedgerCleaner(Json::Value const& parameters);
virtual beast::PropertyStream::Source& getPropertySource () = 0; beast::PropertyStream::Source& getPropertySource ();
virtual void clearPriorLedgers (LedgerIndex seq) = 0; void clearPriorLedgers (LedgerIndex seq);
virtual void clearLedgerCachePrior (LedgerIndex seq) = 0; void clearLedgerCachePrior (LedgerIndex seq);
// ledger replay // ledger replay
virtual void takeReplay (std::unique_ptr<LedgerReplay> replay) = 0; void takeReplay (std::unique_ptr<LedgerReplay> replay);
virtual std::unique_ptr<LedgerReplay> releaseReplay () = 0; std::unique_ptr<LedgerReplay> releaseReplay ();
// Fetch Packs // Fetch Packs
virtual
void gotFetchPack ( void gotFetchPack (
bool progress, bool progress,
std::uint32_t seq) = 0; std::uint32_t seq);
virtual
void addFetchPack ( void addFetchPack (
uint256 const& hash, uint256 const& hash,
std::shared_ptr<Blob>& data) = 0; std::shared_ptr<Blob>& data);
virtual
bool getFetchPack ( bool getFetchPack (
uint256 const& hash, uint256 const& hash,
Blob& data) = 0; Blob& data);
virtual
void makeFetchPack ( void makeFetchPack (
std::weak_ptr<Peer> const& wPeer, std::weak_ptr<Peer> const& wPeer,
std::shared_ptr<protocol::TMGetObjectByHash> const& request, std::shared_ptr<protocol::TMGetObjectByHash> const& request,
uint256 haveLedgerHash, uint256 haveLedgerHash,
std::uint32_t uUptime) = 0; std::uint32_t uUptime);
std::size_t getFetchPackCacheSize () const;
private:
void setValidLedger(Ledger::ref l);
void setPubLedger(Ledger::ref l);
void tryFill(Job& job, Ledger::pointer ledger);
void getFetchPack(LedgerHash missingHash, LedgerIndex missingIndex);
LedgerHash getLedgerHashForHistory(LedgerIndex index);
int getNeededValidations();
void advanceThread();
// Try to publish ledgers, acquire missing ledgers
void doAdvance();
bool shouldFetchPack(std::uint32_t seq) const;
bool shouldAcquire(
std::uint32_t const currentLedger,
std::uint32_t const ledgerHistory,
std::uint32_t const ledgerHistoryIndex,
std::uint32_t const candidateLedger) const;
std::vector<Ledger::pointer> findNewLedgersToPublish();
void updatePaths(Job& job);
void newPFWork(const char *name);
private:
using ScopedLockType = std::lock_guard <std::recursive_mutex>;
using ScopedUnlockType = beast::GenericScopedUnlock <std::recursive_mutex>;
Application& app_;
beast::Journal m_journal;
std::recursive_mutex m_mutex;
// The ledger that most recently closed.
LedgerHolder mClosedLedger;
// The highest-sequence ledger we have fully accepted.
LedgerHolder mValidLedger;
// The last ledger we have published.
Ledger::pointer mPubLedger;
// The last ledger we did pathfinding against.
Ledger::pointer mPathLedger;
// The last ledger we handled fetching history
Ledger::pointer mHistLedger;
// Fully validated ledger, whether or not we have the ledger resident.
std::pair <uint256, LedgerIndex> mLastValidLedger;
LedgerHistory mLedgerHistory;
CanonicalTXSet mHeldTransactions;
// A set of transactions to replay during the next close
std::unique_ptr<LedgerReplay> replayData;
std::recursive_mutex mCompleteLock;
RangeSet mCompleteLedgers;
std::unique_ptr <detail::LedgerCleaner> mLedgerCleaner;
int mMinValidations; // The minimum validations to publish a ledger.
bool mStrictValCount; // Don't raise the minimum
uint256 mLastValidateHash;
std::uint32_t mLastValidateSeq;
// Publish thread is running.
bool mAdvanceThread;
// Publish thread has work to do.
bool mAdvanceWork;
int mFillInProgress;
int mPathFindThread; // Pathfinder jobs dispatched
bool mPathFindNewRequest;
std::atomic <std::uint32_t> mPubLedgerClose;
std::atomic <std::uint32_t> mPubLedgerSeq;
std::atomic <std::uint32_t> mValidLedgerSign;
std::atomic <std::uint32_t> mValidLedgerSeq;
std::atomic <std::uint32_t> mBuildingLedgerSeq;
// The server is in standalone mode
bool const standalone_;
// How many ledgers before the current ledger do we allow peers to request?
std::uint32_t const fetch_depth_;
// How much history do we want to keep
std::uint32_t const ledger_history_;
int const ledger_fetch_size_;
TaggedCache<uint256, Blob> fetch_packs_;
std::uint32_t fetch_seq_;
virtual
std::size_t getFetchPackCacheSize () const = 0;
}; };
std::unique_ptr <LedgerMaster>
make_LedgerMaster (
Application& app,
Stopwatch& stopwatch,
beast::Stoppable& parent,
beast::insight::Collector::ptr const& collector,
beast::Journal journal);
} // ripple } // ripple
#endif #endif

View File

@@ -18,7 +18,7 @@
//============================================================================== //==============================================================================
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/app/ledger/impl/LedgerCleaner.h> #include <ripple/app/ledger/LedgerCleaner.h>
#include <ripple/app/ledger/InboundLedgers.h> #include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/LedgerMaster.h> #include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/core/LoadFeeTrack.h> #include <ripple/core/LoadFeeTrack.h>
@@ -26,6 +26,7 @@
#include <beast/threads/Thread.h> #include <beast/threads/Thread.h>
namespace ripple { namespace ripple {
namespace detail {
/* /*
@@ -502,4 +503,5 @@ make_LedgerCleaner (Application& app,
return std::make_unique<LedgerCleanerImp>(app, parent, journal); return std::make_unique<LedgerCleanerImp>(app, parent, journal);
} }
} // detail
} // ripple } // ripple

View File

@@ -20,24 +20,20 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/app/ledger/LedgerMaster.h> #include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/ledger/InboundLedgers.h> #include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/LedgerHistory.h>
#include <ripple/app/ledger/OpenLedger.h> #include <ripple/app/ledger/OpenLedger.h>
#include <ripple/app/ledger/OrderBookDB.h> #include <ripple/app/ledger/OrderBookDB.h>
#include <ripple/app/ledger/PendingSaves.h> #include <ripple/app/ledger/PendingSaves.h>
#include <ripple/app/ledger/impl/LedgerCleaner.h>
#include <ripple/app/tx/apply.h> #include <ripple/app/tx/apply.h>
#include <ripple/app/main/Application.h> #include <ripple/app/main/Application.h>
#include <ripple/app/misc/AmendmentTable.h> #include <ripple/app/misc/AmendmentTable.h>
#include <ripple/app/misc/HashRouter.h> #include <ripple/app/misc/HashRouter.h>
#include <ripple/app/misc/NetworkOPs.h> #include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/misc/CanonicalTXSet.h>
#include <ripple/app/misc/SHAMapStore.h> #include <ripple/app/misc/SHAMapStore.h>
#include <ripple/app/misc/Transaction.h> #include <ripple/app/misc/Transaction.h>
#include <ripple/app/misc/TxQ.h> #include <ripple/app/misc/TxQ.h>
#include <ripple/app/misc/Validations.h> #include <ripple/app/misc/Validations.h>
#include <ripple/app/paths/PathRequests.h> #include <ripple/app/paths/PathRequests.h>
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/basics/RangeSet.h>
#include <ripple/basics/TaggedCache.h> #include <ripple/basics/TaggedCache.h>
#include <ripple/basics/UptimeTimer.h> #include <ripple/basics/UptimeTimer.h>
#include <ripple/core/LoadFeeTrack.h> #include <ripple/core/LoadFeeTrack.h>
@@ -65,96 +61,16 @@ using namespace std::chrono_literals;
// Don't acquire history if ledger is too old // Don't acquire history if ledger is too old
auto constexpr MAX_LEDGER_AGE_ACQUIRE = 1min; auto constexpr MAX_LEDGER_AGE_ACQUIRE = 1min;
class LedgerMasterImp LedgerMaster::LedgerMaster (Application& app, Stopwatch& stopwatch,
: public LedgerMaster
{
public:
using ScopedLockType = std::lock_guard <std::recursive_mutex>;
using ScopedUnlockType = beast::GenericScopedUnlock <std::recursive_mutex>;
Application& app_;
beast::Journal m_journal;
std::recursive_mutex m_mutex;
// The ledger that most recently closed.
LedgerHolder mClosedLedger;
// The highest-sequence ledger we have fully accepted.
LedgerHolder mValidLedger;
// The last ledger we have published.
Ledger::pointer mPubLedger;
// The last ledger we did pathfinding against.
Ledger::pointer mPathLedger;
// The last ledger we handled fetching history
Ledger::pointer mHistLedger;
// Fully validated ledger, whether or not we have the ledger resident.
std::pair <uint256, LedgerIndex> mLastValidLedger;
LedgerHistory mLedgerHistory;
CanonicalTXSet mHeldTransactions;
// A set of transactions to replay during the next close
std::unique_ptr<LedgerReplay> replayData;
std::recursive_mutex mCompleteLock;
RangeSet mCompleteLedgers;
std::unique_ptr <LedgerCleaner> mLedgerCleaner;
int mMinValidations; // The minimum validations to publish a ledger.
bool mStrictValCount; // Don't raise the minimum
uint256 mLastValidateHash;
std::uint32_t mLastValidateSeq;
// Publish thread is running.
bool mAdvanceThread;
// Publish thread has work to do.
bool mAdvanceWork;
int mFillInProgress;
int mPathFindThread; // Pathfinder jobs dispatched
bool mPathFindNewRequest;
std::atomic <std::uint32_t> mPubLedgerClose;
std::atomic <std::uint32_t> mPubLedgerSeq;
std::atomic <std::uint32_t> mValidLedgerSign;
std::atomic <std::uint32_t> mValidLedgerSeq;
std::atomic <std::uint32_t> mBuildingLedgerSeq;
// The server is in standalone mode
bool const standalone_;
// How many ledgers before the current ledger do we allow peers to request?
std::uint32_t const fetch_depth_;
// How much history do we want to keep
std::uint32_t const ledger_history_;
int const ledger_fetch_size_;
TaggedCache<uint256, Blob> fetch_packs_;
std::uint32_t fetch_seq_;
//--------------------------------------------------------------------------
LedgerMasterImp (Application& app, Stopwatch& stopwatch,
Stoppable& parent, Stoppable& parent,
beast::insight::Collector::ptr const& collector, beast::Journal journal) beast::insight::Collector::ptr const& collector, beast::Journal journal)
: LedgerMaster (parent) : Stoppable ("LedgerMaster", parent)
, app_ (app) , app_ (app)
, m_journal (journal) , m_journal (journal)
, mLastValidLedger (std::make_pair (uint256(), 0)) , mLastValidLedger (std::make_pair (uint256(), 0))
, mLedgerHistory (collector, app) , mLedgerHistory (collector, app)
, mHeldTransactions (uint256 ()) , mHeldTransactions (uint256 ())
, mLedgerCleaner (make_LedgerCleaner ( , mLedgerCleaner (detail::make_LedgerCleaner (
app, *this, app_.journal("LedgerCleaner"))) app, *this, app_.journal("LedgerCleaner")))
, mMinValidations (0) , mMinValidations (0)
, mStrictValCount (false) , mStrictValCount (false)
@@ -180,22 +96,21 @@ public:
{ {
} }
~LedgerMasterImp () LedgerIndex
{ LedgerMaster::getCurrentLedgerIndex ()
}
LedgerIndex getCurrentLedgerIndex () override
{ {
return app_.openLedger().current()->info().seq; return app_.openLedger().current()->info().seq;
} }
LedgerIndex getValidLedgerIndex () override LedgerIndex
LedgerMaster::getValidLedgerIndex ()
{ {
return mValidLedgerSeq; return mValidLedgerSeq;
} }
bool isCompatible (Ledger::pointer ledger, bool
beast::Journal::Stream s, const char* reason) override LedgerMaster::isCompatible (Ledger::pointer ledger,
beast::Journal::Stream s, const char* reason)
{ {
if (mStrictValCount) if (mStrictValCount)
{ {
@@ -227,7 +142,7 @@ public:
} }
std::chrono::seconds std::chrono::seconds
getPublishedLedgerAge() override LedgerMaster::getPublishedLedgerAge()
{ {
std::chrono::seconds pubClose{mPubLedgerClose.load()}; std::chrono::seconds pubClose{mPubLedgerClose.load()};
if (pubClose == 0s) if (pubClose == 0s)
@@ -245,7 +160,7 @@ public:
} }
std::chrono::seconds std::chrono::seconds
getValidatedLedgerAge() override LedgerMaster::getValidatedLedgerAge()
{ {
std::chrono::seconds valClose{mValidLedgerSign.load()}; std::chrono::seconds valClose{mValidLedgerSign.load()};
if (valClose == 0s) if (valClose == 0s)
@@ -262,7 +177,8 @@ public:
return ret; return ret;
} }
bool isCaughtUp(std::string& reason) override bool
LedgerMaster::isCaughtUp(std::string& reason)
{ {
if (getPublishedLedgerAge() > 3min) if (getPublishedLedgerAge() > 3min)
{ {
@@ -284,7 +200,8 @@ public:
return true; return true;
} }
void setValidLedger(Ledger::ref l) void
LedgerMaster::setValidLedger(Ledger::ref l)
{ {
std::vector <NetClock::time_point> times; std::vector <NetClock::time_point> times;
NetClock::time_point signTime; NetClock::time_point signTime;
@@ -313,22 +230,25 @@ public:
app_.getAmendmentTable().doValidatedLedger (l); app_.getAmendmentTable().doValidatedLedger (l);
} }
void setPubLedger(Ledger::ref l) void
LedgerMaster::setPubLedger(Ledger::ref l)
{ {
mPubLedger = l; mPubLedger = l;
mPubLedgerClose = l->info().closeTime.time_since_epoch().count(); mPubLedgerClose = l->info().closeTime.time_since_epoch().count();
mPubLedgerSeq = l->info().seq; mPubLedgerSeq = l->info().seq;
} }
void addHeldTransaction ( void
std::shared_ptr<Transaction> const& transaction) override LedgerMaster::addHeldTransaction (
std::shared_ptr<Transaction> const& transaction)
{ {
// returns true if transaction was added // returns true if transaction was added
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
mHeldTransactions.insert (transaction->getSTransaction ()); mHeldTransactions.insert (transaction->getSTransaction ());
} }
void switchLCL (Ledger::pointer lastClosed) override void
LedgerMaster::switchLCL (Ledger::pointer lastClosed)
{ {
assert (lastClosed); assert (lastClosed);
@@ -352,18 +272,20 @@ public:
} }
bool bool
fixIndex (LedgerIndex ledgerIndex, LedgerHash const& ledgerHash) override LedgerMaster::fixIndex (LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
{ {
return mLedgerHistory.fixIndex (ledgerIndex, ledgerHash); return mLedgerHistory.fixIndex (ledgerIndex, ledgerHash);
} }
bool storeLedger (Ledger::pointer ledger) override bool
LedgerMaster::storeLedger (Ledger::pointer ledger)
{ {
// Returns true if we already had the ledger // Returns true if we already had the ledger
return mLedgerHistory.addLedger (ledger, false); return mLedgerHistory.addLedger (ledger, false);
} }
void forceValid (Ledger::pointer ledger) override void
LedgerMaster::forceValid (Ledger::pointer ledger)
{ {
ledger->setValidated(); ledger->setValidated();
setFullLedger(ledger, true, false); setFullLedger(ledger, true, false);
@@ -374,7 +296,8 @@ public:
The open ledger remains open to handle new transactions The open ledger remains open to handle new transactions
until a new open ledger is built. until a new open ledger is built.
*/ */
void applyHeldTransactions () override void
LedgerMaster::applyHeldTransactions ()
{ {
ScopedLockType sl (m_mutex); ScopedLockType sl (m_mutex);
@@ -401,31 +324,36 @@ public:
app_.openLedger().current()->info().parentHash); app_.openLedger().current()->info().parentHash);
} }
LedgerIndex getBuildingLedger () override LedgerIndex
LedgerMaster::getBuildingLedger ()
{ {
// The ledger we are currently building, 0 of none // The ledger we are currently building, 0 of none
return mBuildingLedgerSeq.load (); return mBuildingLedgerSeq.load ();
} }
void setBuildingLedger (LedgerIndex i) override void
LedgerMaster::setBuildingLedger (LedgerIndex i)
{ {
mBuildingLedgerSeq.store (i); mBuildingLedgerSeq.store (i);
} }
bool haveLedger (std::uint32_t seq) override bool
LedgerMaster::haveLedger (std::uint32_t seq)
{ {
ScopedLockType sl (mCompleteLock); ScopedLockType sl (mCompleteLock);
return mCompleteLedgers.hasValue (seq); return mCompleteLedgers.hasValue (seq);
} }
void clearLedger (std::uint32_t seq) override void
LedgerMaster::clearLedger (std::uint32_t seq)
{ {
ScopedLockType sl (mCompleteLock); ScopedLockType sl (mCompleteLock);
return mCompleteLedgers.clearValue (seq); return mCompleteLedgers.clearValue (seq);
} }
// returns Ledgers we have all the nodes for // returns Ledgers we have all the nodes for
bool getFullValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal) override bool
LedgerMaster::getFullValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal)
{ {
// Validated ledger is likely not stored in the DB yet so we use the // Validated ledger is likely not stored in the DB yet so we use the
// published ledger which is. // published ledger which is.
@@ -448,7 +376,8 @@ public:
} }
// Returns Ledgers we have all the nodes for and are indexed // Returns Ledgers we have all the nodes for and are indexed
bool getValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal) override bool
LedgerMaster::getValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal)
{ {
// Validated ledger is likely not stored in the DB yet so we use the // Validated ledger is likely not stored in the DB yet so we use the
// published ledger which is. // published ledger which is.
@@ -503,7 +432,8 @@ public:
} }
// Get the earliest ledger we will let peers fetch // Get the earliest ledger we will let peers fetch
std::uint32_t getEarliestFetch () override std::uint32_t
LedgerMaster::getEarliestFetch ()
{ {
// The earliest ledger we will let people fetch is ledger zero, // The earliest ledger we will let people fetch is ledger zero,
// unless that creates a larger range than allowed // unless that creates a larger range than allowed
@@ -516,7 +446,8 @@ public:
return e; return e;
} }
void tryFill (Job& job, Ledger::pointer ledger) void
LedgerMaster::tryFill (Job& job, Ledger::pointer ledger)
{ {
std::uint32_t seq = ledger->info().seq; std::uint32_t seq = ledger->info().seq;
uint256 prevHash = ledger->info().parentHash; uint256 prevHash = ledger->info().parentHash;
@@ -577,7 +508,8 @@ public:
/** Request a fetch pack to get to the specified ledger /** Request a fetch pack to get to the specified ledger
*/ */
void getFetchPack (LedgerHash missingHash, LedgerIndex missingIndex) void
LedgerMaster::getFetchPack (LedgerHash missingHash, LedgerIndex missingIndex)
{ {
uint256 haveHash = getLedgerHashForHistory (missingIndex + 1); uint256 haveHash = getLedgerHashForHistory (missingIndex + 1);
@@ -624,7 +556,8 @@ public:
JLOG (m_journal.debug) << "No peer for fetch pack"; JLOG (m_journal.debug) << "No peer for fetch pack";
} }
void fixMismatch (Ledger::ref ledger) override void
LedgerMaster::fixMismatch (Ledger::ref ledger)
{ {
int invalidate = 0; int invalidate = 0;
boost::optional<uint256> hash; boost::optional<uint256> hash;
@@ -670,8 +603,9 @@ public:
invalidate << " prior ledgers invalidated"; invalidate << " prior ledgers invalidated";
} }
void setFullLedger ( void
Ledger::pointer ledger, bool isSynchronous, bool isCurrent) override LedgerMaster::setFullLedger (
Ledger::pointer ledger, bool isSynchronous, bool isCurrent)
{ {
// A new ledger has been accepted as part of the trusted chain // A new ledger has been accepted as part of the trusted chain
JLOG (m_journal.debug) << "Ledger " << ledger->info().seq JLOG (m_journal.debug) << "Ledger " << ledger->info().seq
@@ -729,7 +663,8 @@ public:
} }
} }
void failedSave(std::uint32_t seq, uint256 const& hash) override void
LedgerMaster::failedSave(std::uint32_t seq, uint256 const& hash)
{ {
clearLedger(seq); clearLedger(seq);
app_.getInboundLedgers().acquire( app_.getInboundLedgers().acquire(
@@ -738,7 +673,8 @@ public:
// Check if the specified ledger can become the new last fully-validated // Check if the specified ledger can become the new last fully-validated
// ledger. // ledger.
void checkAccept (uint256 const& hash, std::uint32_t seq) override void
LedgerMaster::checkAccept (uint256 const& hash, std::uint32_t seq)
{ {
int valCount; int valCount;
@@ -800,7 +736,8 @@ public:
* *
* @return Number of validations needed * @return Number of validations needed
*/ */
int getNeededValidations () int
LedgerMaster::getNeededValidations ()
{ {
if (standalone_) if (standalone_)
return 0; return 0;
@@ -821,7 +758,8 @@ public:
return minVal; return minVal;
} }
void checkAccept (Ledger::ref ledger) override void
LedgerMaster::checkAccept (Ledger::ref ledger)
{ {
if (ledger->info().seq <= mValidLedgerSeq) if (ledger->info().seq <= mValidLedgerSeq)
return; return;
@@ -885,7 +823,8 @@ public:
} }
/** Report that the consensus process built a particular ledger */ /** Report that the consensus process built a particular ledger */
void consensusBuilt (Ledger::ref ledger, Json::Value consensus) override void
LedgerMaster::consensusBuilt (Ledger::ref ledger, Json::Value consensus)
{ {
// Because we just built a ledger, we are no longer building one // Because we just built a ledger, we are no longer building one
@@ -981,7 +920,8 @@ public:
mLedgerHistory.builtLedger (ledger, std::move (consensus)); mLedgerHistory.builtLedger (ledger, std::move (consensus));
} }
void advanceThread() void
LedgerMaster::advanceThread()
{ {
ScopedLockType sl (m_mutex); ScopedLockType sl (m_mutex);
assert (!mValidLedger.empty () && mAdvanceThread); assert (!mValidLedger.empty () && mAdvanceThread);
@@ -1002,7 +942,8 @@ public:
} }
// VFALCO NOTE This should return boost::optional<uint256> // VFALCO NOTE This should return boost::optional<uint256>
LedgerHash getLedgerHashForHistory (LedgerIndex index) LedgerHash
LedgerMaster::getLedgerHashForHistory (LedgerIndex index)
{ {
// Try to get the hash of a ledger we need to fetch for history // Try to get the hash of a ledger we need to fetch for history
boost::optional<LedgerHash> ret; boost::optional<LedgerHash> ret;
@@ -1020,21 +961,14 @@ public:
return *ret; return *ret;
} }
bool shouldFetchPack (std::uint32_t seq) const bool
LedgerMaster::shouldFetchPack (std::uint32_t seq) const
{ {
return (fetch_seq_ != seq); return (fetch_seq_ != seq);
} }
bool shouldAcquire ( std::vector<Ledger::pointer>
std::uint32_t const currentLedger, LedgerMaster::findNewLedgersToPublish ()
std::uint32_t const ledgerHistory,
std::uint32_t const ledgerHistoryIndex,
std::uint32_t const candidateLedger) const;
// Try to publish ledgers, acquire missing ledgers
void doAdvance ();
std::vector<Ledger::pointer> findNewLedgersToPublish ()
{ {
std::vector<Ledger::pointer> ret; std::vector<Ledger::pointer> ret;
@@ -1126,7 +1060,8 @@ public:
return ret; return ret;
} }
void tryAdvance() override void
LedgerMaster::tryAdvance()
{ {
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
@@ -1144,7 +1079,8 @@ public:
// Return the hash of the valid ledger with a particular sequence, given a // Return the hash of the valid ledger with a particular sequence, given a
// subsequent ledger known valid. // subsequent ledger known valid.
// VFALCO NOTE This should return boost::optional<uint256> // VFALCO NOTE This should return boost::optional<uint256>
uint256 getLedgerHash(std::uint32_t desiredSeq, Ledger::ref knownGoodLedger) override uint256
LedgerMaster::getLedgerHash(std::uint32_t desiredSeq, Ledger::ref knownGoodLedger)
{ {
assert(desiredSeq < knownGoodLedger->info().seq); assert(desiredSeq < knownGoodLedger->info().seq);
@@ -1177,7 +1113,8 @@ public:
return hash ? *hash : zero; // kludge return hash ? *hash : zero; // kludge
} }
void updatePaths (Job& job) void
LedgerMaster::updatePaths (Job& job)
{ {
{ {
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
@@ -1254,7 +1191,8 @@ public:
} }
} }
void newPathRequest () override void
LedgerMaster::newPathRequest ()
{ {
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
mPathFindNewRequest = true; mPathFindNewRequest = true;
@@ -1262,7 +1200,8 @@ public:
newPFWork("pf:newRequest"); newPFWork("pf:newRequest");
} }
bool isNewPathRequest () override bool
LedgerMaster::isNewPathRequest ()
{ {
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
if (!mPathFindNewRequest) if (!mPathFindNewRequest)
@@ -1273,7 +1212,8 @@ public:
// If the order book is radically updated, we need to reprocess all // If the order book is radically updated, we need to reprocess all
// pathfinding requests. // pathfinding requests.
void newOrderBookDB () override void
LedgerMaster::newOrderBookDB ()
{ {
ScopedLockType ml (m_mutex); ScopedLockType ml (m_mutex);
mPathLedger.reset(); mPathLedger.reset();
@@ -1283,7 +1223,8 @@ public:
/** A thread needs to be dispatched to handle pathfinding work of some kind. /** A thread needs to be dispatched to handle pathfinding work of some kind.
*/ */
void newPFWork (const char *name) void
LedgerMaster::newPFWork (const char *name)
{ {
if (mPathFindThread < 2) if (mPathFindThread < 2)
{ {
@@ -1294,30 +1235,35 @@ public:
} }
} }
std::recursive_mutex& peekMutex () override std::recursive_mutex&
LedgerMaster::peekMutex ()
{ {
return m_mutex; return m_mutex;
} }
// The current ledger is the ledger we believe new transactions should go in // The current ledger is the ledger we believe new transactions should go in
std::shared_ptr<ReadView const> getCurrentLedger () override std::shared_ptr<ReadView const>
LedgerMaster::getCurrentLedger ()
{ {
return app_.openLedger().current(); return app_.openLedger().current();
} }
// The finalized ledger is the last closed/accepted ledger // The finalized ledger is the last closed/accepted ledger
Ledger::pointer getClosedLedger () override Ledger::pointer
LedgerMaster::getClosedLedger ()
{ {
return mClosedLedger.get (); return mClosedLedger.get ();
} }
// The validated ledger is the last fully validated ledger // The validated ledger is the last fully validated ledger
Ledger::pointer getValidatedLedger () override Ledger::pointer
LedgerMaster::getValidatedLedger ()
{ {
return mValidLedger.get (); return mValidLedger.get ();
} }
Rules getValidatedRules () override Rules
LedgerMaster::getValidatedRules ()
{ {
// Once we have a guarantee that there's always a last validated // Once we have a guarantee that there's always a last validated
// ledger then we can dispense with the if. // ledger then we can dispense with the if.
@@ -1331,13 +1277,15 @@ public:
// This is the last ledger we published to clients and can lag the validated // This is the last ledger we published to clients and can lag the validated
// ledger. // ledger.
Ledger::pointer getPublishedLedger () override Ledger::pointer
LedgerMaster::getPublishedLedger ()
{ {
ScopedLockType lock(m_mutex); ScopedLockType lock(m_mutex);
return mPubLedger; return mPubLedger;
} }
bool isValidLedger(LedgerInfo const& info) override bool
LedgerMaster::isValidLedger(LedgerInfo const& info)
{ {
if (info.validated) if (info.validated)
return true; return true;
@@ -1367,12 +1315,14 @@ public:
return true; return true;
} }
int getMinValidations () override int
LedgerMaster::getMinValidations ()
{ {
return mMinValidations; return mMinValidations;
} }
void setMinValidations (int v, bool strict) override void
LedgerMaster::setMinValidations (int v, bool strict)
{ {
JLOG (m_journal.info) << "Validation quorum: " << v JLOG (m_journal.info) << "Validation quorum: " << v
<< (strict ? " strict" : ""); << (strict ? " strict" : "");
@@ -1380,21 +1330,22 @@ public:
mStrictValCount = strict; mStrictValCount = strict;
} }
std::string getCompleteLedgers () override std::string
LedgerMaster::getCompleteLedgers ()
{ {
ScopedLockType sl (mCompleteLock); ScopedLockType sl (mCompleteLock);
return mCompleteLedgers.toString (); return mCompleteLedgers.toString ();
} }
boost::optional <NetClock::time_point> boost::optional <NetClock::time_point>
getCloseTimeBySeq (LedgerIndex ledgerIndex) override LedgerMaster::getCloseTimeBySeq (LedgerIndex ledgerIndex)
{ {
uint256 hash = getHashBySeq (ledgerIndex); uint256 hash = getHashBySeq (ledgerIndex);
return hash.isNonZero() ? getCloseTimeByHash (hash) : boost::none; return hash.isNonZero() ? getCloseTimeByHash (hash) : boost::none;
} }
boost::optional <NetClock::time_point> boost::optional <NetClock::time_point>
getCloseTimeByHash (LedgerHash const& ledgerHash) override LedgerMaster::getCloseTimeByHash (LedgerHash const& ledgerHash)
{ {
auto node = app_.getNodeStore().fetch (ledgerHash); auto node = app_.getNodeStore().fetch (ledgerHash);
if (node && if (node &&
@@ -1413,7 +1364,8 @@ public:
return boost::none; return boost::none;
} }
uint256 getHashBySeq (std::uint32_t index) override uint256
LedgerMaster::getHashBySeq (std::uint32_t index)
{ {
uint256 hash = mLedgerHistory.getLedgerHash (index); uint256 hash = mLedgerHistory.getLedgerHash (index);
@@ -1424,7 +1376,8 @@ public:
} }
// VFALCO NOTE This should return boost::optional<uint256> // VFALCO NOTE This should return boost::optional<uint256>
uint256 walkHashBySeq (std::uint32_t index) override uint256
LedgerMaster::walkHashBySeq (std::uint32_t index)
{ {
uint256 ledgerHash; uint256 ledgerHash;
Ledger::pointer referenceLedger; Ledger::pointer referenceLedger;
@@ -1443,7 +1396,8 @@ public:
in the node store. in the node store.
*/ */
// VFALCO NOTE This should return boost::optional<uint256> // VFALCO NOTE This should return boost::optional<uint256>
uint256 walkHashBySeq (std::uint32_t index, Ledger::ref referenceLedger) override uint256
LedgerMaster::walkHashBySeq (std::uint32_t index, Ledger::ref referenceLedger)
{ {
if (!referenceLedger || (referenceLedger->info().seq < index)) if (!referenceLedger || (referenceLedger->info().seq < index))
{ {
@@ -1493,7 +1447,8 @@ public:
return ledgerHash ? *ledgerHash : zero; // kludge return ledgerHash ? *ledgerHash : zero; // kludge
} }
Ledger::pointer getLedgerBySeq (std::uint32_t index) override Ledger::pointer
LedgerMaster::getLedgerBySeq (std::uint32_t index)
{ {
if (index <= mValidLedgerSeq) if (index <= mValidLedgerSeq)
{ {
@@ -1529,7 +1484,8 @@ public:
return Ledger::pointer(); return Ledger::pointer();
} }
Ledger::pointer getLedgerByHash (uint256 const& hash) override Ledger::pointer
LedgerMaster::getLedgerByHash (uint256 const& hash)
{ {
Ledger::pointer ret = mLedgerHistory.getLedgerByHash (hash); Ledger::pointer ret = mLedgerHistory.getLedgerByHash (hash);
if (ret) if (ret)
@@ -1542,38 +1498,46 @@ public:
return Ledger::pointer (); return Ledger::pointer ();
} }
void doLedgerCleaner(Json::Value const& parameters) override void
LedgerMaster::doLedgerCleaner(Json::Value const& parameters)
{ {
mLedgerCleaner->doClean (parameters); mLedgerCleaner->doClean (parameters);
} }
void setLedgerRangePresent (std::uint32_t minV, std::uint32_t maxV) override void
LedgerMaster::setLedgerRangePresent (std::uint32_t minV, std::uint32_t maxV)
{ {
ScopedLockType sl (mCompleteLock); ScopedLockType sl (mCompleteLock);
mCompleteLedgers.setRange (minV, maxV); mCompleteLedgers.setRange (minV, maxV);
} }
void tune (int size, int age) override
void
LedgerMaster::tune (int size, int age)
{ {
mLedgerHistory.tune (size, age); mLedgerHistory.tune (size, age);
} }
void sweep () override void
LedgerMaster::sweep ()
{ {
mLedgerHistory.sweep (); mLedgerHistory.sweep ();
fetch_packs_.sweep (); fetch_packs_.sweep ();
} }
float getCacheHitRate () override float
LedgerMaster::getCacheHitRate ()
{ {
return mLedgerHistory.getCacheHitRate (); return mLedgerHistory.getCacheHitRate ();
} }
beast::PropertyStream::Source& getPropertySource () override beast::PropertyStream::Source&
LedgerMaster::getPropertySource ()
{ {
return *mLedgerCleaner; return *mLedgerCleaner;
} }
void clearPriorLedgers (LedgerIndex seq) override void
LedgerMaster::clearPriorLedgers (LedgerIndex seq)
{ {
ScopedLockType sl (mCompleteLock); ScopedLockType sl (mCompleteLock);
for (LedgerIndex i = mCompleteLedgers.getFirst(); i < seq; ++i) for (LedgerIndex i = mCompleteLedgers.getFirst(); i < seq; ++i)
@@ -1583,44 +1547,26 @@ public:
} }
} }
void clearLedgerCachePrior (LedgerIndex seq) override void
LedgerMaster::clearLedgerCachePrior (LedgerIndex seq)
{ {
mLedgerHistory.clearLedgerCachePrior (seq); mLedgerHistory.clearLedgerCachePrior (seq);
} }
void takeReplay (std::unique_ptr<LedgerReplay> replay) override void
LedgerMaster::takeReplay (std::unique_ptr<LedgerReplay> replay)
{ {
replayData = std::move (replay); replayData = std::move (replay);
} }
std::unique_ptr<LedgerReplay> releaseReplay () override std::unique_ptr<LedgerReplay>
LedgerMaster::releaseReplay ()
{ {
return std::move (replayData); return std::move (replayData);
} }
// Fetch packs: bool
void gotFetchPack ( LedgerMaster::shouldAcquire (
bool progress,
std::uint32_t seq) override;
void addFetchPack (
uint256 const& hash,
std::shared_ptr<Blob>& data) override;
bool getFetchPack (
uint256 const& hash,
Blob& data) override;
void makeFetchPack (
std::weak_ptr<Peer> const& wPeer,
std::shared_ptr<protocol::TMGetObjectByHash> const& request,
uint256 haveLedgerHash,
std::uint32_t uUptime) override;
std::size_t getFetchPackCacheSize () const override;
};
bool LedgerMasterImp::shouldAcquire (
std::uint32_t const currentLedger, std::uint32_t const currentLedger,
std::uint32_t const ledgerHistory, std::uint32_t const ledgerHistory,
std::uint32_t const ledgerHistoryIndex, std::uint32_t const ledgerHistoryIndex,
@@ -1639,7 +1585,7 @@ bool LedgerMasterImp::shouldAcquire (
} }
// Try to publish ledgers, acquire missing ledgers // Try to publish ledgers, acquire missing ledgers
void LedgerMasterImp::doAdvance () void LedgerMaster::doAdvance ()
{ {
// TODO NIKB: simplify and unindent this a bit! // TODO NIKB: simplify and unindent this a bit!
@@ -1821,14 +1767,16 @@ void LedgerMasterImp::doAdvance ()
} while (mAdvanceWork); } while (mAdvanceWork);
} }
void LedgerMasterImp::addFetchPack ( void
LedgerMaster::addFetchPack (
uint256 const& hash, uint256 const& hash,
std::shared_ptr< Blob >& data) std::shared_ptr< Blob >& data)
{ {
fetch_packs_.canonicalize (hash, data); fetch_packs_.canonicalize (hash, data);
} }
bool LedgerMasterImp::getFetchPack ( bool
LedgerMaster::getFetchPack (
uint256 const& hash, uint256 const& hash,
Blob& data) Blob& data)
{ {
@@ -1840,7 +1788,8 @@ bool LedgerMasterImp::getFetchPack (
return hash == sha512Half(makeSlice(data)); return hash == sha512Half(makeSlice(data));
} }
void LedgerMasterImp::gotFetchPack ( void
LedgerMaster::gotFetchPack (
bool progress, bool progress,
std::uint32_t seq) std::uint32_t seq)
{ {
@@ -1853,7 +1802,8 @@ void LedgerMasterImp::gotFetchPack (
[&] (Job&) { app_.getInboundLedgers().gotFetchPack(); }); [&] (Job&) { app_.getInboundLedgers().gotFetchPack(); });
} }
void LedgerMasterImp::makeFetchPack ( void
LedgerMaster::makeFetchPack (
std::weak_ptr<Peer> const& wPeer, std::weak_ptr<Peer> const& wPeer,
std::shared_ptr<protocol::TMGetObjectByHash> const& request, std::shared_ptr<protocol::TMGetObjectByHash> const& request,
uint256 haveLedgerHash, uint256 haveLedgerHash,
@@ -1992,28 +1942,10 @@ void LedgerMasterImp::makeFetchPack (
} }
} }
std::size_t LedgerMasterImp::getFetchPackCacheSize () const std::size_t
LedgerMaster::getFetchPackCacheSize () const
{ {
return fetch_packs_.getCacheSize (); return fetch_packs_.getCacheSize ();
} }
//------------------------------------------------------------------------------
LedgerMaster::LedgerMaster (Stoppable& parent)
: Stoppable ("LedgerMaster", parent)
{
}
std::unique_ptr<LedgerMaster>
make_LedgerMaster (
Application& app,
Stopwatch& stopwatch,
beast::Stoppable& parent,
beast::insight::Collector::ptr const& collector,
beast::Journal journal)
{
return std::make_unique <LedgerMasterImp> (
app, stopwatch, parent, collector, journal);
}
} // ripple } // ripple

View File

@@ -416,7 +416,7 @@ public:
, m_pathRequests (std::make_unique<PathRequests> ( , m_pathRequests (std::make_unique<PathRequests> (
*this, logs_->journal("PathRequest"), m_collectorManager->collector ())) *this, logs_->journal("PathRequest"), m_collectorManager->collector ()))
, m_ledgerMaster (make_LedgerMaster (*this, stopwatch (), , m_ledgerMaster (std::make_unique<LedgerMaster> (*this, stopwatch (),
*m_jobQueue, m_collectorManager->collector (), *m_jobQueue, m_collectorManager->collector (),
logs_->journal("LedgerMaster"))) logs_->journal("LedgerMaster")))