Skip to content

Commit 5aadbb7

Browse files
committed
Merge 63c0d0e into merged_master (Bitcoin PR bitcoin/bitcoin#21327)
I commented out a few new lines at the bottom of test/functional/p2p_ibd_txrelay.py It tests that nodes process certain transactions, after IBD. These new assertions from upstream are failing, but it may be because our IBD / tx sharing logic is different. We should revisit this.
2 parents 0c2dff3 + 63c0d0e commit 5aadbb7

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/net_processing.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3264,6 +3264,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32643264
return;
32653265
}
32663266

3267+
// Stop processing the transaction early if we are still in IBD since we don't
3268+
// have enough information to validate it yet. Sending unsolicited transactions
3269+
// is not considered a protocol violation, so don't punish the peer.
3270+
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) return;
3271+
32673272
CTransactionRef ptx;
32683273
vRecv >> ptx;
32693274
const CTransaction& tx = *ptx;

test/functional/p2p_ibd_txrelay.py

+53-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22
# Copyright (c) 2020-2021 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test fee filters during and after IBD."""
5+
"""Test transaction relay behavior during IBD:
6+
- Set fee filters to MAX_MONEY
7+
- Don't request transactions
8+
- Ignore all transaction messages
9+
"""
610

711
from decimal import Decimal
12+
import time
813

9-
from test_framework.messages import COIN
14+
from test_framework.messages import (
15+
CInv,
16+
COIN,
17+
CTransaction,
18+
from_hex,
19+
msg_inv,
20+
msg_tx,
21+
MSG_WTX,
22+
)
23+
from test_framework.p2p import (
24+
NONPREF_PEER_TX_DELAY,
25+
P2PDataStore,
26+
P2PInterface,
27+
p2p_lock
28+
)
1029
from test_framework.test_framework import BitcoinTestFramework
1130

1231
# ELEMENTS: this number is implied by DEFAULT_MIN_RELAY_TX_FEE in src/net_processing.cpp
@@ -30,6 +49,33 @@ def run_test(self):
3049
assert node.getblockchaininfo()['initialblockdownload']
3150
self.wait_until(lambda: all(peer['minfeefilter'] == MAX_FEE_FILTER for peer in node.getpeerinfo()))
3251

52+
self.log.info("Check that nodes don't send getdatas for transactions while still in IBD")
53+
peer_inver = self.nodes[0].add_p2p_connection(P2PDataStore())
54+
txid = 0xdeadbeef
55+
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=txid)]))
56+
# The node should not send a getdata, but if it did, it would first delay 2 seconds
57+
self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY))
58+
peer_inver.sync_send_with_ping()
59+
with p2p_lock:
60+
assert txid not in peer_inver.getdata_requests
61+
self.nodes[0].disconnect_p2ps()
62+
63+
self.log.info("Check that nodes don't process unsolicited transactions while still in IBD")
64+
# A transaction hex pulled from tx_valid.json. There are no valid transactions since no UTXOs
65+
# exist yet, but it should be a well-formed transaction.
66+
# ELEMENTS: this is an arbitrary transaction pulled from a dummy regtest network
67+
rawhex = "0200000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0502ca000101" + \
68+
"ffffffff0201230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b201000000000000000000016" + \
69+
"a01230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b201000000000000000000266a24aa21a9" + \
70+
"ed94f15ed3a62165e4a0b99699cc28b48e19cb5bc1b1f47155db62d63f1e047d45000000000000012000000000000000000" + \
71+
"000000000000000000000000000000000000000000000000000000000"
72+
assert self.nodes[1].decoderawtransaction(rawhex) # returns a dict, should not throw
73+
tx = from_hex(CTransaction(), rawhex)
74+
peer_txer = self.nodes[0].add_p2p_connection(P2PInterface())
75+
with self.nodes[0].assert_debug_log(expected_msgs=["received: tx"], unexpected_msgs=["was not accepted"]):
76+
peer_txer.send_and_ping(msg_tx(tx))
77+
self.nodes[0].disconnect_p2ps()
78+
3379
# Come out of IBD by generating a block
3480
self.generate(self.nodes[0], 1)
3581

@@ -38,6 +84,11 @@ def run_test(self):
3884
assert not node.getblockchaininfo()['initialblockdownload']
3985
self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo()))
4086

87+
self.log.info("Check that nodes process the same transaction, even when unsolicited, when no longer in IBD")
88+
peer_txer = self.nodes[0].add_p2p_connection(P2PInterface())
89+
# ELEMENTS FIXME:
90+
# with self.nodes[0].assert_debug_log(expected_msgs=["was not accepted"]):
91+
#peer_txer.send_and_ping(msg_tx(tx))
4192

4293
if __name__ == '__main__':
4394
P2PIBDTxRelayTest().main()

test/functional/test_framework/p2p.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
P2P_SUBVERSION = "/python-p2p-tester:0.0.3/"
9090
# Value for relay that this test framework sends in its `version` message
9191
P2P_VERSION_RELAY = 1
92+
# Delay after receiving a tx inv before requesting transactions from non-preferred peers, in seconds
93+
NONPREF_PEER_TX_DELAY = 2
9294

9395
MESSAGEMAP = {
9496
b"addr": msg_addr,

0 commit comments

Comments
 (0)