Skip to content

Commit

Permalink
test: p2p: add test for rejected tx request logic (m_recent_rejects
Browse files Browse the repository at this point in the history
… filter)
  • Loading branch information
theStack committed Apr 15, 2024
1 parent e9dc511 commit 60ca5d5
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/functional/p2p_tx_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Test transaction download behavior
"""
from decimal import Decimal
import time

from test_framework.messages import (
Expand All @@ -14,6 +15,7 @@
MSG_WTX,
msg_inv,
msg_notfound,
msg_tx,
)
from test_framework.p2p import (
P2PInterface,
Expand All @@ -22,6 +24,7 @@
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
fill_mempool,
)
from test_framework.wallet import MiniWallet

Expand Down Expand Up @@ -54,6 +57,7 @@ def on_getdata(self, message):
class TxDownloadTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args= [['-datacarriersize=100000', '-maxmempool=5', '-persistmempool=0']] * self.num_nodes

def test_tx_requests(self):
self.log.info("Test that we request transactions from all our peers, eventually")
Expand Down Expand Up @@ -241,6 +245,29 @@ def test_spurious_notfound(self):
self.log.info('Check that spurious notfound is ignored')
self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)]))

def test_rejects_filter_reset(self):
self.log.info('Check that rejected tx is not requested again')
node = self.nodes[0]
fill_mempool(self, node, self.wallet)
self.wallet.rescan_utxos()
mempoolminfee = node.getmempoolinfo()['mempoolminfee']
peer = node.add_p2p_connection(TestP2PConn())
low_fee_tx = self.wallet.create_self_transfer(fee_rate=Decimal("0.9")*mempoolminfee)
assert_equal(node.testmempoolaccept([low_fee_tx['hex']])[0]["reject-reason"], "mempool min fee not met")
peer.send_and_ping(msg_tx(low_fee_tx['tx']))
peer.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=int(low_fee_tx['wtxid'], 16))]))
node.setmocktime(int(time.time()))
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
peer.sync_with_ping()
assert_equal(peer.tx_getdata_count, 0)

self.log.info('Check that rejection filter is cleared after new block comes in')
self.generate(self.wallet, 1, sync_fun=self.no_op)
peer.sync_with_ping()
peer.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=int(low_fee_tx['wtxid'], 16))]))
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
peer.wait_for_getdata([int(low_fee_tx['wtxid'], 16)])

def run_test(self):
self.wallet = MiniWallet(self.nodes[0])

Expand All @@ -257,7 +284,8 @@ def run_test(self):

# Run each test against new bitcoind instances, as setting mocktimes has long-term effects on when
# the next trickle relay event happens.
for test in [self.test_in_flight_max, self.test_inv_block, self.test_tx_requests]:
for test in [self.test_in_flight_max, self.test_inv_block, self.test_tx_requests,
self.test_rejects_filter_reset]:
self.stop_nodes()
self.start_nodes()
self.connect_nodes(1, 0)
Expand Down

0 comments on commit 60ca5d5

Please sign in to comment.