Skip to content

Commit 4a744c7

Browse files
committed
refactor: use std::chrono for time variables, reduce resolution
1 parent b051c22 commit 4a744c7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/chainlock/chainlock.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ using node::GetTransaction;
3232

3333
namespace llmq {
3434
namespace {
35-
static constexpr int64_t CLEANUP_INTERVAL{1000 * 30};
36-
static constexpr int64_t CLEANUP_SEEN_TIMEOUT{24 * 60 * 60 * 1000};
35+
static constexpr auto CLEANUP_INTERVAL{30s};
36+
static constexpr auto CLEANUP_SEEN_TIMEOUT{24h};
3737
//! How long to wait for islocks until we consider a block with non-islocked TXs to be safe to sign
38-
static constexpr int64_t WAIT_FOR_ISLOCK_TIMEOUT{10 * 60};
38+
static constexpr auto WAIT_FOR_ISLOCK_TIMEOUT{10min};
3939
} // anonymous namespace
4040

4141
bool AreChainLocksEnabled(const CSporkManager& sporkman)
@@ -133,7 +133,7 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro
133133

134134
{
135135
LOCK(cs);
136-
if (!seenChainLocks.emplace(hash, TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now())).second) {
136+
if (!seenChainLocks.emplace(hash, GetTime<std::chrono::seconds>()).second) {
137137
return {};
138138
}
139139

@@ -305,16 +305,16 @@ int32_t CChainLocksHandler::GetBestChainLockHeight() const
305305

306306
bool CChainLocksHandler::IsTxSafeForMining(const uint256& txid) const
307307
{
308-
int64_t txAge = 0;
308+
auto tx_age{0s};
309309
{
310310
LOCK(cs);
311311
auto it = txFirstSeenTime.find(txid);
312312
if (it != txFirstSeenTime.end()) {
313-
txAge = GetTime<std::chrono::seconds>().count() - it->second;
313+
tx_age = GetTime<std::chrono::seconds>() - it->second;
314314
}
315315
}
316316

317-
return txAge >= WAIT_FOR_ISLOCK_TIMEOUT;
317+
return tx_age >= WAIT_FOR_ISLOCK_TIMEOUT;
318318
}
319319

320320
// WARNING: cs_main and cs should not be held!
@@ -444,15 +444,15 @@ void CChainLocksHandler::Cleanup()
444444
return;
445445
}
446446

447-
if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - lastCleanupTime < CLEANUP_INTERVAL) {
447+
if (GetTime<std::chrono::seconds>() - lastCleanupTime.load() < CLEANUP_INTERVAL) {
448448
return;
449449
}
450-
lastCleanupTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now());
450+
lastCleanupTime = GetTime<std::chrono::seconds>();
451451

452452
{
453453
LOCK(cs);
454454
for (auto it = seenChainLocks.begin(); it != seenChainLocks.end();) {
455-
if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - it->second >= CLEANUP_SEEN_TIMEOUT) {
455+
if (GetTime<std::chrono::seconds>() - it->second >= CLEANUP_SEEN_TIMEOUT) {
456456
it = seenChainLocks.erase(it);
457457
} else {
458458
++it;

src/chainlock/chainlock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent
6161
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs){nullptr};
6262
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs){nullptr};
6363

64-
std::unordered_map<uint256, int64_t, StaticSaltedHasher> txFirstSeenTime GUARDED_BY(cs);
64+
std::unordered_map<uint256, std::chrono::seconds, StaticSaltedHasher> txFirstSeenTime GUARDED_BY(cs);
6565

66-
std::map<uint256, int64_t> seenChainLocks GUARDED_BY(cs);
66+
std::map<uint256, std::chrono::seconds> seenChainLocks GUARDED_BY(cs);
6767

68-
std::atomic<int64_t> lastCleanupTime{0};
68+
std::atomic<std::chrono::seconds> lastCleanupTime{0s};
6969

7070
public:
7171
explicit CChainLocksHandler(CChainState& chainstate, CQuorumManager& _qman, CSigningManager& _sigman,

0 commit comments

Comments
 (0)