Skip to content

Commit

Permalink
add Config::getExpectedLedgerCloseTime method
Browse files Browse the repository at this point in the history
Signed-off-by: Rafał Malinowski <[email protected]>
  • Loading branch information
vogel committed Apr 25, 2018
1 parent 6efec67 commit 4c82161
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
11 changes: 1 addition & 10 deletions src/herder/HerderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 15 additions & 0 deletions src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,7 @@ class Config : public std::enable_shared_from_this<Config>
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;
};
}
6 changes: 4 additions & 2 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 4c82161

Please sign in to comment.