@@ -61,8 +61,8 @@ static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
61
61
static constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60 ; // 10 minutes
62
62
/* * How frequently to check for extra outbound peers and disconnect, in seconds */
63
63
static 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 } ;
66
66
/* * SHA256("main address relay")[0:8] */
67
67
static constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL ;
68
68
// / Age after which a stale block will no longer be served if requested as
@@ -330,7 +330,7 @@ class PeerManagerImpl final : public PeerManager
330
330
void ConsiderEviction (CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
331
331
332
332
/* * 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);
334
334
335
335
/* * Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */
336
336
void ReattemptInitialBroadcast (CScheduler& scheduler);
@@ -2511,7 +2511,7 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlo
2511
2511
bool new_block{false };
2512
2512
m_chainman.ProcessNewBlock (m_chainparams, block, force_processing, &new_block);
2513
2513
if (new_block) {
2514
- node.nLastBlockTime = GetTime ();
2514
+ node.m_last_block_time = GetTime<std::chrono::seconds> ();
2515
2515
} else {
2516
2516
LOCK (cs_main);
2517
2517
mapBlockSource.erase (block->GetHash ());
@@ -3314,7 +3314,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3314
3314
_RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
3315
3315
m_orphanage.AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
3316
3316
3317
- pfrom.nLastTXTime = GetTime ();
3317
+ pfrom.m_last_tx_time = GetTime<std::chrono::seconds> ();
3318
3318
3319
3319
LogPrint (BCLog::MEMPOOL, " AcceptToMemoryPool: peer=%d: accepted %s (poolsz %u txn, %u kB)\n " ,
3320
3320
pfrom.GetId (),
@@ -4228,7 +4228,7 @@ void PeerManagerImpl::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
4228
4228
}
4229
4229
}
4230
4230
4231
- void PeerManagerImpl::EvictExtraOutboundPeers (int64_t time_in_seconds )
4231
+ void PeerManagerImpl::EvictExtraOutboundPeers (std::chrono::seconds now )
4232
4232
{
4233
4233
// If we have any extra block-relay-only peers, disconnect the youngest unless
4234
4234
// 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)
4237
4237
// to temporarily in order to sync our tip; see net.cpp.
4238
4238
// Note that we use higher nodeid as a measure for most recent connection.
4239
4239
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 };
4241
4241
4242
4242
m_connman.ForEachNode ([&](CNode* pnode) {
4243
4243
if (!pnode->IsBlockOnlyConn () || pnode->fDisconnect ) return ;
4244
4244
if (pnode->GetId () > youngest_peer.first ) {
4245
4245
next_youngest_peer = youngest_peer;
4246
4246
youngest_peer.first = pnode->GetId ();
4247
- youngest_peer.second = pnode->nLastBlockTime ;
4247
+ youngest_peer.second = pnode->m_last_block_time ;
4248
4248
}
4249
4249
});
4250
4250
NodeId to_disconnect = youngest_peer.first ;
@@ -4262,13 +4262,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(int64_t time_in_seconds)
4262
4262
// valid headers chain with at least as much work as our tip.
4263
4263
CNodeState *node_state = State (pnode->GetId ());
4264
4264
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 )) {
4266
4266
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 ));
4268
4269
return true ;
4269
4270
} else {
4270
4271
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 );
4272
4273
}
4273
4274
return false ;
4274
4275
});
@@ -4308,12 +4309,13 @@ void PeerManagerImpl::EvictExtraOutboundPeers(int64_t time_in_seconds)
4308
4309
// Also don't disconnect any peer we're trying to download a
4309
4310
// block from.
4310
4311
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 ) {
4312
4313
LogPrint (BCLog::NET, " disconnecting extra outbound peer=%d (last block announcement received at time %d)\n " , pnode->GetId (), oldest_block_announcement);
4313
4314
pnode->fDisconnect = true ;
4314
4315
return true ;
4315
4316
} 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 );
4317
4319
return false ;
4318
4320
}
4319
4321
});
@@ -4335,7 +4337,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
4335
4337
4336
4338
int64_t time_in_seconds = GetTime ();
4337
4339
4338
- EvictExtraOutboundPeers (time_in_seconds);
4340
+ EvictExtraOutboundPeers (std::chrono::seconds{ time_in_seconds} );
4339
4341
4340
4342
if (time_in_seconds > m_stale_tip_check_time) {
4341
4343
// Check whether our tip is stale, and if so, allow using an extra
@@ -4565,7 +4567,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4565
4567
4566
4568
const auto current_time = GetTime<std::chrono::microseconds>();
4567
4569
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) {
4569
4571
LogPrint (BCLog::NET, " addrfetch connection timeout; disconnecting peer=%d\n " , pto->GetId ());
4570
4572
pto->fDisconnect = true ;
4571
4573
return true ;
0 commit comments