Skip to content

Commit

Permalink
Merge bitcoin#19260: p2p: disconnect peers that send filterclear + up…
Browse files Browse the repository at this point in the history
…date existing filter msg disconnect logic

3a10d93 [p2p/refactor] move disconnect logic and remove misbehaving (gzhao408)
ff8c430 [test] test disconnect for filterclear (gzhao408)
1c6b787 [netprocessing] disconnect node that sends filterclear (gzhao408)

Pull request description:

  Nodes that don't have bloomfilters turned on (i.e. no `NODE_BLOOM` service) should disconnect peers that send them `filterclear` P2P messages.

  Non-bloomfilter nodes already disconnect peers for [`filteradd` and `filterload`](https://github.com/bitcoin/bitcoin/blob/19e919217e6d62e3640525e4149de1a4ae04e74f/src/net_processing.cpp#L2218), but bitcoin#8709 removed `filterclear` so it could be used to reset tx relay. This isn't needed now because using `feefilter` message is much better for this purpose (See bitcoin#19204).

  Also refactors existing disconnect logic for `filteradd` and `filterload` into respective message handlers and removes banning for them.

ACKs for top commit:
  jnewbery:
    Code review ACK 3a10d93
  naumenkogs:
    utACK 3a10d93
  gillichu:
    tested ACK: quick test_runner on macOS [`3a10d93`](bitcoin@3a10d93)
  MarcoFalke:
    re-ACK 3a10d93 only change is replacing false with true 🚝

Tree-SHA512: 7aad8b3c0b0e776a47ad52544f0c1250feb242320f9a2962542f5905042f77e297a1486f8cdc3bf0fb93cd00c1ab66a67b2ec426eb6da3fe4cda56b5e623620f
  • Loading branch information
fanquake authored and knst committed Jan 16, 2024
1 parent 3fa7dd0 commit f7ddb7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2814,14 +2814,6 @@ void PeerManagerImpl::ProcessMessage(
PeerRef peer = GetPeerRef(pfrom.GetId());
if (peer == nullptr) return;

if (!(pfrom.GetLocalServices() & NODE_BLOOM) &&
(msg_type == NetMsgType::FILTERLOAD ||
msg_type == NetMsgType::FILTERADD))
{
Misbehaving(pfrom.GetId(), 100);
return;
}

if (msg_type == NetMsgType::VERSION) {
// Each connection can only send one version message
if (pfrom.nVersion != 0)
Expand Down Expand Up @@ -4181,6 +4173,10 @@ void PeerManagerImpl::ProcessMessage(
}

if (msg_type == NetMsgType::FILTERLOAD) {
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
pfrom.fDisconnect = true;
return;
}
CBloomFilter filter;
vRecv >> filter;

Expand All @@ -4199,6 +4195,10 @@ void PeerManagerImpl::ProcessMessage(
}

if (msg_type == NetMsgType::FILTERADD) {
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
pfrom.fDisconnect = true;
return;
}
std::vector<unsigned char> vData;
vRecv >> vData;

Expand All @@ -4222,13 +4222,15 @@ void PeerManagerImpl::ProcessMessage(
}

if (msg_type == NetMsgType::FILTERCLEAR) {
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
pfrom.fDisconnect = true;
return;
}
if (!pfrom.RelayAddrsWithConn()) {
return;
}
LOCK(pfrom.m_tx_relay->cs_filter);
if (pfrom.GetLocalServices() & NODE_BLOOM) {
pfrom.m_tx_relay->pfilter = nullptr;
}
pfrom.m_tx_relay->pfilter = nullptr;
pfrom.m_tx_relay->fRelayTxes = true;
return;
}
Expand Down
6 changes: 5 additions & 1 deletion test/functional/p2p_nobloomfilter_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
1. They send a p2p mempool message
2. They send a p2p filterload message
3. They send a p2p filteradd message
4. They send a p2p filterclear message
"""

from test_framework.messages import msg_mempool, msg_filteradd, msg_filterload
from test_framework.messages import msg_mempool, msg_filteradd, msg_filterload, msg_filterclear
from test_framework.mininode import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
Expand Down Expand Up @@ -39,5 +40,8 @@ def run_test(self):
self.log.info("Test that node is disconnected if it sends filteradd message")
self.test_message_causes_disconnect(msg_filteradd(data=b'\xcc'))

self.log.info("Test that peer is disconnected if it sends a filterclear message")
self.test_message_causes_disconnect(msg_filterclear())

if __name__ == '__main__':
P2PNobloomfilterMessages().main()

0 comments on commit f7ddb7e

Please sign in to comment.