Skip to content
Bitcoin Roots

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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/net_processing.cpp CHANGED
@@ -1819,23 +1819,10 @@ void PeerManagerImpl::Misbehaving(Peer& peer, const std::string& message)
1819
  );
1820
  }
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
  void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
1837
  bool via_compact_block, const std::string& message)
1838
  {
 
1839
  switch (state.GetResult()) {
1840
  case BlockValidationResult::BLOCK_RESULT_UNSET:
1841
  break;
@@ -1847,7 +1834,7 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
1847
  case BlockValidationResult::BLOCK_CONSENSUS:
1848
  case BlockValidationResult::BLOCK_MUTATED:
1849
  if (!via_compact_block) {
1850
- HandleDoSPunishment(m_connman, nodeid, 100, "block");
1851
  return;
1852
  }
1853
  break;
@@ -1855,19 +1842,19 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
1855
  {
1856
  // Discourage outbound (but not inbound) peers if on an invalid chain.
1857
  // Exempt HB compact block peers. Manual connections are always protected from discouragement.
1858
- if (!via_compact_block) {
1859
- HandleDoSPunishment(m_connman, nodeid, 100, "block");
1860
  return;
1861
  }
1862
  break;
1863
  }
1864
  case BlockValidationResult::BLOCK_INVALID_HEADER:
1865
  case BlockValidationResult::BLOCK_INVALID_PREV:
1866
- HandleDoSPunishment(m_connman, nodeid, 100, "block header");
1867
  return;
1868
  // Conflicting (but not necessarily invalid) data or different policy:
1869
  case BlockValidationResult::BLOCK_MISSING_PREV:
1870
- HandleDoSPunishment(m_connman, nodeid, 100, "block header");
1871
  return;
1872
  case BlockValidationResult::BLOCK_TIME_FUTURE:
1873
  break;
@@ -2591,9 +2578,6 @@ void PeerManagerImpl::HandleUnconnectingHeaders(CNode& pfrom, Peer& peer,
2591
  // we can use this peer to download.
2592
  WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
2593
 
2594
- if (pfrom.PunishInvalidBlocks()) {
2595
- pfrom.fDisconnect = true;
2596
- }
2597
  }
2598
 
2599
  bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const
 
1819
  );
1820
  }
1821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1822
  void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
1823
  bool via_compact_block, const std::string& message)
1824
  {
1825
+ PeerRef peer{GetPeerRef(nodeid)};
1826
  switch (state.GetResult()) {
1827
  case BlockValidationResult::BLOCK_RESULT_UNSET:
1828
  break;
 
1834
  case BlockValidationResult::BLOCK_CONSENSUS:
1835
  case BlockValidationResult::BLOCK_MUTATED:
1836
  if (!via_compact_block) {
1837
+ if (peer) Misbehaving(*peer, message);
1838
  return;
1839
  }
1840
  break;
 
1842
  {
1843
  // Discourage outbound (but not inbound) peers if on an invalid chain.
1844
  // Exempt HB compact block peers. Manual connections are always protected from discouragement.
1845
+ if (peer && !via_compact_block && !peer->m_is_inbound) {
1846
+ Misbehaving(*peer, message);
1847
  return;
1848
  }
1849
  break;
1850
  }
1851
  case BlockValidationResult::BLOCK_INVALID_HEADER:
1852
  case BlockValidationResult::BLOCK_INVALID_PREV:
1853
+ if (peer) Misbehaving(*peer, message);
1854
  return;
1855
  // Conflicting (but not necessarily invalid) data or different policy:
1856
  case BlockValidationResult::BLOCK_MISSING_PREV:
1857
+ if (peer) Misbehaving(*peer, message);
1858
  return;
1859
  case BlockValidationResult::BLOCK_TIME_FUTURE:
1860
  break;
 
2578
  // we can use this peer to download.
2579
  WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()));
2580
 
 
 
 
2581
  }
2582
 
2583
  bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>& headers) const