v29.4-roots.4 · Commit 7: [PATCH 07/37] release: establish Roots maintenance and assurance
src/net_processing.cpp
Before: src/net_processing.cpp · After: src/net_processing.cpp
File metadata
index de81fb24b3225c9422fbf56db9516c5669ca1f14..a3b63b10bd5815bac85fd80aa9bf76ddf029d88f 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
|
@@ -1788,23 +1788,10 @@ void PeerManagerImpl::Misbehaving(Peer& peer, const std::string& message)
|
|
|
1788
1788
|
);
|
|
1789
1789
|
}
|
|
1790
1790
|
|
|
1791
|
-
static void HandleDoSPunishment(CConnman& connman, NodeId node_id, const int nDoS, const char * const what_is_it) {
|
|
1792
|
-
// We never actually DoS ban for invalid blocks, merely disconnect nodes if we're relying on them as a primary node
|
|
1793
|
-
const std::string msg = strprintf("peer=%d got DoS score %d on invalid %s", node_id, nDoS, what_is_it);
|
|
1794
|
-
connman.ForNode(node_id, [msg](CNode* node) {
|
|
1795
|
-
if (node->PunishInvalidBlocks()) {
|
|
1796
|
-
LogDebug(BCLog::NET, "%s; simply disconnecting\n", msg);
|
|
1797
|
-
node->fDisconnect = true;
|
|
1798
|
-
} else {
|
|
1799
|
-
LogDebug(BCLog::NET, "%s; tolerating\n", msg);
|
|
1800
|
-
}
|
|
1801
|
-
return true;
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
1791
|
void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
|
1806
1792
|
bool via_compact_block, const std::string& message)
|
|
1807
1793
|
{
|
|
1794
|
+
PeerRef peer{GetPeerRef(nodeid)};
|
|
1808
1795
|
switch (state.GetResult()) {
|
|
1809
1796
|
case BlockValidationResult::BLOCK_RESULT_UNSET:
|
|
1810
1797
|
break;
|
|
@@ -1816,7 +1803,7 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
|
1816
1803
|
case BlockValidationResult::BLOCK_CONSENSUS:
|
|
1817
1804
|
case BlockValidationResult::BLOCK_MUTATED:
|
|
1818
1805
|
if (!via_compact_block) {
|
|
1819
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
|
1806
|
+
if (peer) Misbehaving(*peer, message);
|
|
1820
1807
|
return;
|
|
1821
1808
|
}
|
|
1822
1809
|
break;
|
|
@@ -1824,8 +1811,8 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
|
1824
1811
|
{
|
|
1825
1812
|
// Discourage outbound (but not inbound) peers if on an invalid chain.
|
|
1826
1813
|
// Exempt HB compact block peers. Manual connections are always protected from discouragement.
|
|
1827
|
-
if (!via_compact_block) {
|
|
1828
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
|
1814
|
+
if (peer && !via_compact_block && !peer->m_is_inbound) {
|
|
1815
|
+
Misbehaving(*peer, message);
|
|
1829
1816
|
return;
|
|
1830
1817
|
}
|
|
1831
1818
|
break;
|
|
@@ -1833,11 +1820,11 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
|
1833
1820
|
case BlockValidationResult::BLOCK_INVALID_HEADER:
|
|
1834
1821
|
case BlockValidationResult::BLOCK_CHECKPOINT:
|
|
1835
1822
|
case BlockValidationResult::BLOCK_INVALID_PREV:
|
|
1836
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
|
1823
|
+
if (peer) Misbehaving(*peer, message);
|
|
1837
1824
|
return;
|
|
1838
1825
|
// Conflicting (but not necessarily invalid) data or different policy:
|
|
1839
1826
|
case BlockValidationResult::BLOCK_MISSING_PREV:
|
|
1840
|
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
|
1827
|
+
if (peer) Misbehaving(*peer, message);
|
|
1841
1828
|
return;
|
|
1842
1829
|
case BlockValidationResult::BLOCK_TIME_FUTURE:
|
|
1843
1830
|
break;
|
|
@@ -2553,9 +2540,6 @@ void PeerManagerImpl::HandleUnconnectingHeaders(CNode& pfrom, Peer& peer,
|
|
|
2553
2540
|
// we can use this peer to download.
|
|
2554
2541
|
WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
|
|
2555
2542
|
|
|
2556
|
-
if (pfrom.PunishInvalidBlocks()) {
|
|
2557
|
-
pfrom.fDisconnect = true;
|
|
2558
|
-
}
|
|
2559
2543
|
}
|
|
2560
2544
|
|
|
2561
2545
|
bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const
|