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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/net_processing.cpp
CHANGED
|
@@ -1788,23 +1788,10 @@ void PeerManagerImpl::Misbehaving(Peer& peer, const std::string& message)
|
|
| 1788 |
);
|
| 1789 |
}
|
| 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 |
void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
| 1806 |
bool via_compact_block, const std::string& message)
|
| 1807 |
{
|
|
|
|
| 1808 |
switch (state.GetResult()) {
|
| 1809 |
case BlockValidationResult::BLOCK_RESULT_UNSET:
|
| 1810 |
break;
|
|
@@ -1816,7 +1803,7 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
| 1816 |
case BlockValidationResult::BLOCK_CONSENSUS:
|
| 1817 |
case BlockValidationResult::BLOCK_MUTATED:
|
| 1818 |
if (!via_compact_block) {
|
| 1819 |
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
| 1820 |
return;
|
| 1821 |
}
|
| 1822 |
break;
|
|
@@ -1824,8 +1811,8 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
| 1824 |
{
|
| 1825 |
// Discourage outbound (but not inbound) peers if on an invalid chain.
|
| 1826 |
// Exempt HB compact block peers. Manual connections are always protected from discouragement.
|
| 1827 |
-
if (!via_compact_block) {
|
| 1828 |
-
HandleDoSPunishment(m_connman, nodeid, 100, "block");
|
| 1829 |
return;
|
| 1830 |
}
|
| 1831 |
break;
|
|
@@ -1833,11 +1820,11 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|
| 1833 |
case BlockValidationResult::BLOCK_INVALID_HEADER:
|
| 1834 |
case BlockValidationResult::BLOCK_CHECKPOINT:
|
| 1835 |
case BlockValidationResult::BLOCK_INVALID_PREV:
|
| 1836 |
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
| 1837 |
return;
|
| 1838 |
// Conflicting (but not necessarily invalid) data or different policy:
|
| 1839 |
case BlockValidationResult::BLOCK_MISSING_PREV:
|
| 1840 |
-
HandleDoSPunishment(m_connman, nodeid, 100, "block header");
|
| 1841 |
return;
|
| 1842 |
case BlockValidationResult::BLOCK_TIME_FUTURE:
|
| 1843 |
break;
|
|
@@ -2553,9 +2540,6 @@ void PeerManagerImpl::HandleUnconnectingHeaders(CNode& pfrom, Peer& peer,
|
|
| 2553 |
// we can use this peer to download.
|
| 2554 |
WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
|
| 2555 |
|
| 2556 |
-
if (pfrom.PunishInvalidBlocks()) {
|
| 2557 |
-
pfrom.fDisconnect = true;
|
| 2558 |
-
}
|
| 2559 |
}
|
| 2560 |
|
| 2561 |
bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const
|
|
|
|
| 1788 |
);
|
| 1789 |
}
|
| 1790 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1791 |
void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
| 1792 |
bool via_compact_block, const std::string& message)
|
| 1793 |
{
|
| 1794 |
+
PeerRef peer{GetPeerRef(nodeid)};
|
| 1795 |
switch (state.GetResult()) {
|
| 1796 |
case BlockValidationResult::BLOCK_RESULT_UNSET:
|
| 1797 |
break;
|
|
|
|
| 1803 |
case BlockValidationResult::BLOCK_CONSENSUS:
|
| 1804 |
case BlockValidationResult::BLOCK_MUTATED:
|
| 1805 |
if (!via_compact_block) {
|
| 1806 |
+
if (peer) Misbehaving(*peer, message);
|
| 1807 |
return;
|
| 1808 |
}
|
| 1809 |
break;
|
|
|
|
| 1811 |
{
|
| 1812 |
// Discourage outbound (but not inbound) peers if on an invalid chain.
|
| 1813 |
// Exempt HB compact block peers. Manual connections are always protected from discouragement.
|
| 1814 |
+
if (peer && !via_compact_block && !peer->m_is_inbound) {
|
| 1815 |
+
Misbehaving(*peer, message);
|
| 1816 |
return;
|
| 1817 |
}
|
| 1818 |
break;
|
|
|
|
| 1820 |
case BlockValidationResult::BLOCK_INVALID_HEADER:
|
| 1821 |
case BlockValidationResult::BLOCK_CHECKPOINT:
|
| 1822 |
case BlockValidationResult::BLOCK_INVALID_PREV:
|
| 1823 |
+
if (peer) Misbehaving(*peer, message);
|
| 1824 |
return;
|
| 1825 |
// Conflicting (but not necessarily invalid) data or different policy:
|
| 1826 |
case BlockValidationResult::BLOCK_MISSING_PREV:
|
| 1827 |
+
if (peer) Misbehaving(*peer, message);
|
| 1828 |
return;
|
| 1829 |
case BlockValidationResult::BLOCK_TIME_FUTURE:
|
| 1830 |
break;
|
|
|
|
| 2540 |
// we can use this peer to download.
|
| 2541 |
WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
|
| 2542 |
|
|
|
|
|
|
|
|
|
|
| 2543 |
}
|
| 2544 |
|
| 2545 |
bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const
|