Skip to content

Commit 28ce05d

Browse files
committed
Merge #19260: p2p: disconnect peers that send filterclear + update 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 #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 #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/bitcoin@3a10d93) MarcoFalke: re-ACK 3a10d93 only change is replacing false with true 🚝 Tree-SHA512: 7aad8b3c0b0e776a47ad52544f0c1250feb242320f9a2962542f5905042f77e297a1486f8cdc3bf0fb93cd00c1ab66a67b2ec426eb6da3fe4cda56b5e623620f
2 parents 1c86ed4 + 3a10d93 commit 28ce05d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,20 +2215,6 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
22152215
}
22162216

22172217

2218-
if (!(pfrom.GetLocalServices() & NODE_BLOOM) &&
2219-
(msg_type == NetMsgType::FILTERLOAD ||
2220-
msg_type == NetMsgType::FILTERADD))
2221-
{
2222-
if (pfrom.nVersion >= NO_BLOOM_VERSION) {
2223-
LOCK(cs_main);
2224-
Misbehaving(pfrom.GetId(), 100);
2225-
return false;
2226-
} else {
2227-
pfrom.fDisconnect = true;
2228-
return false;
2229-
}
2230-
}
2231-
22322218
if (msg_type == NetMsgType::VERSION) {
22332219
// Each connection can only send one version message
22342220
if (pfrom.nVersion != 0)
@@ -3447,6 +3433,10 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
34473433
}
34483434

34493435
if (msg_type == NetMsgType::FILTERLOAD) {
3436+
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
3437+
pfrom.fDisconnect = true;
3438+
return true;
3439+
}
34503440
CBloomFilter filter;
34513441
vRecv >> filter;
34523442

@@ -3466,6 +3456,10 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
34663456
}
34673457

34683458
if (msg_type == NetMsgType::FILTERADD) {
3459+
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
3460+
pfrom.fDisconnect = true;
3461+
return true;
3462+
}
34693463
std::vector<unsigned char> vData;
34703464
vRecv >> vData;
34713465

@@ -3490,13 +3484,15 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
34903484
}
34913485

34923486
if (msg_type == NetMsgType::FILTERCLEAR) {
3487+
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
3488+
pfrom.fDisconnect = true;
3489+
return true;
3490+
}
34933491
if (pfrom.m_tx_relay == nullptr) {
34943492
return true;
34953493
}
34963494
LOCK(pfrom.m_tx_relay->cs_filter);
3497-
if (pfrom.GetLocalServices() & NODE_BLOOM) {
3498-
pfrom.m_tx_relay->pfilter = nullptr;
3499-
}
3495+
pfrom.m_tx_relay->pfilter = nullptr;
35003496
pfrom.m_tx_relay->fRelayTxes = true;
35013497
return true;
35023498
}

test/functional/p2p_nobloomfilter_messages.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
1. They send a p2p mempool message
99
2. They send a p2p filterload message
1010
3. They send a p2p filteradd message
11+
4. They send a p2p filterclear message
1112
"""
1213

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

43+
self.log.info("Test that peer is disconnected if it sends a filterclear message")
44+
self.test_message_causes_disconnect(msg_filterclear())
45+
4246
if __name__ == '__main__':
4347
P2PNobloomfilterMessages().main()

0 commit comments

Comments
 (0)