diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 8f59c19f01..036a209af4 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,7 @@ #include #include +#include #include #include @@ -172,6 +174,9 @@ public: OverlayFactory overlayFactory_; TimeoutCounterTimerFactory peerTimerFactory_; TimeoutCounterTimerFactory timeoutCounterTimerFactory_; + Stopwatch& stopwatch_; + Stopwatch& preciseStopwatch_; + std::function prng_; std::unique_ptr datagram_monitor_; @@ -282,9 +287,8 @@ public: std::unique_ptr logs, std::unique_ptr timeKeeper, OverlayFactory overlayFactory, - [[maybe_unused]] beast::abstract_clock* - injectedClock, - [[maybe_unused]] beast::xor_shift_engine* injectedPrng, + beast::abstract_clock* injectedClock, + beast::xor_shift_engine* injectedPrng, TimeoutCounterTimerFactory timeoutCounterTimerFactory, TimeoutCounterTimerFactory peerTimerFactory) : BasicApp(numberOfThreads(*config)) @@ -310,6 +314,16 @@ public: return makeAsioTimeoutCounterTimer(getIOService()); }; }()) + , stopwatch_(injectedClock ? *injectedClock : stopwatch()) + , preciseStopwatch_( + injectedClock + ? *injectedClock + : beast::get_abstract_clock()) + , prng_([injectedPrng]() -> beast::xor_shift_engine& { + if (injectedPrng) + return *injectedPrng; + return default_prng(); + }) , instanceCookie_( 1 + rand_int( @@ -374,14 +388,14 @@ public: "NodeCache", 16384, std::chrono::seconds{90}, - stopwatch(), + stopwatch_, logs_->journal("TaggedCache")) , cachedSLEs_( "Cached SLEs", 0, std::chrono::minutes(1), - stopwatch(), + stopwatch_, logs_->journal("CachedSLEs")) , validatorKeys_(*config_, m_journal) @@ -404,7 +418,7 @@ public: , m_ledgerMaster(std::make_unique( *this, - stopwatch(), + stopwatch_, m_collectorManager->collector(), logs_->journal("LedgerMaster"))) @@ -416,7 +430,7 @@ public: // , m_inboundLedgers(make_InboundLedgers( *this, - stopwatch(), + stopwatch_, m_collectorManager->collector())) , m_inboundTransactions(make_InboundTransactions( @@ -435,12 +449,12 @@ public: "AcceptedLedger", 4, std::chrono::minutes{1}, - stopwatch(), + stopwatch_, logs_->journal("TaggedCache")) , m_networkOPs(make_NetworkOPs( *this, - stopwatch(), + preciseStopwatch_, config_->standalone(), config_->NETWORK_QUORUM, config_->START_VALID, @@ -484,12 +498,12 @@ public: std::make_unique(logs_->journal("LoadManager"))) , hashRouter_(std::make_unique( - stopwatch(), + stopwatch_, HashRouter::getDefaultHoldTime())) , mValidations( ValidationParms(), - stopwatch(), + stopwatch_, *this, logs_->journal("Validations")) @@ -656,6 +670,24 @@ public: return peerTimerFactory_(); } + Stopwatch& + getStopwatch() override + { + return stopwatch_; + } + + Stopwatch& + getPreciseStopwatch() override + { + return preciseStopwatch_; + } + + beast::xor_shift_engine& + getPrng() override + { + return prng_(); + } + std::chrono::milliseconds getIOLatency() override { @@ -2183,7 +2215,7 @@ ApplicationImp::loadOldLedger( hash, 0, InboundLedger::Reason::GENERIC, - stopwatch(), + stopwatch_, make_DummyPeerSet(*this)); if (il->checkLocal()) loadLedger = il->getLedger(); @@ -2227,7 +2259,7 @@ ApplicationImp::loadOldLedger( replayLedger->info().parentHash, 0, InboundLedger::Reason::GENERIC, - stopwatch(), + stopwatch_, make_DummyPeerSet(*this)); if (il->checkLocal()) diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index a7cd90458a..b2a61ff199 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -183,7 +183,7 @@ public: ledgerMaster, *m_localTX, app.getInboundTransactions(), - beast::get_abstract_clock(), + clock, validatorKeys, app_.logs().journal("LedgerConsensus")) , m_ledgerMaster(ledgerMaster) @@ -335,6 +335,9 @@ public: void setStateTimer() override; + void + heartbeatTick() override; + void setNeedNetworkLedger() override; void @@ -907,6 +910,9 @@ NetworkOPsImp::setTimer( void NetworkOPsImp::setHeartbeatTimer() { + if (app_.config().manualHeartbeat) + return; + setTimer( heartbeatTimer_, mConsensus.parms().ledgerGRANULARITY, @@ -918,6 +924,14 @@ NetworkOPsImp::setHeartbeatTimer() [this]() { setHeartbeatTimer(); }); } +void +NetworkOPsImp::heartbeatTick() +{ + m_job_queue.addJob(jtNETOP_TIMER, "NetOPs.heartbeat", [this]() { + processHeartbeatTimer(); + }); +} + void NetworkOPsImp::setClusterTimer() { diff --git a/src/xrpld/app/misc/NetworkOPs.h b/src/xrpld/app/misc/NetworkOPs.h index aafef2585a..69fd30e722 100644 --- a/src/xrpld/app/misc/NetworkOPs.h +++ b/src/xrpld/app/misc/NetworkOPs.h @@ -163,6 +163,11 @@ public: virtual void setStateTimer() = 0; + /** Posts the same heartbeat job the asio timer would. Used when + Config::manualHeartbeat suppresses the wall-clock timer. */ + virtual void + heartbeatTick() = 0; + virtual void setNeedNetworkLedger() = 0; virtual void