From fa51cc965110e14661c848364a29c493287673be Mon Sep 17 00:00:00 2001 From: MacroFake Date: Thu, 13 Oct 2022 14:49:13 +0200 Subject: [PATCH] refactor: Use type-safe time point for CWallet::m_next_resend --- src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a576b07f50..9a383582ca 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1916,12 +1916,12 @@ bool CWallet::ShouldResend() const // Do this infrequently and randomly to avoid giving away // that these are our transactions. - if (GetTime() < m_next_resend) return false; + if (NodeClock::now() < m_next_resend) return false; return true; } -int64_t CWallet::GetDefaultNextResend() { return GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60); } +NodeClock::time_point CWallet::GetDefaultNextResend() { return FastRandomContext{}.rand_uniform_delay(NodeClock::now() + 12h, 24h); } // Resubmit transactions from the wallet to the mempool, optionally asking the // mempool to relay them. On startup, we will do this for all unconfirmed diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6312ef7820..9076fe31ec 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -250,7 +251,7 @@ private: int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE}; /** The next scheduled rebroadcast of wallet transactions. */ - int64_t m_next_resend{GetDefaultNextResend()}; + NodeClock::time_point m_next_resend{GetDefaultNextResend()}; /** Whether this wallet will submit newly created transactions to the node's mempool and * prompt rebroadcasts (see ResendWalletTransactions()). */ bool fBroadcastTransactions = false; @@ -348,7 +349,7 @@ private: */ static bool AttachChain(const std::shared_ptr& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector& warnings); - static int64_t GetDefaultNextResend(); + static NodeClock::time_point GetDefaultNextResend(); public: /**