-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: use SteadyClock instead of SystemClock for duration measurements in Dash-specific code #7283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use SteadyClock instead of SystemClock for duration measurements in Dash-specific code #7283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ class CDKGSessionManager | |
| using SessionHandlerMap = std::map<SessionHandlerKey, std::unique_ptr<CDKGSessionHandler>>; | ||
|
|
||
| private: | ||
| static constexpr int64_t MAX_CONTRIBUTION_CACHE_TIME = 60 * 1000; | ||
| static constexpr auto MAX_CONTRIBUTION_CACHE_TIME = 60s; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing |
||
|
|
||
| private: | ||
| CDeterministicMNManager& m_dmnman; | ||
|
|
@@ -84,7 +84,7 @@ class CDKGSessionManager | |
| } | ||
| }; | ||
| struct ContributionsCacheEntry { | ||
| int64_t entryTime; | ||
| SteadyClock::time_point entryTime; | ||
| BLSVerificationVectorPtr vvec; | ||
| CBLSSecretKey skContribution; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2119,17 +2119,17 @@ void CConnman::DisconnectNodes() | |
| // the socket), we can be pretty sure that they are not interested in any pending messages anymore and | ||
| // thus can immediately close the socket. | ||
| if (!pnode->fOtherSideDisconnected) { | ||
| if (pnode->nDisconnectLingerTime == 0) { | ||
| if (pnode->nDisconnectLingerTime.load() == SteadyClock::time_point{}) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick: Default-constructed time_point used as sentinel The source: ['claude'] |
||
| // let's not immediately close the socket but instead wait for at least 100ms so that there is a | ||
| // chance to flush all/some pending data. Otherwise the other side might not receive REJECT messages | ||
| // that were pushed right before setting fDisconnect=true | ||
| // Flushing must happen in two places to ensure data can be received by the other side: | ||
| // 1. vSendMsg must be empty and all messages sent via send(). This is ensured by SocketHandler() | ||
| // being called before DisconnectNodes and also by the linger time | ||
| // 2. Internal socket send buffers must be flushed. This is ensured solely by the linger time | ||
| pnode->nDisconnectLingerTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) + 100; | ||
| pnode->nDisconnectLingerTime = SteadyClock::now() + 100ms; | ||
| } | ||
| if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) < pnode->nDisconnectLingerTime) { | ||
| if (SteadyClock::now() < pnode->nDisconnectLingerTime.load()) { | ||
| // everything flushed to the kernel? | ||
| const auto& [to_send, more, _msg_type] = pnode->m_transport->GetBytesToSend(pnode->nSendMsgSize != 0); | ||
| const bool queue_is_empty{to_send.empty() && !more}; | ||
|
|
@@ -2636,18 +2636,18 @@ void CConnman::ThreadSocketHandler(CMasternodeSync& mn_sync) | |
| { | ||
| AssertLockNotHeld(m_total_bytes_sent_mutex); | ||
|
|
||
| int64_t nLastCleanupNodes = 0; | ||
| auto nLastCleanupNodes = SteadyClock::time_point{}; | ||
|
|
||
| while (!interruptNet) | ||
| { | ||
| // Handle sockets before we do the next round of disconnects. This allows us to flush send buffers one last time | ||
| // before actually closing sockets. Receiving is however skipped in case a peer is pending to be disconnected | ||
| SocketHandler(mn_sync); | ||
| if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nLastCleanupNodes > 1000) { | ||
| if (SteadyClock::now() - nLastCleanupNodes > 1s) { | ||
| ForEachNode(AllNodes, [&](CNode* pnode) { | ||
| if (InactivityCheck(*pnode)) pnode->fDisconnect = true; | ||
| }); | ||
| nLastCleanupNodes = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); | ||
| nLastCleanupNodes = SteadyClock::now(); | ||
| } | ||
| DisconnectNodes(); | ||
| NotifyNumConnectionsChanged(mn_sync); | ||
|
|
@@ -3663,17 +3663,17 @@ void CConnman::ThreadMessageHandler() | |
| { | ||
| LOCK(NetEventsInterface::g_msgproc_mutex); | ||
|
|
||
| int64_t nLastSendMessagesTimeMasternodes = 0; | ||
| auto nLastSendMessagesTimeMasternodes = SteadyClock::time_point{}; | ||
|
|
||
| FastRandomContext rng; | ||
| while (!flagInterruptMsgProc) | ||
| { | ||
| bool fMoreWork = false; | ||
|
|
||
| bool fSkipSendMessagesForMasternodes = true; | ||
| if (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nLastSendMessagesTimeMasternodes >= 100) { | ||
| if (SteadyClock::now() - nLastSendMessagesTimeMasternodes >= 100ms) { | ||
| fSkipSendMessagesForMasternodes = false; | ||
| nLastSendMessagesTimeMasternodes = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); | ||
| nLastSendMessagesTimeMasternodes = SteadyClock::now(); | ||
| } | ||
|
|
||
| // Randomize the order in which we process messages from/to our peers. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,7 +784,7 @@ class CNode | |
| // Setting fDisconnect to true will cause the node to be disconnected the | ||
| // next time DisconnectNodes() runs | ||
| std::atomic_bool fDisconnect{false}; | ||
| std::atomic<int64_t> nDisconnectLingerTime{0}; | ||
| std::atomic<SteadyClock::time_point> nDisconnectLingerTime{SteadyClock::time_point{}}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick: std::atomicSteadyClock::time_point lock-freedom is not asserted
source: ['claude'] |
||
| std::atomic_bool fSocketShutdown{false}; | ||
| std::atomic_bool fOtherSideDisconnected { false }; | ||
| // If 'true' this node will be disconnected on CMasternodeMan::ProcessMasternodeConnections() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing util/time.h include in instantsend.h