@@ -61,8 +61,8 @@ static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
6161static constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60 ; // 10 minutes
6262/* * How frequently to check for extra outbound peers and disconnect, in seconds */
6363static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45 ;
64- /* * Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
65- static constexpr int64_t MINIMUM_CONNECT_TIME = 30 ;
64+ /* * Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict */
65+ static constexpr std::chrono::seconds MINIMUM_CONNECT_TIME{ 30 } ;
6666/* * SHA256("main address relay")[0:8] */
6767static constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL ;
6868// / Age after which a stale block will no longer be served if requested as
@@ -330,7 +330,7 @@ class PeerManagerImpl final : public PeerManager
330330 void ConsiderEviction (CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
331331
332332 /* * If we have extra outbound peers, try to disconnect the one with the oldest block announcement */
333- void EvictExtraOutboundPeers (int64_t time_in_seconds ) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
333+ void EvictExtraOutboundPeers (std::chrono::seconds now ) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
334334
335335 /* * Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */
336336 void ReattemptInitialBroadcast (CScheduler& scheduler);
@@ -2511,7 +2511,7 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlo
25112511 bool new_block{false };
25122512 m_chainman.ProcessNewBlock (m_chainparams, block, force_processing, &new_block);
25132513 if (new_block) {
2514- node.nLastBlockTime = GetTime ();
2514+ node.m_last_block_time = GetTime<std::chrono::seconds> ();
25152515 } else {
25162516 LOCK (cs_main);
25172517 mapBlockSource.erase (block->GetHash ());
@@ -3314,7 +3314,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
33143314 _RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
33153315 m_orphanage.AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
33163316
3317- pfrom.nLastTXTime = GetTime ();
3317+ pfrom.m_last_tx_time = GetTime<std::chrono::seconds> ();
33183318
33193319 LogPrint (BCLog::MEMPOOL, " AcceptToMemoryPool: peer=%d: accepted %s (poolsz %u txn, %u kB)\n " ,
33203320 pfrom.GetId (),
@@ -4228,7 +4228,7 @@ void PeerManagerImpl::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
42284228 }
42294229}
42304230
4231- void PeerManagerImpl::EvictExtraOutboundPeers (int64_t time_in_seconds )
4231+ void PeerManagerImpl::EvictExtraOutboundPeers (std::chrono::seconds now )
42324232{
42334233 // If we have any extra block-relay-only peers, disconnect the youngest unless
42344234 // it's given us a block -- in which case, compare with the second-youngest, and
@@ -4237,14 +4237,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(int64_t time_in_seconds)
42374237 // to temporarily in order to sync our tip; see net.cpp.
42384238 // Note that we use higher nodeid as a measure for most recent connection.
42394239 if (m_connman.GetExtraBlockRelayCount () > 0 ) {
4240- std::pair<NodeId, int64_t > youngest_peer{-1 , 0 }, next_youngest_peer{-1 , 0 };
4240+ std::pair<NodeId, std::chrono::seconds > youngest_peer{-1 , 0 }, next_youngest_peer{-1 , 0 };
42414241
42424242 m_connman.ForEachNode ([&](CNode* pnode) {
42434243 if (!pnode->IsBlockOnlyConn () || pnode->fDisconnect ) return ;
42444244 if (pnode->GetId () > youngest_peer.first ) {
42454245 next_youngest_peer = youngest_peer;
42464246 youngest_peer.first = pnode->GetId ();
4247- youngest_peer.second = pnode->nLastBlockTime ;
4247+ youngest_peer.second = pnode->m_last_block_time ;
42484248 }
42494249 });
42504250 NodeId to_disconnect = youngest_peer.first ;
@@ -4262,13 +4262,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(int64_t time_in_seconds)
42624262 // valid headers chain with at least as much work as our tip.
42634263 CNodeState *node_state = State (pnode->GetId ());
42644264 if (node_state == nullptr ||
4265- (time_in_seconds - pnode->nTimeConnected >= MINIMUM_CONNECT_TIME && node_state->nBlocksInFlight == 0 )) {
4265+ (now - pnode->m_connected >= MINIMUM_CONNECT_TIME && node_state->nBlocksInFlight == 0 )) {
42664266 pnode->fDisconnect = true ;
4267- LogPrint (BCLog::NET, " disconnecting extra block-relay-only peer=%d (last block received at time %d)\n " , pnode->GetId (), pnode->nLastBlockTime );
4267+ LogPrint (BCLog::NET, " disconnecting extra block-relay-only peer=%d (last block received at time %d)\n " ,
4268+ pnode->GetId (), count_seconds (pnode->m_last_block_time ));
42684269 return true ;
42694270 } else {
42704271 LogPrint (BCLog::NET, " keeping block-relay-only peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n " ,
4271- pnode->GetId (), pnode->nTimeConnected , node_state->nBlocksInFlight );
4272+ pnode->GetId (), count_seconds ( pnode->m_connected ) , node_state->nBlocksInFlight );
42724273 }
42734274 return false ;
42744275 });
@@ -4308,12 +4309,13 @@ void PeerManagerImpl::EvictExtraOutboundPeers(int64_t time_in_seconds)
43084309 // Also don't disconnect any peer we're trying to download a
43094310 // block from.
43104311 CNodeState &state = *State (pnode->GetId ());
4311- if (time_in_seconds - pnode->nTimeConnected > MINIMUM_CONNECT_TIME && state.nBlocksInFlight == 0 ) {
4312+ if (now - pnode->m_connected > MINIMUM_CONNECT_TIME && state.nBlocksInFlight == 0 ) {
43124313 LogPrint (BCLog::NET, " disconnecting extra outbound peer=%d (last block announcement received at time %d)\n " , pnode->GetId (), oldest_block_announcement);
43134314 pnode->fDisconnect = true ;
43144315 return true ;
43154316 } else {
4316- LogPrint (BCLog::NET, " keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n " , pnode->GetId (), pnode->nTimeConnected , state.nBlocksInFlight );
4317+ LogPrint (BCLog::NET, " keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n " ,
4318+ pnode->GetId (), count_seconds (pnode->m_connected ), state.nBlocksInFlight );
43174319 return false ;
43184320 }
43194321 });
@@ -4335,7 +4337,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
43354337
43364338 int64_t time_in_seconds = GetTime ();
43374339
4338- EvictExtraOutboundPeers (time_in_seconds);
4340+ EvictExtraOutboundPeers (std::chrono::seconds{ time_in_seconds} );
43394341
43404342 if (time_in_seconds > m_stale_tip_check_time) {
43414343 // Check whether our tip is stale, and if so, allow using an extra
@@ -4565,7 +4567,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
45654567
45664568 const auto current_time = GetTime<std::chrono::microseconds>();
45674569
4568- if (pto->IsAddrFetchConn () && current_time - std::chrono::seconds ( pto->nTimeConnected ) > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
4570+ if (pto->IsAddrFetchConn () && current_time - pto->m_connected > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
45694571 LogPrint (BCLog::NET, " addrfetch connection timeout; disconnecting peer=%d\n " , pto->GetId ());
45704572 pto->fDisconnect = true ;
45714573 return true ;
0 commit comments