Skip to content

Commit 8ef15e8

Browse files
author
MarcoFalke
committed
Merge bitcoin#19198: test: Check that peers with forcerelay permission are not asked to feefilter
fac63eb doc: Remove -whitelistforcerelay from comment (MarcoFalke) faabd15 test: Check that peers with forcerelay permission do not get a feefilter message (MarcoFalke) fad676b test: Add connect_nodes method (MarcoFalke) fac6ef4 test: Add test for no net permission (MarcoFalke) ffff3fe test: Replace self.nodes[0].p2p with conn (MarcoFalke) faccdc8 test: remove redundant generate (MarcoFalke) fab83b9 test: pep-8 p2p_feefilter.py (MarcoFalke) Pull request description: ACKs for top commit: jonatack: re-ACK fac63eb move-only change of two class member functions in test_framework.py and rebases since my review @ faccf0a per `git range-diff 4b5c919 faccf0a fac63eb`. Verified p2p_feefilter and p2p_permissions functional tests are running 🟢 locally. Tree-SHA512: 30a1c83baee15a4236d127d199c4f264852045372918d5aa5c09ef3d48041762ce3920ff86ef2466d4b2c792ddf56943d12b16c6dce34c6c5aea2a4af2eb4d49
2 parents 4b5c919 + fac63eb commit 8ef15e8

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

