From 8bc4461326df73813cd66340373d052806bea85a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 20 Aug 2015 21:15:27 -0700 Subject: [PATCH 01/11] Add NODE_BLOOM service bit and bump protocol version Lets nodes advertise that they offer bloom filter support explicitly. The protocol version bump allows SPV nodes to assume that NODE_BLOOM is set if NODE_NETWORK is set for pre-170004 nodes. Also adds an option to turn bloom filter support off for nodes which advertise a version number >= 170004. Nodes attempting to use bloom filters on such protocol versions are banned, and a later upgade should drop nodes of an older version which attempt to use bloom filters. Much code stolen from Peter Todd. Zcash: Implements Zcash equivalent of BIP 111; deploys with Overwinter --- src/init.cpp | 3 +++ src/main.cpp | 15 +++++++++++++++ src/protocol.h | 4 ++++ src/version.h | 5 ++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 76e6f35dc..730b0f75f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1025,6 +1025,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Option to startup with mocktime set (used for regression testing): SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op + if (GetBoolArg("-peerbloomfilters", true)) + nLocalServices |= NODE_BLOOM; + #ifdef ENABLE_MINING if (mapArgs.count("-mineraddress")) { CBitcoinAddress addr; diff --git a/src/main.cpp b/src/main.cpp index e1b49a62b..1848ee7fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5498,6 +5498,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } + else if (!(nLocalServices & NODE_BLOOM) && + (strCommand == "filterload" || + strCommand == "filteradd" || + strCommand == "filterclear") && + //TODO: Remove this line after reasonable network upgrade + pfrom->nVersion >= NO_BLOOM_VERSION) + { + if (pfrom->nVersion >= NO_BLOOM_VERSION) + Misbehaving(pfrom->GetId(), 100); + //TODO: Enable this after reasonable network upgrade + //else + // pfrom->fDisconnect = true; + } + + else if (strCommand == "filterload") { CBloomFilter filter; diff --git a/src/protocol.h b/src/protocol.h index b0208b01c..5eafb7df6 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -71,6 +71,10 @@ enum { // set by all Bitcoin Core nodes, and is unset by SPV clients or other peers that just want // network services but don't provide them. NODE_NETWORK = (1 << 0), + // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections. + // Zcash nodes used to support this by default, without advertising this bit, + // but no longer do as of protocol version 170004 (= NO_BLOOM_VERSION) + NODE_BLOOM = (1 << 2), // Bits 24-31 are reserved for temporary experiments. Just pick a bit that // isn't getting used, or one not being used much, and notify the diff --git a/src/version.h b/src/version.h index 25527895d..258534aa6 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 170003; +static const int PROTOCOL_VERSION = 170004; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -30,4 +30,7 @@ static const int BIP0031_VERSION = 60000; //! "mempool" command, enhanced "getdata" behavior starts with this version static const int MEMPOOL_GD_VERSION = 60002; +//! "filter*" commands are disabled without NODE_BLOOM after and including this version +static const int NO_BLOOM_VERSION = 170004; + #endif // BITCOIN_VERSION_H From 935f9f713ce706b56bcbc4097962ced872525d27 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 8 Sep 2015 17:16:59 +0200 Subject: [PATCH 02/11] doc: update release-notes and bips.md for BIP111 Also includes a09db7c [trivial] Minor format fixes --- doc/bips.md | 4 ++++ doc/release-notes.md | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 doc/bips.md diff --git a/doc/bips.md b/doc/bips.md new file mode 100644 index 000000000..14c7e372f --- /dev/null +++ b/doc/bips.md @@ -0,0 +1,4 @@ +BIPs that are implemented by Zcash (up-to-date up to **v1.1.0**): + +* Numerous historic BIPs were present in **v1.0.0** at launch; see [the protocol spec](https://github.com/zcash/zips/blob/master/protocol/protocol.pdf) for details. +* [`BIP 111`](https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki): `NODE_BLOOM` service bit added, but only enforced for peer versions `>=170004` as of **v1.1.0** ([PR #2814](https://github.com/zcash/zcash/pull/2814)). diff --git a/doc/release-notes.md b/doc/release-notes.md index 8d7614c8b..596ad6eae 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -20,3 +20,20 @@ inputs each. Starting from this release, `-mempooltxinputlimit` will be enforced before the Overwinter activation height is reached, but will be ignored once Overwinter activates. The option will be removed entirely in a future release after Overwinter has activated. + +`NODE_BLOOM` service bit +------------------------ + +Support for the `NODE_BLOOM` service bit, as described in [BIP +111](https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki), has been +added to the P2P protocol code. + +BIP 111 defines a service bit to allow peers to advertise that they support +bloom filters (such as used by SPV clients) explicitly. It also bumps the protocol +version to allow peers to identify old nodes which allow bloom filtering of the +connection despite lacking the new service bit. + +In this version, it is only enforced for peers that send protocol versions +`>=170004`. For the next major version it is planned that this restriction will be +removed. It is recommended to update SPV clients to check for the `NODE_BLOOM` +service bit for nodes that report versions newer than 170004. From d06ae252a0e604da84df66f7348433ca422bd16e Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Tue, 24 Nov 2015 01:47:32 -0800 Subject: [PATCH 03/11] Move bloom filter filtering logic outside of command "switch" (giant if/else). Moving this logic outside of the "switch" makes it far simpler to enable the forced disconnect by a parameter. --- src/main.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1848ee7fe..60a14fd15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4721,6 +4721,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } + if (!(nLocalServices & NODE_BLOOM) && + (strCommand == "filterload" || + strCommand == "filteradd" || + strCommand == "filterclear")) + { + if (pfrom->nVersion >= NO_BLOOM_VERSION) { + Misbehaving(pfrom->GetId(), 100); + return false; + } + //TODO: Enable this after reasonable network upgrade + //else { + // pfrom->fDisconnect = true; + // return false; + //} + } if (strCommand == "version") @@ -5498,21 +5513,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - else if (!(nLocalServices & NODE_BLOOM) && - (strCommand == "filterload" || - strCommand == "filteradd" || - strCommand == "filterclear") && - //TODO: Remove this line after reasonable network upgrade - pfrom->nVersion >= NO_BLOOM_VERSION) - { - if (pfrom->nVersion >= NO_BLOOM_VERSION) - Misbehaving(pfrom->GetId(), 100); - //TODO: Enable this after reasonable network upgrade - //else - // pfrom->fDisconnect = true; - } - - else if (strCommand == "filterload") { CBloomFilter filter; From f07ad435532a44158182fdf43abc9d1cb8402104 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Tue, 24 Nov 2015 01:51:53 -0800 Subject: [PATCH 04/11] Add enforcenodebloom option. Previously peers which implement a protocol version less than NO_BLOOM_VERSION would not be disconnected for sending a filter command, regardless of the peerbloomfilter option. Many node operators do not wish to provide expensive bloom filtering for SPV clients, previously they had to cherry pick the commit which enabled the disconnect logic. The default should remain false until a sufficient percent of SPV clients have updated. --- src/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 60a14fd15..6d1c04b08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4729,12 +4729,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->nVersion >= NO_BLOOM_VERSION) { Misbehaving(pfrom->GetId(), 100); return false; + } else if (GetBoolArg("-enforcenodebloom", false)) { + pfrom->fDisconnect = true; + return false; } - //TODO: Enable this after reasonable network upgrade - //else { - // pfrom->fDisconnect = true; - // return false; - //} } From b976ce7ceed4cb71f6ffa6da8d44174a8b349886 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Tue, 24 Nov 2015 01:57:08 -0800 Subject: [PATCH 05/11] Document both the peerbloomfilters and enforcenodebloom options. --- src/init.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 730b0f75f..3e8abbc25 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -389,6 +389,9 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-onion=", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy")); strUsage += HelpMessageOpt("-onlynet=", _("Only connect to nodes in network (ipv4, ipv6 or onion)")); strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1)); + strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), 1)); + if (showDebug) + strUsage += HelpMessageOpt("-enforcenodebloom", strprintf("Enforce minimum protocol version to limit use of bloom filters (default: %u)", 0)); strUsage += HelpMessageOpt("-port=", strprintf(_("Listen for connections on (default: %u or testnet: %u)"), 8233, 18233)); strUsage += HelpMessageOpt("-proxy=", _("Connect through SOCKS5 proxy")); strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1)); From 1c82adeb87beda028e53abe465ab87f42fb1d022 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 5 Dec 2015 17:45:44 +0800 Subject: [PATCH 06/11] Don't do mempool lookups for "mempool" command without a filter --- src/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6d1c04b08..a892ff0d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5384,12 +5384,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vector vInv; BOOST_FOREACH(uint256& hash, vtxid) { CInv inv(MSG_TX, hash); - CTransaction tx; - bool fInMemPool = mempool.lookup(hash, tx); - if (!fInMemPool) continue; // another thread removed since queryHashes, maybe... - if ((pfrom->pfilter && pfrom->pfilter->IsRelevantAndUpdate(tx)) || - (!pfrom->pfilter)) - vInv.push_back(inv); + if (pfrom->pfilter) { + CTransaction tx; + bool fInMemPool = mempool.lookup(hash, tx); + if (!fInMemPool) continue; // another thread removed since queryHashes, maybe... + if (!pfrom->pfilter->IsRelevantAndUpdate(tx)) continue; + } + vInv.push_back(inv); if (vInv.size() == MAX_INV_SZ) { pfrom->PushMessage("inv", vInv); vInv.clear(); From b77e46fe018a2c3e6699dc5d79cb7754251029b6 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 3 Apr 2018 17:12:46 +0100 Subject: [PATCH 07/11] Add RPC test for -enforcenodebloom --- qa/pull-tester/rpc-tests.sh | 1 + qa/rpc-tests/p2p_node_bloom.py | 97 +++++++++++++++++++++++++ qa/rpc-tests/test_framework/mininode.py | 16 ++++ 3 files changed, 114 insertions(+) create mode 100755 qa/rpc-tests/p2p_node_bloom.py diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 9900b1c20..729c92b1d 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -57,6 +57,7 @@ testScripts=( 'overwinter_peer_management.py' 'rewind_index.py' 'p2p_txexpiry_dos.py' + 'p2p_node_bloom.py' ); testScriptsExt=( 'getblocktemplate_longpoll.py' diff --git a/qa/rpc-tests/p2p_node_bloom.py b/qa/rpc-tests/p2p_node_bloom.py new file mode 100755 index 000000000..2e0d60e4e --- /dev/null +++ b/qa/rpc-tests/p2p_node_bloom.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 The Zcash developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \ + msg_filterclear, mininode_lock, MY_VERSION +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import initialize_chain_clean, start_nodes, \ + p2p_port, assert_equal + +import time + + +class TestNode(NodeConnCB): + def __init__(self): + NodeConnCB.__init__(self) + self.create_callback_map() + self.connection = None + + def add_connection(self, conn): + self.connection = conn + + # Spin until verack message is received from the node. + # We use this to signal that our test can begin. This + # is called from the testing thread, so it needs to acquire + # the global lock. + def wait_for_verack(self): + while True: + with mininode_lock: + if self.verack_received: + return + time.sleep(0.05) + + # Wrapper for the NodeConn's send_message function + def send_message(self, message): + self.connection.send_message(message) + + def on_close(self, conn): + pass + + def on_reject(self, conn, message): + conn.rejectMessage = message + + +class NodeBloomTest(BitcoinTestFramework): + + def setup_chain(self): + print "Initializing test directory "+self.options.tmpdir + initialize_chain_clean(self.options.tmpdir, 2) + + def setup_network(self): + self.nodes = start_nodes(2, self.options.tmpdir, + extra_args=[['-nopeerbloomfilters', '-enforcenodebloom'], []]) + + def run_test(self): + nobf_node = TestNode() + bf_node = TestNode() + + connections = [] + connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], nobf_node)) + connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], bf_node)) + nobf_node.add_connection(connections[0]) + bf_node.add_connection(connections[1]) + + # Start up network handling in another thread + NetworkThread().start() + + nobf_node.wait_for_verack() + bf_node.wait_for_verack() + + # Verify mininodes are connected to zcashd nodes + peerinfo = self.nodes[0].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(MY_VERSION)) + peerinfo = self.nodes[1].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(MY_VERSION)) + + # Mininodes send filterclear message to zcashd node. + nobf_node.send_message(msg_filterclear()) + bf_node.send_message(msg_filterclear()) + + time.sleep(3) + + # Verify NoBF mininode has been dropped, and BF mininode is still connected. + peerinfo = self.nodes[0].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(0, versions.count(MY_VERSION)) + peerinfo = self.nodes[1].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(MY_VERSION)) + + [ c.disconnect_node() for c in connections ] + +if __name__ == '__main__': + NodeBloomTest().main() diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index 12b48ae0b..e0f2a3844 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -1263,6 +1263,22 @@ class msg_reject(object): % (self.message, self.code, self.reason, self.data) +class msg_filterclear(object): + command = "filterclear" + + def __init__(self): + pass + + def deserialize(self, f): + pass + + def serialize(self): + return "" + + def __repr__(self): + return "msg_filterclear()" + + # This is what a callback should look like for NodeConn # Reimplement the on_* functions to provide handling for events class NodeConnCB(object): From 0a284ecaf63447e8ef1241caa1c6d58153f3d89a Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 3 Apr 2018 17:30:14 +0100 Subject: [PATCH 08/11] Fix NODE_BLOOM documentation errors --- doc/release-notes.md | 6 +++--- src/init.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/release-notes.md b/doc/release-notes.md index 596ad6eae..4ecb9d000 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -29,11 +29,11 @@ Support for the `NODE_BLOOM` service bit, as described in [BIP added to the P2P protocol code. BIP 111 defines a service bit to allow peers to advertise that they support -bloom filters (such as used by SPV clients) explicitly. It also bumps the protocol -version to allow peers to identify old nodes which allow bloom filtering of the +Bloom filters (such as used by SPV clients) explicitly. It also bumps the protocol +version to allow peers to identify old nodes which allow Bloom filtering of the connection despite lacking the new service bit. In this version, it is only enforced for peers that send protocol versions `>=170004`. For the next major version it is planned that this restriction will be removed. It is recommended to update SPV clients to check for the `NODE_BLOOM` -service bit for nodes that report versions newer than 170004. +service bit for nodes that report version 170004 or newer. diff --git a/src/init.cpp b/src/init.cpp index 3e8abbc25..7893afab9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -389,9 +389,9 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-onion=", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy")); strUsage += HelpMessageOpt("-onlynet=", _("Only connect to nodes in network (ipv4, ipv6 or onion)")); strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1)); - strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), 1)); + strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with Bloom filters (default: %u)"), 1)); if (showDebug) - strUsage += HelpMessageOpt("-enforcenodebloom", strprintf("Enforce minimum protocol version to limit use of bloom filters (default: %u)", 0)); + strUsage += HelpMessageOpt("-enforcenodebloom", strprintf("Enforce minimum protocol version to limit use of Bloom filters (default: %u)", 0)); strUsage += HelpMessageOpt("-port=", strprintf(_("Listen for connections on (default: %u or testnet: %u)"), 8233, 18233)); strUsage += HelpMessageOpt("-proxy=", _("Connect through SOCKS5 proxy")); strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1)); From 2b7fcab8fc3205c49224a25ed108a6a2d05c63ed Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 4 Apr 2018 12:19:30 +0100 Subject: [PATCH 09/11] Move bloom filter filtering logic back into command "switch" --- src/main.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a892ff0d3..92666d851 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4721,21 +4721,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - if (!(nLocalServices & NODE_BLOOM) && - (strCommand == "filterload" || - strCommand == "filteradd" || - strCommand == "filterclear")) - { - if (pfrom->nVersion >= NO_BLOOM_VERSION) { - Misbehaving(pfrom->GetId(), 100); - return false; - } else if (GetBoolArg("-enforcenodebloom", false)) { - pfrom->fDisconnect = true; - return false; - } - } - - if (strCommand == "version") { // Each connection can only send one version message @@ -5512,6 +5497,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } + else if (!(nLocalServices & NODE_BLOOM) && + (strCommand == "filterload" || + strCommand == "filteradd" || + strCommand == "filterclear")) + { + if (pfrom->nVersion >= NO_BLOOM_VERSION) { + Misbehaving(pfrom->GetId(), 100); + return false; + } else if (GetBoolArg("-enforcenodebloom", false)) { + pfrom->fDisconnect = true; + return false; + } + } + + else if (strCommand == "filterload") { CBloomFilter filter; From 4f31d823952a1dac35b7d2b4fdad4d41fee5a201 Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Tue, 13 Sep 2016 09:10:22 +0700 Subject: [PATCH 10/11] Allow filterclear messages for enabling TX relay only. An example of where this might be useful is allowing a node to connect blocksonly during IBD but then becoming a full-node once caught up with the latest block. This might also even want to be the default behaviour since during IBD most TXs appear to be orphans, and are routinely dropped (for example when a node disconnects). Therefore, this can waste a lot of bandwidth. Additionally, another pull could be written to stop relaying of TXs to nodes that are clearly far behind the latest block and are running a node that doesn't store many orphan TXs, such as recent versions of Bitcoin Core. --- src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 92666d851..766369344 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5499,8 +5499,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (!(nLocalServices & NODE_BLOOM) && (strCommand == "filterload" || - strCommand == "filteradd" || - strCommand == "filterclear")) + strCommand == "filteradd")) { if (pfrom->nVersion >= NO_BLOOM_VERSION) { Misbehaving(pfrom->GetId(), 100); @@ -5554,8 +5553,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (strCommand == "filterclear") { LOCK(pfrom->cs_filter); - delete pfrom->pfilter; - pfrom->pfilter = new CBloomFilter(); + if (nLocalServices & NODE_BLOOM) { + delete pfrom->pfilter; + pfrom->pfilter = new CBloomFilter(); + } pfrom->fRelayTxes = true; } From 3fe2f3d14380228f8c1556f349f986b64efae9ed Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 4 Apr 2018 12:55:15 +0100 Subject: [PATCH 11/11] Update -enforcenodebloom RPC test with filterclear vs filteradd --- qa/rpc-tests/p2p_node_bloom.py | 16 +++++++++++++++- qa/rpc-tests/test_framework/mininode.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/p2p_node_bloom.py b/qa/rpc-tests/p2p_node_bloom.py index 2e0d60e4e..271689aad 100755 --- a/qa/rpc-tests/p2p_node_bloom.py +++ b/qa/rpc-tests/p2p_node_bloom.py @@ -4,7 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \ - msg_filterclear, mininode_lock, MY_VERSION + msg_filteradd, msg_filterclear, mininode_lock, MY_VERSION from test_framework.test_framework import BitcoinTestFramework from test_framework.util import initialize_chain_clean, start_nodes, \ p2p_port, assert_equal @@ -83,6 +83,20 @@ class NodeBloomTest(BitcoinTestFramework): time.sleep(3) + # Verify mininodes are still connected to zcashd nodes + peerinfo = self.nodes[0].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(MY_VERSION)) + peerinfo = self.nodes[1].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(MY_VERSION)) + + # Mininodes send filteradd message to zcashd node. + nobf_node.send_message(msg_filteradd()) + bf_node.send_message(msg_filteradd()) + + time.sleep(3) + # Verify NoBF mininode has been dropped, and BF mininode is still connected. peerinfo = self.nodes[0].getpeerinfo() versions = [x["version"] for x in peerinfo] diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index e0f2a3844..23b8293ba 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -1263,6 +1263,22 @@ class msg_reject(object): % (self.message, self.code, self.reason, self.data) +class msg_filteradd(object): + command = "filteradd" + + def __init__(self): + self.data = "" + + def deserialize(self, f): + self.data = deser_string(f) + + def serialize(self): + return ser_string(self.data) + + def __repr__(self): + return "msg_filteradd(data=%s)" % (repr(self.data)) + + class msg_filterclear(object): command = "filterclear"