@@ -875,6 +875,7 @@ bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
875875 PeerRef peer = GetPeerRef (nodeid);
876876 if (peer == nullptr ) return false ;
877877 stats.m_misbehavior_score = WITH_LOCK (peer->m_misbehavior_mutex , return peer->m_misbehavior_score );
878+ stats.nStartingHeight = peer->nStartingHeight ;
878879
879880 return true ;
880881}
@@ -1769,7 +1770,9 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
17691770 m_connman.PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
17701771}
17711772
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)
17731776{
17741777 const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
17751778 size_t nCount = headers.size ();
@@ -1859,7 +1862,8 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHe
18591862 // Headers message had its maximum size; the peer may have more headers.
18601863 // TODO: optimize: if pindexLast is an ancestor of ::ChainActive().Tip or pindexBestHeader, continue
18611864 // 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 );
18631867 m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexLast), uint256 ()));
18641868 }
18651869
@@ -2365,7 +2369,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
23652369 LOCK (pfrom.cs_SubVer );
23662370 pfrom.cleanSubVer = cleanSubVer;
23672371 }
2368- pfrom. nStartingHeight = nStartingHeight;
2372+ peer-> nStartingHeight = nStartingHeight;
23692373
23702374 // set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients"
23712375 pfrom.fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED));
@@ -2445,7 +2449,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24452449
24462450 LogPrint (BCLog::NET, " receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n " ,
24472451 cleanSubVer, pfrom.nVersion ,
2448- pfrom. nStartingHeight , addrMe.ToString (), pfrom.GetId (),
2452+ peer-> nStartingHeight , addrMe.ToString (), pfrom.GetId (),
24492453 remoteAddr);
24502454
24512455 int64_t nTimeOffset = nTime - GetTime ();
@@ -2479,7 +2483,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
24792483
24802484 if (!pfrom.IsInboundConn ()) {
24812485 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 ,
24832487 pfrom.GetId (), (fLogIPs ? strprintf (" , peeraddr=%s" , pfrom.addr .ToString ()) : " " ),
24842488 pfrom.ConnectionTypeAsString ());
24852489 }
@@ -3321,7 +3325,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
33213325 // the peer if the header turns out to be for an invalid block.
33223326 // Note that if a peer tries to build on an invalid chain, that
33233327 // 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 );
33253329 }
33263330
33273331 if (fBlockReconstructed ) {
@@ -3464,7 +3468,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
34643468 ReadCompactSize (vRecv); // ignore tx count; assume it is 0.
34653469 }
34663470
3467- return ProcessHeadersMessage (pfrom, headers, /* via_compact_block=*/ false );
3471+ return ProcessHeadersMessage (pfrom, *peer, headers, /* via_compact_block=*/ false );
34683472 }
34693473
34703474 if (msg_type == NetMsgType::BLOCK)
@@ -4072,6 +4076,7 @@ class CompareInvMempoolOrder
40724076
40734077bool PeerManager::SendMessages (CNode* pto)
40744078{
4079+ PeerRef peer = GetPeerRef (pto->GetId ());
40754080 const Consensus::Params& consensusParams = m_chainparams.GetConsensus ();
40764081
40774082 // We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
@@ -4197,7 +4202,7 @@ bool PeerManager::SendMessages(CNode* pto)
41974202 got back an empty response. */
41984203 if (pindexStart->pprev )
41994204 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 );
42014206 m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexStart), uint256 ()));
42024207 }
42034208 }
0 commit comments