Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/active/dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ void ActiveDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase, const uint2
double adjustedPhaseSleepTimePerMember = phaseSleepTimePerMember * randomSleepFactor;

int64_t sleepTime = (int64_t)(adjustedPhaseSleepTimePerMember * curSession->GetMyMemberIndex().value_or(0));
int64_t endTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) + sleepTime;
const auto endTime = SteadyClock::now() + std::chrono::milliseconds{sleepTime};
int heightTmp{currentHeight.load()};
int heightStart{heightTmp};

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting sleep for %d ms, curPhase=%d\n", __func__, params.name, quorumIndex, sleepTime, std23::to_underlying(curPhase));

while (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) < endTime) {
while (SteadyClock::now() < endTime) {
if (stopRequested) {
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - aborting due to stop/shutdown requested\n", __func__, params.name, quorumIndex);
throw AbortPhaseException();
Expand Down
4 changes: 2 additions & 2 deletions src/instantsend/instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void CInstantSendManager::EnqueueInstantSendLock(NodeId from, const uint256& has
LOCK(cs_timingsTxSeen);
if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) {
// This is the normal case where we received the TX before the islock
auto diff = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - it->second;
auto diff = Ticks<std::chrono::milliseconds>(SteadyClock::now() - it->second);
timingsTxSeen.erase(it);
return diff;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock
if (ShouldReportISLockTiming()) {
LOCK(cs_timingsTxSeen);
// Only insert the time the first time we see the tx, as we sometimes try to resign
timingsTxSeen.try_emplace(tx->GetHash(), TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()));
timingsTxSeen.try_emplace(tx->GetHash(), SteadyClock::now());
}

LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, pindexMined=%s\n", __func__,
Expand Down
2 changes: 1 addition & 1 deletion src/instantsend/instantsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CInstantSendManager
Uint256HashSet pendingRetryTxs GUARDED_BY(cs_pendingRetry);

mutable Mutex cs_timingsTxSeen;
Uint256HashMap<int64_t> timingsTxSeen GUARDED_BY(cs_timingsTxSeen);
Uint256HashMap<SteadyClock::time_point> timingsTxSeen GUARDED_BY(cs_timingsTxSeen);

mutable Mutex cs_height_cache;
static constexpr size_t MAX_BLOCK_HEIGHT_CACHE{16384};
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/dkgsessionmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType,
CBLSSecretKey skContribution;
db->Read(std::make_tuple(DB_SKCONTRIB, llmqType, pQuorumBaseBlockIndex->GetBlockHash(), proTxHash), skContribution);

it = contributionsCache.emplace(cacheKey, ContributionsCacheEntry{TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()), vvecPtr, skContribution}).first;
it = contributionsCache.emplace(cacheKey, ContributionsCacheEntry{SteadyClock::now(), vvecPtr, skContribution}).first;
}

memberIndexesRet.emplace_back(i);
Expand Down Expand Up @@ -358,7 +358,7 @@ bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType,
void CDKGSessionManager::CleanupCache() const
{
LOCK(contributionsCacheCs);
auto curTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now());
const auto curTime = SteadyClock::now();
for (auto it = contributionsCache.begin(); it != contributionsCache.end(); ) {
if (curTime - it->second.entryTime > MAX_CONTRIBUTION_CACHE_TIME) {
it = contributionsCache.erase(it);
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/dkgsessionmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

private:
CDeterministicMNManager& m_dmnman;
Expand All @@ -84,7 +84,7 @@ class CDKGSessionManager
}
};
struct ContributionsCacheEntry {
int64_t entryTime;
SteadyClock::time_point entryTime;
BLSVerificationVectorPtr vvec;
CBLSSecretKey skContribution;
};
Expand Down
18 changes: 9 additions & 9 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Default-constructed time_point used as sentinel

The == SteadyClock::time_point{} check preserves the prior == 0 sentinel semantics and is correct in practice (a running process's SteadyClock::now() is never the epoch). It is slightly less self-documenting than std::optional<SteadyClock::time_point> or a named kUnset constant. Low priority — a short comment at the declaration site would be enough to document the idiom.

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};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{}};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: std::atomicSteadyClock::time_point lock-freedom is not asserted

std::atomic<SteadyClock::time_point> is well-formed and will be lock-free on all 64-bit targets Dash ships (same width as the previous atomic<int64_t>). On platforms where steady_clock::duration::rep is wider than the largest lock-free integer, libstdc++/libc++ fall back to an internal spinlock — a silent regression from the previous atomic<int64_t>. All official Dash builds are 64-bit so this is not a real concern today; a defensive static_assert(std::atomic<SteadyClock::time_point>::is_always_lock_free) would catch any future regression.

source: ['claude']

std::atomic_bool fSocketShutdown{false};
std::atomic_bool fOtherSideDisconnected { false };
// If 'true' this node will be disconnected on CMasternodeMan::ProcessMasternodeConnections()
Expand Down
Loading