v30.3-roots.1 · Commit 7: [PATCH 07/68] build: adapt Roots maintenance and assurance to Core 30.3
src/net_processing.cpp
Before: src/net_processing.cpp · After: src/net_processing.cpp
File metadata
index b1dcbf122e0ab69b292923fca2123116abe2a758..3b0c0761e10db5ea20ab123675eeee7accab4b5f 100644
Download original patch · Release notes
Diff rows 1–64 of 64. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/net_processing.cpp
CHANGED
|
@@ -1819,23 +1819,10 @@ void PeerManagerImpl::Misbehaving(Peer& peer, const std::string& message)
|
|
|
1819
1819
|
);
|
|
1820
1820
|
}
|
|
1821
1821
|
|
|
1822
|
-
static void HandleDoSPunishment(CConnman& connman, NodeId node_id, const int nDoS, const char * const what_is_it) {
|
|
1823
|
-
// We never actually DoS ban for invalid blocks, merely disconnect nodes if we're relying on them as a primary node
|
|
1824
|
-
const std::string msg = strprintf("peer=%d got DoS score %d on invalid %s", node_id, nDoS, what_is_it);
|
|
1825
|
-
connman.ForNode(node_id, [msg](CNode* node) {
|
|
1826
|
-
if (node->PunishInvalidBlocks()) {
|
|
1827
|
-
LogDebug(BCLog::NET, "%s; simply disconnecting\n", msg);
|
|
1828
|
-
node->fDisconnect = true;
|
|
1829
|
-
} else {
|
|
1830
|
-
LogDebug(BCLog::NET, "%s; tolerating\n", msg);
|
|
1831
|
-
}
|
|
1832
|
-
return true;
|
|
1833
|
-
});
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
1822
|
void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
|
1837
1823
|
bool via_compact_block, const std::string& message)
|
|
1838
1824
|
{
|
|
1825
|
+
PeerRef peer{GetPeerRef(nodeid)};
|
|
1839
1826
|
switch (state.GetResult()) {
|
|
1840
1827
|
case BlockValidationResult::BLOCK_RESULT_UNSET:
|
|
1841
1828
|
break;
|
|
@@ -1847,7 +1834,7 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
|
1847
1834
|
case BlockValidationResult::BLOCK_CONSENSUS:
|
|
1848
1835
|
case BlockValidationResult::BLOCK_MUTATED:
|
|
1849
1836
|
if (!via_compact_block) {
|
|
1850
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
|
1837
|
+
if (peer) Misbehaving(*peer, message);
|
|
1851
1838
|
return;
|
|
1852
1839
|
}
|
|
1853
1840
|
break;
|
|
@@ -1855,19 +1842,19 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
|
1855
1842
|
{
|
|
1856
1843
|
// Discourage outbound (but not inbound) peers if on an invalid chain.
|
|
1857
1844
|
// Exempt HB compact block peers. Manual connections are always protected from discouragement.
|
|
1858
|
-
if (!via_compact_block) {
|
|
1859
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
|
1845
|
+
if (peer && !via_compact_block && !peer->m_is_inbound) {
|
|
1846
|
+
Misbehaving(*peer, message);
|
|
1860
1847
|
return;
|
|
1861
1848
|
}
|
|
1862
1849
|
break;
|
|
1863
1850
|
}
|
|
1864
1851
|
case BlockValidationResult::BLOCK_INVALID_HEADER:
|
|
1865
1852
|
case BlockValidationResult::BLOCK_INVALID_PREV:
|
|
1866
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
|
1853
|
+
if (peer) Misbehaving(*peer, message);
|
|
1867
1854
|
return;
|
|
1868
1855
|
// Conflicting (but not necessarily invalid) data or different policy:
|
|
1869
1856
|
case BlockValidationResult::BLOCK_MISSING_PREV:
|
|
1870
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
|
1857
|
+
if (peer) Misbehaving(*peer, message);
|
|
1871
1858
|
return;
|
|
1872
1859
|
case BlockValidationResult::BLOCK_TIME_FUTURE:
|
|
1873
1860
|
break;
|
|
@@ -2591,9 +2578,6 @@ void PeerManagerImpl::HandleUnconnectingHeaders(CNode& pfrom, Peer& peer,
|
|
|
2591
2578
|
// we can use this peer to download.
|
|
2592
2579
|
WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
|
|
2593
2580
|
|
|
2594
|
-
if (pfrom.PunishInvalidBlocks()) {
|
|
2595
|
-
pfrom.fDisconnect = true;
|
|
2596
|
-
}
|
|
2597
2581
|
}
|
|
2598
2582
|
|
|
2599
2583
|
bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const
|