From 9932a19139f05d09439287c76dab8b2c4cb315a5 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 18 Feb 2021 14:09:49 -0500 Subject: [PATCH] Reduce coupling to date.h by calling C++17 chrono functions --- src/ripple/app/ledger/impl/LedgerToJson.cpp | 2 - src/ripple/app/main/Application.cpp | 4 +- src/ripple/app/misc/NetworkOPs.cpp | 4 +- src/ripple/app/misc/impl/ValidatorList.cpp | 2 - src/ripple/app/reporting/ETLSource.h | 2 +- src/ripple/app/reporting/ReportingETL.h | 4 +- src/ripple/basics/impl/PerfLogImp.cpp | 2 +- src/ripple/beast/insight/Event.h | 4 +- src/ripple/core/impl/JobQueue.cpp | 4 +- src/ripple/core/impl/LoadMonitor.cpp | 9 ++--- src/ripple/overlay/impl/Handshake.cpp | 2 +- src/test/app/ValidatorSite_test.cpp | 1 + .../consensus/ByzantineFailureSim_test.cpp | 2 +- src/test/consensus/Consensus_test.cpp | 38 ++++++++----------- src/test/consensus/ScaleFreeSim_test.cpp | 2 +- 15 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/ripple/app/ledger/impl/LedgerToJson.cpp b/src/ripple/app/ledger/impl/LedgerToJson.cpp index 94ca237774..eac6843e0b 100644 --- a/src/ripple/app/ledger/impl/LedgerToJson.cpp +++ b/src/ripple/app/ledger/impl/LedgerToJson.cpp @@ -25,8 +25,6 @@ #include #include -#include - namespace ripple { namespace { diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 0baaae14f5..ec9acd3472 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -76,6 +76,8 @@ #include #include +#include + #include #include #include @@ -123,7 +125,7 @@ private: operator()(Duration const& elapsed) { using namespace std::chrono; - auto const lastSample = date::ceil(elapsed); + auto const lastSample = ceil(elapsed); lastSample_ = lastSample; diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 261abe0258..9ce8e4156a 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -2589,8 +2589,8 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) info[jss::server_state] = strOperatingMode(admin); - info[jss::time] = to_string(date::floor( - std::chrono::system_clock::now())); + info[jss::time] = to_string( + floor(std::chrono::system_clock::now())); if (needNetworkLedger_) info[jss::network_ledger] = "waiting"; diff --git a/src/ripple/app/misc/impl/ValidatorList.cpp b/src/ripple/app/misc/impl/ValidatorList.cpp index bda38fe050..3d8dce5094 100644 --- a/src/ripple/app/misc/impl/ValidatorList.cpp +++ b/src/ripple/app/misc/impl/ValidatorList.cpp @@ -32,8 +32,6 @@ #include #include -#include - #include #include #include diff --git a/src/ripple/app/reporting/ETLSource.h b/src/ripple/app/reporting/ETLSource.h index 83d6b470be..4efde9778d 100644 --- a/src/ripple/app/reporting/ETLSource.h +++ b/src/ripple/app/reporting/ETLSource.h @@ -238,7 +238,7 @@ public: auto last = getLastMsgTime(); if (last.time_since_epoch().count() != 0) result["last_message_arrival_time"] = - to_string(date::floor(last)); + to_string(floor(last)); return result; } diff --git a/src/ripple/app/reporting/ReportingETL.h b/src/ripple/app/reporting/ReportingETL.h index 0452b413ee..5ccd8d90d4 100644 --- a/src/ripple/app/reporting/ReportingETL.h +++ b/src/ripple/app/reporting/ReportingETL.h @@ -315,8 +315,8 @@ public: result["is_writer"] = writing_.load(); auto last = getLastPublish(); if (last.time_since_epoch().count() != 0) - result["last_publish_time"] = to_string( - date::floor(getLastPublish())); + result["last_publish_time"] = + to_string(floor(getLastPublish())); return result; } diff --git a/src/ripple/basics/impl/PerfLogImp.cpp b/src/ripple/basics/impl/PerfLogImp.cpp index edf4651c9d..7a20209b74 100644 --- a/src/ripple/basics/impl/PerfLogImp.cpp +++ b/src/ripple/basics/impl/PerfLogImp.cpp @@ -288,7 +288,7 @@ PerfLogImp::report() lastLog_ = present; Json::Value report(Json::objectValue); - report[jss::time] = to_string(date::floor(present)); + report[jss::time] = to_string(floor(present)); { std::lock_guard lock{counters_.jobsMutex_}; report[jss::workers] = diff --git a/src/ripple/beast/insight/Event.h b/src/ripple/beast/insight/Event.h index 7d2ee08d91..5319a9a667 100644 --- a/src/ripple/beast/insight/Event.h +++ b/src/ripple/beast/insight/Event.h @@ -22,8 +22,6 @@ #include -#include - #include #include @@ -67,7 +65,7 @@ public: { using namespace std::chrono; if (m_impl) - m_impl->notify(date::ceil(value)); + m_impl->notify(ceil(value)); } std::shared_ptr const& diff --git a/src/ripple/core/impl/JobQueue.cpp b/src/ripple/core/impl/JobQueue.cpp index 8f1dbff31f..2e1dfaa66c 100644 --- a/src/ripple/core/impl/JobQueue.cpp +++ b/src/ripple/core/impl/JobQueue.cpp @@ -417,14 +417,14 @@ JobQueue::processTask(int instance) // The amount of time that the job was in the queue auto const q_time = - date::ceil(start_time - job.queue_time()); + ceil(start_time - job.queue_time()); perfLog_.jobStart(type, q_time, start_time, instance); job.doJob(); // The amount of time it took to execute the job auto const x_time = - date::ceil(Job::clock_type::now() - start_time); + ceil(Job::clock_type::now() - start_time); if (x_time >= 10ms || q_time >= 10ms) { diff --git a/src/ripple/core/impl/LoadMonitor.cpp b/src/ripple/core/impl/LoadMonitor.cpp index d64722b833..e70b7947a3 100644 --- a/src/ripple/core/impl/LoadMonitor.cpp +++ b/src/ripple/core/impl/LoadMonitor.cpp @@ -21,8 +21,6 @@ #include #include -#include - namespace ripple { /* @@ -106,15 +104,14 @@ LoadMonitor::addLoadSample(LoadEvent const& s) auto const total = s.runTime() + s.waitTime(); // Don't include "jitter" as part of the latency - auto const latency = total < 2ms ? 0ms : date::round(total); + auto const latency = total < 2ms ? 0ms : round(total); if (latency > 500ms) { auto mj = (latency > 1s) ? j_.warn() : j_.info(); JLOG(mj) << "Job: " << s.name() - << " run: " << date::round(s.runTime()).count() - << "ms" - << " wait: " << date::round(s.waitTime()).count() + << " run: " << round(s.runTime()).count() << "ms" + << " wait: " << round(s.waitTime()).count() << "ms"; } diff --git a/src/ripple/overlay/impl/Handshake.cpp b/src/ripple/overlay/impl/Handshake.cpp index b28e5ba356..a11d6b802b 100644 --- a/src/ripple/overlay/impl/Handshake.cpp +++ b/src/ripple/overlay/impl/Handshake.cpp @@ -277,7 +277,7 @@ verifyHandshake( auto const offset = calculateOffset(netTime, ourTime); - if (date::abs(offset) > tolerance) + if (abs(offset) > tolerance) throw std::runtime_error("Peer clock is too far off"); } diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index 3c7bb9c9e8..56626f9257 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/consensus/ByzantineFailureSim_test.cpp b/src/test/consensus/ByzantineFailureSim_test.cpp index 6e760efbf0..73104ab5e8 100644 --- a/src/test/consensus/ByzantineFailureSim_test.cpp +++ b/src/test/consensus/ByzantineFailureSim_test.cpp @@ -40,7 +40,7 @@ class ByzantineFailureSim_test : public beast::unit_test::suite ConsensusParms const parms{}; SimDuration const delay = - date::round(0.2 * parms.ledgerGRANULARITY); + round(0.2 * parms.ledgerGRANULARITY); PeerGroup a = sim.createGroup(1); PeerGroup b = sim.createGroup(1); PeerGroup c = sim.createGroup(1); diff --git a/src/test/consensus/Consensus_test.cpp b/src/test/consensus/Consensus_test.cpp index d2f04cb4a2..1c19ff0708 100644 --- a/src/test/consensus/Consensus_test.cpp +++ b/src/test/consensus/Consensus_test.cpp @@ -151,7 +151,7 @@ public: // Connected trust and network graphs with single fixed delay peers.trustAndConnect( - peers, date::round(0.2 * parms.ledgerGRANULARITY)); + peers, round(0.2 * parms.ledgerGRANULARITY)); // everyone submits their own ID as a TX for (Peer* p : peers) @@ -199,11 +199,10 @@ public: // Fast and slow network connections fast.connect( - fast, date::round(0.2 * parms.ledgerGRANULARITY)); + fast, round(0.2 * parms.ledgerGRANULARITY)); slow.connect( - network, - date::round(1.1 * parms.ledgerGRANULARITY)); + network, round(1.1 * parms.ledgerGRANULARITY)); // All peers submit their own ID as a transaction for (Peer* peer : network) @@ -256,12 +255,11 @@ public: // Fast and slow network connections fast.connect( - fast, - date::round(0.2 * parms.ledgerGRANULARITY)); + fast, round(0.2 * parms.ledgerGRANULARITY)); slow.connect( network, - date::round(1.1 * parms.ledgerGRANULARITY)); + round(1.1 * parms.ledgerGRANULARITY)); for (Peer* peer : slow) peer->runAsValidator = isParticipant; @@ -384,7 +382,7 @@ public: network.trust(network); network.connect( - network, date::round(0.2 * parms.ledgerGRANULARITY)); + network, round(0.2 * parms.ledgerGRANULARITY)); // Run consensus without skew until we have a short close time // resolution @@ -454,7 +452,7 @@ public: PeerGroup network = minority + majority; SimDuration delay = - date::round(0.2 * parms.ledgerGRANULARITY); + round(0.2 * parms.ledgerGRANULARITY); minority.trustAndConnect(minority + majorityA, delay); majority.trustAndConnect(majority, delay); @@ -559,8 +557,7 @@ public: PeerGroup network = loner + clique; network.connect( - network, - date::round(0.2 * parms.ledgerGRANULARITY)); + network, round(0.2 * parms.ledgerGRANULARITY)); // initial round to set prior state sim.run(1); @@ -609,10 +606,9 @@ public: network.trust(network); // Fast and slow network connections - fast.connect( - fast, date::round(0.2 * parms.ledgerGRANULARITY)); + fast.connect(fast, round(0.2 * parms.ledgerGRANULARITY)); slow.connect( - network, date::round(1.1 * parms.ledgerGRANULARITY)); + network, round(1.1 * parms.ledgerGRANULARITY)); // Run to the ledger *prior* to decreasing the resolution sim.run(increaseLedgerTimeResolutionEvery - 2); @@ -712,7 +708,7 @@ public: PeerGroup network = a + b; SimDuration delay = - date::round(0.2 * parms.ledgerGRANULARITY); + round(0.2 * parms.ledgerGRANULARITY); a.trustAndConnect(a, delay); b.trustAndConnect(b, delay); @@ -758,8 +754,7 @@ public: validators.trust(validators); center.trust(validators); - SimDuration delay = - date::round(0.2 * parms.ledgerGRANULARITY); + SimDuration delay = round(0.2 * parms.ledgerGRANULARITY); validators.connect(center, delay); center[0]->runAsValidator = false; @@ -879,10 +874,8 @@ public: PeerGroup groupNotFastC = groupABD + groupCsplit; PeerGroup network = groupABD + groupCsplit + groupCfast; - SimDuration delay = - date::round(0.2 * parms.ledgerGRANULARITY); - SimDuration fDelay = - date::round(0.1 * parms.ledgerGRANULARITY); + SimDuration delay = round(0.2 * parms.ledgerGRANULARITY); + SimDuration fDelay = round(0.1 * parms.ledgerGRANULARITY); network.trust(network); // C must have a shorter delay to see all the validations before the @@ -992,8 +985,7 @@ public: ConsensusParms const parms{}; Sim sim; - SimDuration delay = - date::round(0.2 * parms.ledgerGRANULARITY); + SimDuration delay = round(0.2 * parms.ledgerGRANULARITY); PeerGroup behind = sim.createGroup(3); PeerGroup ahead = sim.createGroup(2); diff --git a/src/test/consensus/ScaleFreeSim_test.cpp b/src/test/consensus/ScaleFreeSim_test.cpp index fe433ea549..4fe911eacf 100644 --- a/src/test/consensus/ScaleFreeSim_test.cpp +++ b/src/test/consensus/ScaleFreeSim_test.cpp @@ -59,7 +59,7 @@ class ScaleFreeSim_test : public beast::unit_test::suite // nodes with a trust line in either direction are network-connected network.connectFromTrust( - date::round(0.2 * parms.ledgerGRANULARITY)); + round(0.2 * parms.ledgerGRANULARITY)); // Initialize collectors to track statistics to report TxCollector txCollector;