From 4c82161d7a19b281c1add7ce7e08b20df4a93600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Malinowski?= Date: Thu, 29 Mar 2018 12:27:24 +0200 Subject: [PATCH] add Config::getExpectedLedgerCloseTime method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RafaƂ Malinowski --- src/herder/HerderImpl.cpp | 11 +---------- src/ledger/LedgerManagerImpl.cpp | 2 +- src/main/Config.cpp | 15 +++++++++++++++ src/main/Config.h | 2 ++ src/simulation/LoadGenerator.cpp | 6 ++++-- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/herder/HerderImpl.cpp b/src/herder/HerderImpl.cpp index fbbd65cfe5..2a4f82facf 100644 --- a/src/herder/HerderImpl.cpp +++ b/src/herder/HerderImpl.cpp @@ -563,16 +563,7 @@ HerderImpl::ledgerClosed() return; } - auto seconds = Herder::EXP_LEDGER_TIMESPAN_SECONDS; - if (mApp.getConfig().ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING) - { - seconds = std::chrono::seconds(1); - } - if (mApp.getConfig().ARTIFICIALLY_SET_CLOSE_TIME_FOR_TESTING) - { - seconds = std::chrono::seconds( - mApp.getConfig().ARTIFICIALLY_SET_CLOSE_TIME_FOR_TESTING); - } + auto seconds = mApp.getConfig().getExpectedLedgerCloseTime(); // bootstrap with a pessimistic estimate of when // the ballot protocol started last diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index d96c9faa59..a21b62ce7a 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -526,7 +526,7 @@ LedgerManagerImpl::startCatchupIf(uint32_t lastReceivedLedgerSeq) else { auto eta = (mCatchupTriggerLedger - lastReceivedLedgerSeq) * - Herder::EXP_LEDGER_TIMESPAN_SECONDS; + mApp.getConfig().getExpectedLedgerCloseTime(); auto message = fmt::format( "Waiting for trigger ledger: {}/{}, ETA: {}s", lastReceivedLedgerSeq, mCatchupTriggerLedger, eta.count()); diff --git a/src/main/Config.cpp b/src/main/Config.cpp index cb04149ac7..aa498cc2d6 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -6,6 +6,7 @@ #include "main/Config.h" #include "crypto/Hex.h" #include "crypto/KeyUtils.h" +#include "herder/Herder.h" #include "history/HistoryArchive.h" #include "ledger/LedgerManager.h" #include "main/ExternalQueue.h" @@ -782,4 +783,18 @@ Config::expandNodeID(const std::string& s) const return {}; } } + +std::chrono::seconds +Config::getExpectedLedgerCloseTime() const +{ + if (ARTIFICIALLY_SET_CLOSE_TIME_FOR_TESTING) + { + return std::chrono::seconds{ARTIFICIALLY_SET_CLOSE_TIME_FOR_TESTING}; + } + if (ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING) + { + return std::chrono::seconds{1}; + } + return Herder::EXP_LEDGER_TIMESPAN_SECONDS; +} } diff --git a/src/main/Config.h b/src/main/Config.h index c09f69f15e..f2c7c7402c 100644 --- a/src/main/Config.h +++ b/src/main/Config.h @@ -213,5 +213,7 @@ class Config : public std::enable_shared_from_this std::string toStrKey(PublicKey const& pk, bool& isAlias) const; std::string toStrKey(PublicKey const& pk) const; bool resolveNodeID(std::string const& s, PublicKey& retKey) const; + + std::chrono::seconds getExpectedLedgerCloseTime() const; }; } diff --git a/src/simulation/LoadGenerator.cpp b/src/simulation/LoadGenerator.cpp index 980878a6f9..f7e94ab798 100644 --- a/src/simulation/LoadGenerator.cpp +++ b/src/simulation/LoadGenerator.cpp @@ -370,7 +370,8 @@ LoadGenerator::inspectRate(uint32_t ledgerNum, uint32_t& txRate) // enough, independent of database close-speed. double targetAge = - (double)Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * 1000.0; + (double)mApp.getConfig().getExpectedLedgerCloseTime().count() * + 1000.0; double actualAge = ledgerAgeClosedTimer.mean(); if (mApp.getConfig().ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING) @@ -627,7 +628,8 @@ LoadGenerator::waitTillComplete() } else { - mLoadTimer->expires_from_now(Herder::EXP_LEDGER_TIMESPAN_SECONDS); + mLoadTimer->expires_from_now( + mApp.getConfig().getExpectedLedgerCloseTime()); mLoadTimer->async_wait([this](asio::error_code const& error) { if (!error) {