mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#23801: Change time variable type from int64_t to std::chrono::seconds in net_processing.cpp
This commit is contained in:
parent
6e6c9442fa
commit
182e31d04c
@ -34,6 +34,8 @@
|
|||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -101,10 +103,10 @@ static constexpr auto HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1ms;
|
|||||||
static constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4;
|
static constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4;
|
||||||
/** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */
|
/** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */
|
||||||
static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
|
static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
|
||||||
/** How frequently to check for stale tips, in seconds */
|
/** How frequently to check for stale tips */
|
||||||
static constexpr int64_t STALE_CHECK_INTERVAL = 2.5 * 60; // 2.5 minutes (~block interval)
|
static constexpr auto STALE_CHECK_INTERVAL{150s}; // 2.5 minutes (~block interval)
|
||||||
/** How frequently to check for extra outbound peers and disconnect, in seconds */
|
/** How frequently to check for extra outbound peers and disconnect */
|
||||||
static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
|
static constexpr auto EXTRA_PEER_CHECK_INTERVAL{45s};
|
||||||
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict */
|
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict */
|
||||||
static constexpr std::chrono::seconds MINIMUM_CONNECT_TIME{30};
|
static constexpr std::chrono::seconds MINIMUM_CONNECT_TIME{30};
|
||||||
/** SHA256("main address relay")[0:8] */
|
/** SHA256("main address relay")[0:8] */
|
||||||
@ -517,7 +519,7 @@ private:
|
|||||||
std::atomic<int> m_best_height{-1};
|
std::atomic<int> m_best_height{-1};
|
||||||
|
|
||||||
/** Next time to check for stale tip */
|
/** Next time to check for stale tip */
|
||||||
int64_t m_stale_tip_check_time{0};
|
std::chrono::seconds m_stale_tip_check_time{0s};
|
||||||
|
|
||||||
/** Whether this node is running in blocks only mode */
|
/** Whether this node is running in blocks only mode */
|
||||||
const bool m_ignore_incoming_txs;
|
const bool m_ignore_incoming_txs;
|
||||||
@ -685,7 +687,7 @@ private:
|
|||||||
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight GUARDED_BY(cs_main);
|
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight GUARDED_BY(cs_main);
|
||||||
|
|
||||||
/** When our tip was last updated. */
|
/** When our tip was last updated. */
|
||||||
std::atomic<int64_t> m_last_tip_update{0};
|
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
|
||||||
|
|
||||||
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
|
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
|
||||||
CTransactionRef FindTxForGetData(const CNode* peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main);
|
CTransactionRef FindTxForGetData(const CNode* peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main);
|
||||||
@ -1108,10 +1110,10 @@ bool PeerManagerImpl::TipMayBeStale()
|
|||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
|
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
|
||||||
if (m_last_tip_update == 0) {
|
if (count_seconds(m_last_tip_update) == 0) {
|
||||||
m_last_tip_update = GetTime();
|
m_last_tip_update = GetTime<std::chrono::seconds>();
|
||||||
}
|
}
|
||||||
return m_last_tip_update < GetTime() - consensusParams.nPowTargetSpacing * 3 && mapBlocksInFlight.empty();
|
return count_seconds(m_last_tip_update) < GetTime() - consensusParams.nPowTargetSpacing * 3 && mapBlocksInFlight.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerManagerImpl::CanDirectFetch()
|
bool PeerManagerImpl::CanDirectFetch()
|
||||||
@ -1956,7 +1958,7 @@ void PeerManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock
|
|||||||
ProcessOrphanTx(orphanWorkSet);
|
ProcessOrphanTx(orphanWorkSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_last_tip_update = GetTime();
|
m_last_tip_update = GetTime<std::chrono::seconds>();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
LOCK(m_recent_confirmed_transactions_mutex);
|
LOCK(m_recent_confirmed_transactions_mutex);
|
||||||
@ -5196,20 +5198,20 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
int64_t time_in_seconds = GetTime();
|
auto now{GetTime<std::chrono::seconds>()};
|
||||||
|
|
||||||
EvictExtraOutboundPeers(std::chrono::seconds{time_in_seconds});
|
EvictExtraOutboundPeers(now);
|
||||||
|
|
||||||
if (time_in_seconds > m_stale_tip_check_time) {
|
if (now > m_stale_tip_check_time) {
|
||||||
// Check whether our tip is stale, and if so, allow using an extra
|
// Check whether our tip is stale, and if so, allow using an extra
|
||||||
// outbound peer
|
// outbound peer
|
||||||
if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
|
if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
|
||||||
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - m_last_tip_update);
|
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", count_seconds(now) - count_seconds(m_last_tip_update));
|
||||||
m_connman.SetTryNewOutboundPeer(true);
|
m_connman.SetTryNewOutboundPeer(true);
|
||||||
} else if (m_connman.GetTryNewOutboundPeer()) {
|
} else if (m_connman.GetTryNewOutboundPeer()) {
|
||||||
m_connman.SetTryNewOutboundPeer(false);
|
m_connman.SetTryNewOutboundPeer(false);
|
||||||
}
|
}
|
||||||
m_stale_tip_check_time = time_in_seconds + STALE_CHECK_INTERVAL;
|
m_stale_tip_check_time = now + STALE_CHECK_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_initial_sync_finished && CanDirectFetch()) {
|
if (!m_initial_sync_finished && CanDirectFetch()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user