mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Merge #19260: p2p: disconnect peers that send filterclear + update existing filter msg disconnect logic
3a10d935ac
[p2p/refactor] move disconnect logic and remove misbehaving (gzhao408)ff8c430c65
[test] test disconnect for filterclear (gzhao408)1c6b787e03
[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`](19e919217e/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 ACK3a10d935ac
naumenkogs: utACK3a10d93
gillichu: tested ACK: quick test_runner on macOS [`3a10d93`](3a10d935ac
) MarcoFalke: re-ACK3a10d935ac
only change is replacing false with true 🚝 Tree-SHA512: 7aad8b3c0b0e776a47ad52544f0c1250feb242320f9a2962542f5905042f77e297a1486f8cdc3bf0fb93cd00c1ab66a67b2ec426eb6da3fe4cda56b5e623620f
This commit is contained in:
commit
28ce05d06f
@ -2215,20 +2215,6 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
}
|
||||
|
||||
|
||||
if (!(pfrom.GetLocalServices() & NODE_BLOOM) &&
|
||||
(msg_type == NetMsgType::FILTERLOAD ||
|
||||
msg_type == NetMsgType::FILTERADD))
|
||||
{
|
||||
if (pfrom.nVersion >= NO_BLOOM_VERSION) {
|
||||
LOCK(cs_main);
|
||||
Misbehaving(pfrom.GetId(), 100);
|
||||
return false;
|
||||
} else {
|
||||
pfrom.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::VERSION) {
|
||||
// Each connection can only send one version message
|
||||
if (pfrom.nVersion != 0)
|
||||
@ -3447,6 +3433,10 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::FILTERLOAD) {
|
||||
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
|
||||
pfrom.fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
CBloomFilter filter;
|
||||
vRecv >> filter;
|
||||
|
||||
@ -3466,6 +3456,10 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::FILTERADD) {
|
||||
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
|
||||
pfrom.fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
std::vector<unsigned char> vData;
|
||||
vRecv >> vData;
|
||||
|
||||
@ -3490,13 +3484,15 @@ bool ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::FILTERCLEAR) {
|
||||
if (!(pfrom.GetLocalServices() & NODE_BLOOM)) {
|
||||
pfrom.fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
if (pfrom.m_tx_relay == nullptr) {
|
||||
return true;
|
||||
}
|
||||
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 true;
|
||||
}
|
||||
|
@ -8,9 +8,10 @@ Test that, when bloom filters are not enabled, nodes are disconnected if:
|
||||
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
|
||||
@ -39,5 +40,8 @@ class P2PNobloomfilterMessages(BitcoinTestFramework):
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user