[net processing] Move nStartingHeight to Peer
This commit is contained in:
1 parent
717a374e74
commit
77a2c2f8f9
6 files changed
+24
-14
No files matched your search
@@ -590,7 +590,6 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
|
|||||||
stats.m_manual_connection = IsManualConn();
|
stats.m_manual_connection = IsManualConn();
|
||||||
X(m_bip152_highbandwidth_to);
|
X(m_bip152_highbandwidth_to);
|
||||||
X(m_bip152_highbandwidth_from);
|
X(m_bip152_highbandwidth_from);
|
||||||
X(nStartingHeight);
|
|
||||||
{
|
{
|
||||||
LOCK(cs_vSend);
|
LOCK(cs_vSend);
|
||||||
X(mapSendBytesPerMsgCmd);
|
X(mapSendBytesPerMsgCmd);
|
||||||
|
|||||||
@@ -994,7 +994,6 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
uint256 hashContinue;
|
uint256 hashContinue;
|
||||||
std::atomic<int> nStartingHeight{-1};
|
|
||||||
// We selected peer as (compact blocks) high-bandwidth peer (BIP152)
|
// We selected peer as (compact blocks) high-bandwidth peer (BIP152)
|
||||||
std::atomic<bool> m_bip152_highbandwidth_to{false};
|
std::atomic<bool> m_bip152_highbandwidth_to{false};
|
||||||
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
|
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
|
||||||
|
|||||||
+13
-8
@@ -875,6 +875,7 @@ bool PeerManager::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
|
|||||||
PeerRef peer = GetPeerRef(nodeid);
|
PeerRef peer = GetPeerRef(nodeid);
|
||||||
if (peer == nullptr) return false;
|
if (peer == nullptr) return false;
|
||||||
stats.m_misbehavior_score = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
stats.m_misbehavior_score = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
||||||
|
stats.nStartingHeight = peer->nStartingHeight;
|
||||||
|
|
||||||
return true;
|
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));
|
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());
|
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
|
||||||
size_t nCount = headers.size();
|
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.
|
// 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
|
// TODO: optimize: if pindexLast is an ancestor of ::ChainActive().Tip or pindexBestHeader, continue
|
||||||
// from there instead.
|
// 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()));
|
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);
|
LOCK(pfrom.cs_SubVer);
|
||||||
pfrom.cleanSubVer = cleanSubVer;
|
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"
|
// 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));
|
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",
|
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n",
|
||||||
cleanSubVer, pfrom.nVersion,
|
cleanSubVer, pfrom.nVersion,
|
||||||
pfrom.nStartingHeight, addrMe.ToString(), pfrom.GetId(),
|
peer->nStartingHeight, addrMe.ToString(), pfrom.GetId(),
|
||||||
remoteAddr);
|
remoteAddr);
|
||||||
|
|
||||||
int64_t nTimeOffset = nTime - GetTime();
|
int64_t nTimeOffset = nTime - GetTime();
|
||||||
@@ -2479,7 +2483,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
|||||||
|
|
||||||
if (!pfrom.IsInboundConn()) {
|
if (!pfrom.IsInboundConn()) {
|
||||||
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
|
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.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""),
|
||||||
pfrom.ConnectionTypeAsString());
|
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.
|
// 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
|
// Note that if a peer tries to build on an invalid chain, that
|
||||||
// will be detected and the peer will be disconnected/discouraged.
|
// 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) {
|
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.
|
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)
|
if (msg_type == NetMsgType::BLOCK)
|
||||||
@@ -4072,6 +4076,7 @@ public:
|
|||||||
|
|
||||||
bool PeerManager::SendMessages(CNode* pto)
|
bool PeerManager::SendMessages(CNode* pto)
|
||||||
{
|
{
|
||||||
|
PeerRef peer = GetPeerRef(pto->GetId());
|
||||||
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
|
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
|
||||||
|
|
||||||
// We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
|
// We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
|
||||||
@@ -4197,7 +4202,7 @@ bool PeerManager::SendMessages(CNode* pto)
|
|||||||
got back an empty response. */
|
got back an empty response. */
|
||||||
if (pindexStart->pprev)
|
if (pindexStart->pprev)
|
||||||
pindexStart = 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()));
|
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, ::ChainActive().GetLocator(pindexStart), uint256()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct CNodeStateStats {
|
|||||||
int m_misbehavior_score = 0;
|
int m_misbehavior_score = 0;
|
||||||
int nSyncHeight = -1;
|
int nSyncHeight = -1;
|
||||||
int nCommonHeight = -1;
|
int nCommonHeight = -1;
|
||||||
|
int nStartingHeight = -1;
|
||||||
std::vector<int> vHeightInFlight;
|
std::vector<int> vHeightInFlight;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +63,9 @@ struct Peer {
|
|||||||
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
|
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
|
||||||
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
|
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
|
||||||
|
|
||||||
|
/** This peer's reported block height when we connected */
|
||||||
|
std::atomic<int> nStartingHeight{-1};
|
||||||
|
|
||||||
/** Set of txids to reconsider once their parent transactions have been accepted **/
|
/** Set of txids to reconsider once their parent transactions have been accepted **/
|
||||||
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
|
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
|
||||||
|
|
||||||
@@ -182,7 +186,9 @@ private:
|
|||||||
|
|
||||||
void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans);
|
void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans);
|
||||||
/** Process a single headers message from a peer. */
|
/** Process a single headers message from a peer. */
|
||||||
void ProcessHeadersMessage(CNode& pfrom, const std::vector<CBlockHeader>& headers, bool via_compact_block);
|
void ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
|
||||||
|
const std::vector<CBlockHeader>& headers,
|
||||||
|
bool via_compact_block);
|
||||||
|
|
||||||
void SendBlockTransactions(CNode& pfrom, const CBlock& block, const BlockTransactionsRequest& req);
|
void SendBlockTransactions(CNode& pfrom, const CBlock& block, const BlockTransactionsRequest& req);
|
||||||
|
|
||||||
|
|||||||
@@ -1109,7 +1109,6 @@ void RPCConsole::updateDetailWidget()
|
|||||||
ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
|
ui->peerVersion->setText(QString::number(stats->nodeStats.nVersion));
|
||||||
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
|
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
|
||||||
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
|
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
|
||||||
ui->peerHeight->setText(QString::number(stats->nodeStats.nStartingHeight));
|
|
||||||
if (stats->nodeStats.m_permissionFlags == PF_NONE) {
|
if (stats->nodeStats.m_permissionFlags == PF_NONE) {
|
||||||
ui->peerPermissions->setText(tr("N/A"));
|
ui->peerPermissions->setText(tr("N/A"));
|
||||||
} else {
|
} else {
|
||||||
@@ -1135,6 +1134,8 @@ void RPCConsole::updateDetailWidget()
|
|||||||
ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
|
ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
|
||||||
else
|
else
|
||||||
ui->peerCommonHeight->setText(tr("Unknown"));
|
ui->peerCommonHeight->setText(tr("Unknown"));
|
||||||
|
|
||||||
|
ui->peerHeight->setText(QString::number(stats->nodeStateStats.nStartingHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->detailWidget->show();
|
ui->detailWidget->show();
|
||||||
|
|||||||
+2
-2
@@ -133,8 +133,8 @@ static RPCHelpMan getpeerinfo()
|
|||||||
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
|
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"
|
||||||
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
|
"Please note this output is unlikely to be stable in upcoming releases as we iterate to\n"
|
||||||
"best capture connection behaviors."},
|
"best capture connection behaviors."},
|
||||||
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
|
|
||||||
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
|
{RPCResult::Type::NUM, "banscore", "The ban score (DEPRECATED, returned only if config option -deprecatedrpc=banscore is passed)"},
|
||||||
|
{RPCResult::Type::NUM, "startingheight", "The starting height (block) of the peer"},
|
||||||
{RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
|
{RPCResult::Type::NUM, "synced_headers", "The last header we have in common with this peer"},
|
||||||
{RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
|
{RPCResult::Type::NUM, "synced_blocks", "The last block we have in common with this peer"},
|
||||||
{RPCResult::Type::ARR, "inflight", "",
|
{RPCResult::Type::ARR, "inflight", "",
|
||||||
@@ -224,12 +224,12 @@ static RPCHelpMan getpeerinfo()
|
|||||||
// addnode is deprecated in v0.21 for removal in v0.22
|
// addnode is deprecated in v0.21 for removal in v0.22
|
||||||
obj.pushKV("addnode", stats.m_manual_connection);
|
obj.pushKV("addnode", stats.m_manual_connection);
|
||||||
}
|
}
|
||||||
obj.pushKV("startingheight", stats.nStartingHeight);
|
|
||||||
if (fStateStats) {
|
if (fStateStats) {
|
||||||
if (IsDeprecatedRPCEnabled("banscore")) {
|
if (IsDeprecatedRPCEnabled("banscore")) {
|
||||||
// banscore is deprecated in v0.21 for removal in v0.22
|
// banscore is deprecated in v0.21 for removal in v0.22
|
||||||
obj.pushKV("banscore", statestats.m_misbehavior_score);
|
obj.pushKV("banscore", statestats.m_misbehavior_score);
|
||||||
}
|
}
|
||||||
|
obj.pushKV("startingheight", statestats.nStartingHeight);
|
||||||
obj.pushKV("synced_headers", statestats.nSyncHeight);
|
obj.pushKV("synced_headers", statestats.nSyncHeight);
|
||||||
obj.pushKV("synced_blocks", statestats.nCommonHeight);
|
obj.pushKV("synced_blocks", statestats.nCommonHeight);
|
||||||
UniValue heights(UniValue::VARR);
|
UniValue heights(UniValue::VARR);
|
||||||
|
|||||||
Reference in new issue
Block a user