mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-24 12:05:51 +02:00
[net processing] Move nStartingHeight to Peer
This commit is contained in:
@@ -875,6 +875,7 @@ bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
|
||||
PeerRef peer = GetPeerRef(nodeid);
|
||||
if (peer == nullptr) return false;
|
||||
stats.m_misbehavior_score = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
||||
stats.nStartingHeight = peer->nStartingHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1769,7 +1770,9 @@ void PeerManager::SendBlockTransactions(CNode& pfrom, const CBlock& block, const
|
||||
m_connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
|
||||
}
|
||||
|
||||
void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHeader>& headers, bool via_compact_block)
|
||||
void PeerManager::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
|
||||
const std::vector<CBlockHeader>& headers,
|
||||
bool via_compact_block)
|
||||
{
|
||||
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
|
||||
size_t nCount = headers.size();
|
||||
@@ -1859,7 +1862,8 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHe
|
||||
// Headers message had its maximum size; the peer may have more headers.
|
||||
// TODO: optimize: if pindexLast is an ancestor of ::ChainActive().Tip or pindexBestHeader, continue
|
||||
// from there instead.
|
||||
LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom.GetId(), pfrom.nStartingHeight);
|
||||
LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n",
|
||||
pindexLast->nHeight, pfrom.GetId(), peer.nStartingHeight);
|
||||
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, ::ChainActive().GetLocator(pindexLast), uint256()));
|
||||
}
|
||||
|
||||
@@ -2365,7 +2369,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
LOCK(pfrom.cs_SubVer);
|
||||
pfrom.cleanSubVer = cleanSubVer;
|
||||
}
|
||||
pfrom.nStartingHeight = nStartingHeight;
|
||||
peer->nStartingHeight = nStartingHeight;
|
||||
|
||||
// set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients"
|
||||
pfrom.fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED));
|
||||
@@ -2445,7 +2449,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
|
||||
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n",
|
||||
cleanSubVer, pfrom.nVersion,
|
||||
pfrom.nStartingHeight, addrMe.ToString(), pfrom.GetId(),
|
||||
peer->nStartingHeight, addrMe.ToString(), pfrom.GetId(),
|
||||
remoteAddr);
|
||||
|
||||
int64_t nTimeOffset = nTime - GetTime();
|
||||
@@ -2479,7 +2483,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
|
||||
if (!pfrom.IsInboundConn()) {
|
||||
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
|
||||
pfrom.nVersion.load(), pfrom.nStartingHeight,
|
||||
pfrom.nVersion.load(), peer->nStartingHeight,
|
||||
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""),
|
||||
pfrom.ConnectionTypeAsString());
|
||||
}
|
||||
@@ -3321,7 +3325,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
// the peer if the header turns out to be for an invalid block.
|
||||
// Note that if a peer tries to build on an invalid chain, that
|
||||
// will be detected and the peer will be disconnected/discouraged.
|
||||
return ProcessHeadersMessage(pfrom, {cmpctblock.header}, /*via_compact_block=*/true);
|
||||
return ProcessHeadersMessage(pfrom, *peer, {cmpctblock.header}, /*via_compact_block=*/true);
|
||||
}
|
||||
|
||||
if (fBlockReconstructed) {
|
||||
@@ -3464,7 +3468,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
|
||||
}
|
||||
|
||||
return ProcessHeadersMessage(pfrom, headers, /*via_compact_block=*/false);
|
||||
return ProcessHeadersMessage(pfrom, *peer, headers, /*via_compact_block=*/false);
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::BLOCK)
|
||||
@@ -4072,6 +4076,7 @@ public:
|
||||
|
||||
bool PeerManager::SendMessages(CNode* pto)
|
||||
{
|
||||
PeerRef peer = GetPeerRef(pto->GetId());
|
||||
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
|
||||
|
||||
// We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
|
||||
@@ -4197,7 +4202,7 @@ bool PeerManager::SendMessages(CNode* pto)
|
||||
got back an empty response. */
|
||||
if (pindexStart->pprev)
|
||||
pindexStart = pindexStart->pprev;
|
||||
LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->GetId(), pto->nStartingHeight);
|
||||
LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->GetId(), peer->nStartingHeight);
|
||||
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, ::ChainActive().GetLocator(pindexStart), uint256()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user