Skip to content

Commit a57af89

Browse files
author
MarcoFalke
committed
Merge #19564: test: p2p_feefilter improvements (logging, refactoring, speedup)
9e78943 test: speedup p2p_feefilter.py by whitelisting peers (immediate tx relay) (Sebastian Falbesoner) fe3f0cc test: use wait_until for invs matching in p2p_feefilter.py (Sebastian Falbesoner) 6d94192 test: add logging for p2p_feefilter.py (Sebastian Falbesoner) Pull request description: This PR gives some love to the functional test `p2p_feefilter.py` by introducing the following changes: * add missing log messages for the `test_feefilter` subtest (the main one) * deduplicate code by using the utility function `wait_until` (already using the [recently introduced version](bitcoin/bitcoin@12410b1)) instead of a manual condition checking loop with `time.sleep` * improve naming of the function `matchAllInvs` (more expressive name, snake_case) and moving it from global namespace to the connection class `FeefilterConn` * speeding up the test significantly by the good ol' method of activating immediate tx relay (as seen on e.g. bitcoin/bitcoin#17121, bitcoin/bitcoin#17124, bitcoin/bitcoin#17340, bitcoin/bitcoin#17362, ...): ``` master branch: $ time ./p2p_feefilter.py ... real 0m39.367s user 0m1.227s sys 0m0.571s PR branch: $ time ./p2p_feefilter.py ... real 0m9.386s user 0m1.120s sys 0m0.577s ``` ACKs for top commit: instagibbs: code review ACK bitcoin/bitcoin@9e78943 jonatack: re-ACK 9e78943 per `git range-diff 3ab2582 ea74a3c 9e78943` Tree-SHA512: fe21c1c5413df9165fea916b5d5f609d3ba33e7b5c3364b38eb824fcc55d9e6abddf27116cbc0b325913d451a73c44542040fb916aec9c46f805c6e12f6f10cf
2 parents 3ab2582 + 9e78943 commit a57af89

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

test/functional/p2p_feefilter.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Test processing of feefilter messages."""
66

77
from decimal import Decimal
8-
import time
98

109
from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter
1110
from test_framework.mininode import mininode_lock, P2PInterface
@@ -17,16 +16,6 @@ def hashToHex(hash):
1716
return format(hash, '064x')
1817

1918

20-
# Wait up to 60 secs to see if the testnode has received all the expected invs
21-
def allInvsMatch(invsExpected, testnode):
22-
for _ in range(60):
23-
with mininode_lock:
24-
if (sorted(invsExpected) == sorted(testnode.txinvs)):
25-
return True
26-
time.sleep(1)
27-
return False
28-
29-
3019
class FeefilterConn(P2PInterface):
3120
feefilter_received = False
3221

@@ -48,6 +37,10 @@ def on_inv(self, message):
4837
if (i.type == MSG_TX) or (i.type == MSG_WTX):
4938
self.txinvs.append(hashToHex(i.hash))
5039

40+
def wait_for_invs_to_match(self, invs_expected):
41+
invs_expected.sort()
42+
self.wait_until(lambda: invs_expected == sorted(self.txinvs), timeout=60)
43+
5144
def clear_invs(self):
5245
with mininode_lock:
5346
self.txinvs = []
@@ -61,7 +54,12 @@ def set_test_params(self):
6154
# mempool and wallet feerate calculation based on GetFee
6255
# rounding down 3 places, leading to stranded transactions.
6356
# See issue #16499
64-
self.extra_args = [["-minrelaytxfee=0.00000100", "-mintxfee=0.00000100"]] * self.num_nodes
57+
# grant noban permission to all peers to speed up tx relay / mempool sync
58+
self.extra_args = [[
59+
"-minrelaytxfee=0.00000100",
60+
"-mintxfee=0.00000100",
61+
62+
]] * self.num_nodes
6563

6664
def skip_test_if_missing_module(self):
6765
self.skip_if_no_wallet()
@@ -88,24 +86,22 @@ def test_feefilter(self):
8886

8987
conn = self.nodes[0].add_p2p_connection(TestP2PConn())
9088

91-
# Test that invs are received by test connection for all txs at
92-
# feerate of .2 sat/byte
89+
self.log.info("Test txs paying 0.2 sat/byte are received by test connection")
9390
node1.settxfee(Decimal("0.00000200"))
9491
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
95-
assert allInvsMatch(txids, conn)
92+
conn.wait_for_invs_to_match(txids)
9693
conn.clear_invs()
9794

98-
# Set a filter of .15 sat/byte on test connection
95+
# Set a fee filter of 0.15 sat/byte on test connection
9996
conn.send_and_ping(msg_feefilter(150))
10097

101-
# Test that txs are still being received by test connection (paying .15 sat/byte)
98+
self.log.info("Test txs paying 0.15 sat/byte are received by test connection")
10299
node1.settxfee(Decimal("0.00000150"))
103100
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
104-
assert allInvsMatch(txids, conn)
101+
conn.wait_for_invs_to_match(txids)
105102
conn.clear_invs()
106103

107-
# Change tx fee rate to .1 sat/byte and test they are no longer received
108-
# by the test connection
104+
self.log.info("Test txs paying 0.1 sat/byte are no longer received by test connection")
109105
node1.settxfee(Decimal("0.00000100"))
110106
[node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
111107
self.sync_mempools() # must be sure node 0 has received all txs
@@ -119,13 +115,13 @@ def test_feefilter(self):
119115
# as well.
120116
node0.settxfee(Decimal("0.00020000"))
121117
txids = [node0.sendtoaddress(node0.getnewaddress(), 1)]
122-
assert allInvsMatch(txids, conn)
118+
conn.wait_for_invs_to_match(txids)
123119
conn.clear_invs()
124120

125-
# Remove fee filter and check that txs are received again
121+
self.log.info("Remove fee filter and check txs are received again")
126122
conn.send_and_ping(msg_feefilter(0))
127123
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
128-
assert allInvsMatch(txids, conn)
124+
conn.wait_for_invs_to_match(txids)
129125
conn.clear_invs()
130126

131127

0 commit comments

Comments
 (0)