src/net_processing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4387,9 +4387,9 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
43874387
//
43884388
// Message: feefilter
43894389
//
4390-
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
43914390
if (pto->m_tx_relay != nullptr && pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
4392-
!pto->HasPermission(PF_FORCERELAY)) {
4391+
!pto->HasPermission(PF_FORCERELAY) // peers with the forcerelay permission should not filter txs to us
4392+
) {
43934393
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
43944394
int64_t timeNow = GetTimeMicros();
43954395
if (timeNow > pto->m_tx_relay->nextSendTimeFeeFilter) {

test/functional/p2p_feefilter.py

+45-16
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
from test_framework.messages import MSG_TX, msg_feefilter
1111
from test_framework.mininode import mininode_lock, P2PInterface
1212
from test_framework.test_framework import BitcoinTestFramework
13+
from test_framework.util import assert_equal
1314

1415

1516
def hashToHex(hash):
1617
return format(hash, '064x')
1718

19+
1820
# Wait up to 60 secs to see if the testnode has received all the expected invs
1921
def allInvsMatch(invsExpected, testnode):
2022
for x in range(60):
@@ -24,6 +26,18 @@ def allInvsMatch(invsExpected, testnode):
2426
time.sleep(1)
2527
return False
2628

29+
30+
class FeefilterConn(P2PInterface):
31+
feefilter_received = False
32+
33+
def on_feefilter(self, message):
34+
self.feefilter_received = True
35+
36+
def assert_feefilter_received(self, recv: bool):
37+
with mininode_lock:
38+
assert_equal(self.feefilter_received, recv)
39+
40+
2741
class TestP2PConn(P2PInterface):
2842
def __init__(self):
2943
super().__init__()
@@ -38,6 +52,7 @@ def clear_invs(self):
3852
with mininode_lock:
3953
self.txinvs = []
4054

55+
4156
class FeeFilterTest(BitcoinTestFramework):
4257
def set_test_params(self):
4358
self.num_nodes = 2
@@ -46,41 +61,54 @@ def set_test_params(self):
4661
# mempool and wallet feerate calculation based on GetFee
4762
# rounding down 3 places, leading to stranded transactions.
4863
# See issue #16499
49-
self.extra_args = [["-minrelaytxfee=0.00000100", "-mintxfee=0.00000100"]]*self.num_nodes
64+
self.extra_args = [["-minrelaytxfee=0.00000100", "-mintxfee=0.00000100"]] * self.num_nodes
5065

5166
def skip_test_if_missing_module(self):
5267
self.skip_if_no_wallet()
5368

5469
def run_test(self):
70+
self.test_feefilter_forcerelay()
71+
self.test_feefilter()
72+
73+
def test_feefilter_forcerelay(self):
74+
self.log.info('Check that peers without forcerelay permission (default) get a feefilter message')
75+
self.nodes[0].add_p2p_connection(FeefilterConn()).assert_feefilter_received(True)
76+
77+
self.log.info('Check that peers with forcerelay permission do not get a feefilter message')
78+
self.restart_node(0, extra_args=['[email protected]'])
79+
self.nodes[0].add_p2p_connection(FeefilterConn()).assert_feefilter_received(False)
80+
81+
# Restart to disconnect peers and load default extra_args
82+
self.restart_node(0)
83+
self.connect_nodes(1, 0)
84+
85+
def test_feefilter(self):
5586
node1 = self.nodes[1]
5687
node0 = self.nodes[0]
57-
# Get out of IBD
58-
node1.generate(1)
59-
self.sync_blocks()
6088

61-
self.nodes[0].add_p2p_connection(TestP2PConn())
89+
conn = self.nodes[0].add_p2p_connection(TestP2PConn())
6290

6391
# Test that invs are received by test connection for all txs at
6492
# feerate of .2 sat/byte
6593
node1.settxfee(Decimal("0.00000200"))
6694
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
67-
assert allInvsMatch(txids, self.nodes[0].p2p)
68-
self.nodes[0].p2p.clear_invs()
95+
assert allInvsMatch(txids, conn)
96+
conn.clear_invs()
6997

7098
# Set a filter of .15 sat/byte on test connection
71-
self.nodes[0].p2p.send_and_ping(msg_feefilter(150))
99+
conn.send_and_ping(msg_feefilter(150))
72100

73101
# Test that txs are still being received by test connection (paying .15 sat/byte)
74102
node1.settxfee(Decimal("0.00000150"))
75103
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
76-
assert allInvsMatch(txids, self.nodes[0].p2p)
77-
self.nodes[0].p2p.clear_invs()
104+
assert allInvsMatch(txids, conn)
105+
conn.clear_invs()
78106

79107
# Change tx fee rate to .1 sat/byte and test they are no longer received
80108
# by the test connection
81109
node1.settxfee(Decimal("0.00000100"))
82110
[node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
83-
self.sync_mempools() # must be sure node 0 has received all txs
111+
self.sync_mempools() # must be sure node 0 has received all txs
84112

85113
# Send one transaction from node0 that should be received, so that we
86114
# we can sync the test on receipt (if node1's txs were relayed, they'd
@@ -91,14 +119,15 @@ def run_test(self):
91119
# as well.
92120
node0.settxfee(Decimal("0.00020000"))
93121
txids = [node0.sendtoaddress(node0.getnewaddress(), 1)]
94-
assert allInvsMatch(txids, self.nodes[0].p2p)
95-
self.nodes[0].p2p.clear_invs()
122+
assert allInvsMatch(txids, conn)
123+
conn.clear_invs()
96124

97125
# Remove fee filter and check that txs are received again
98-
self.nodes[0].p2p.send_and_ping(msg_feefilter(0))
126+
conn.send_and_ping(msg_feefilter(0))
99127
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
100-
assert allInvsMatch(txids, self.nodes[0].p2p)
101-
self.nodes[0].p2p.clear_invs()
128+
assert allInvsMatch(txids, conn)
129+
conn.clear_invs()
130+
102131

103132
if __name__ == '__main__':
104133
FeeFilterTest().main()

test/functional/p2p_permissions.py

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def run_test(self):
4242
["relay", "noban", "mempool"],
4343
True)
4444

45+
self.checkpermission(
46+
# no permission (even with forcerelay)
47+
["[email protected]", "-whitelistforcerelay=1"],
48+
[],
49+
False)
50+
4551
self.checkpermission(
4652
# relay permission removed (no specific permissions)
4753
["-whitelist=127.0.0.1", "-whitelistrelay=0"],

test/functional/test_framework/test_framework.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ def setup_network(self):
353353
# See fPreferredDownload in net_processing.
354354
#
355355
# If further outbound connections are needed, they can be added at the beginning of the test with e.g.
356-
# connect_nodes(self.nodes[1], 2)
356+
# self.connect_nodes(1, 2)
357357
for i in range(self.num_nodes - 1):
358-
connect_nodes(self.nodes[i + 1], i)
358+
self.connect_nodes(i + 1, i)
359359
self.sync_all()
360360

361361
def setup_nodes(self):
@@ -532,19 +532,25 @@ def restart_node(self, i, extra_args=None):
532532
def wait_for_node_exit(self, i, timeout):
533533
self.nodes[i].process.wait(timeout)
534534

535+
def connect_nodes(self, a, b):
536+
connect_nodes(self.nodes[a], b)
537+
538+
def disconnect_nodes(self, a, b):
539+
disconnect_nodes(self.nodes[a], b)
540+
535541
def split_network(self):
536542
"""
537543
Split the network of four nodes into nodes 0/1 and 2/3.
538544
"""
539-
disconnect_nodes(self.nodes[1], 2)
545+
self.disconnect_nodes(1, 2)
540546
self.sync_all(self.nodes[:2])
541547
self.sync_all(self.nodes[2:])
542548

543549
def join_network(self):
544550
"""
545551
Join the (previously split) network halves together.
546552
"""
547-
connect_nodes(self.nodes[1], 2)
553+
self.connect_nodes(1, 2)
548554
self.sync_all()
549555

550556
def sync_blocks(self, nodes=None, wait=1, timeout=60):

0 commit comments

Comments
 (0)