@@ -875,6 +875,7 @@ bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
875
875
PeerRef peer = GetPeerRef (nodeid);
876
876
if (peer == nullptr ) return false ;
877
877
stats.m_misbehavior_score = WITH_LOCK (peer->m_misbehavior_mutex , return peer->m_misbehavior_score );
878
+ stats.nStartingHeight = peer->nStartingHeight ;
878
879
879
880
return true ;
880
881
}
@@ -1769,7 +1770,9 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
1769
1770
m_connman.PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
1770
1771
}
1771
1772
1772
- void PeerManager::ProcessHeadersMessage (CNode& pfrom, const std::vector<CBlockHeader>& headers, bool via_compact_block)
1773
+ void PeerManager::ProcessHeadersMessage (CNode& pfrom, const Peer& peer,
1774
+ const std::vector<CBlockHeader>& headers,
1775
+ bool via_compact_block)
1773
1776
{
1774
1777
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1775
1778
size_t nCount = headers.size ();
@@ -1859,7 +1862,8 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHe
1859
1862
// Headers message had its maximum size; the peer may have more headers.
1860
1863
// TODO: optimize: if pindexLast is an ancestor of ::ChainActive().Tip or pindexBestHeader, continue
1861
1864
// from there instead.
1862
- LogPrint (BCLog::NET, " more getheaders (%d) to end to peer=%d (startheight:%d)\n " , pindexLast->nHeight , pfrom.GetId (), pfrom.nStartingHeight );
1865
+ LogPrint (BCLog::NET, " more getheaders (%d) to end to peer=%d (startheight:%d)\n " ,
1866
+ pindexLast->nHeight , pfrom.GetId (), peer.nStartingHeight );
1863
1867
m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexLast), uint256 ()));
1864
1868
}
1865
1869
@@ -2365,7 +2369,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2365
2369
LOCK (pfrom.cs_SubVer );
2366
2370
pfrom.cleanSubVer = cleanSubVer;
2367
2371
}
2368
- pfrom. nStartingHeight = nStartingHeight;
2372
+ peer-> nStartingHeight = nStartingHeight;
2369
2373
2370
2374
// set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients"
2371
2375
pfrom.fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED));
@@ -2445,7 +2449,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2445
2449
2446
2450
LogPrint (BCLog::NET, " receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n " ,
2447
2451
cleanSubVer, pfrom.nVersion ,
2448
- pfrom. nStartingHeight , addrMe.ToString (), pfrom.GetId (),
2452
+ peer-> nStartingHeight , addrMe.ToString (), pfrom.GetId (),
2449
2453
remoteAddr);
2450
2454
2451
2455
int64_t nTimeOffset = nTime - GetTime ();
@@ -2479,7 +2483,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2479
2483
2480
2484
if (!pfrom.IsInboundConn ()) {
2481
2485
LogPrintf (" New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n " ,
2482
- pfrom.nVersion .load (), pfrom. nStartingHeight ,
2486
+ pfrom.nVersion .load (), peer-> nStartingHeight ,
2483
2487
pfrom.GetId (), (fLogIPs ? strprintf (" , peeraddr=%s" , pfrom.addr .ToString ()) : " " ),
2484
2488
pfrom.ConnectionTypeAsString ());
2485
2489
}
@@ -3321,7 +3325,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
3321
3325
// the peer if the header turns out to be for an invalid block.
3322
3326
// Note that if a peer tries to build on an invalid chain, that
3323
3327
// will be detected and the peer will be disconnected/discouraged.
3324
- return ProcessHeadersMessage (pfrom, {cmpctblock.header }, /* via_compact_block=*/ true );
3328
+ return ProcessHeadersMessage (pfrom, *peer, {cmpctblock.header }, /* via_compact_block=*/ true );
3325
3329
}
3326
3330
3327
3331
if (fBlockReconstructed ) {
@@ -3464,7 +3468,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
3464
3468
ReadCompactSize (vRecv); // ignore tx count; assume it is 0.
3465
3469
}
3466
3470
3467
- return ProcessHeadersMessage (pfrom, headers, /* via_compact_block=*/ false );
3471
+ return ProcessHeadersMessage (pfrom, *peer, headers, /* via_compact_block=*/ false );
3468
3472
}
3469
3473
3470
3474
if (msg_type == NetMsgType::BLOCK)
@@ -4072,6 +4076,7 @@ class CompareInvMempoolOrder
4072
4076
4073
4077
bool PeerManager::SendMessages (CNode* pto)
4074
4078
{
4079
+ PeerRef peer = GetPeerRef (pto->GetId ());
4075
4080
const Consensus::Params& consensusParams = m_chainparams.GetConsensus ();
4076
4081
4077
4082
// We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
@@ -4197,7 +4202,7 @@ bool PeerManager::SendMessages(CNode* pto)
4197
4202
got back an empty response. */
4198
4203
if (pindexStart->pprev )
4199
4204
pindexStart = pindexStart->pprev ;
4200
- LogPrint (BCLog::NET, " initial getheaders (%d) to peer=%d (startheight:%d)\n " , pindexStart->nHeight , pto->GetId (), pto ->nStartingHeight );
4205
+ LogPrint (BCLog::NET, " initial getheaders (%d) to peer=%d (startheight:%d)\n " , pindexStart->nHeight , pto->GetId (), peer ->nStartingHeight );
4201
4206
m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexStart), uint256 ()));
4202
4207
}
4203
4208
}
0 commit comments