Skip to content

Commit 63c0d0e

Browse files
committed
Merge bitcoin#21327: net_processing: ignore transactions while in IBD
6aed8b7 [test] tx processing before and after ibd (glozow) b9e105b [net_processing] ignore all transactions during ibd (glozow) Pull request description: This is basically a mini, IBD-only version of bitcoin#21224 Incoming transactions aren't really relevant until we're caught up. That's why we send a giant feefilter and don't send tx getdatas, but we also shouldn't process them if peers send them anyway. Simply ignore them. ACKs for top commit: jnewbery: reACK 6aed8b7 laanwj: Code review ACK 6aed8b7 Tree-SHA512: 8e1616bf355f9d0b180bdbc5461f24c757dc5d7bc7bf651470f3b0bffcca5d5e68287106255b5cede2d96b42bce448a0f8c0649de35a530c5e079f7c89c70a35
2 parents ffdf8ee + 6aed8b7 commit 63c0d0e

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32063206
return;
32073207
}
32083208

3209+
// Stop processing the transaction early if we are still in IBD since we don't
3210+
// have enough information to validate it yet. Sending unsolicited transactions
3211+
// is not considered a protocol violation, so don't punish the peer.
3212+
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) return;
3213+
32093214
CTransactionRef ptx;
32103215
vRecv >> ptx;
32113216
const CTransaction& tx = *ptx;

test/functional/p2p_ibd_txrelay.py

Lines changed: 50 additions & 2 deletions
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
MAX_FEE_FILTER = Decimal(9170997) / COIN
@@ -28,6 +47,31 @@ def run_test(self):
2847
assert node.getblockchaininfo()['initialblockdownload']
2948
self.wait_until(lambda: all(peer['minfeefilter'] == MAX_FEE_FILTER for peer in node.getpeerinfo()))
3049

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

@@ -36,6 +80,10 @@ def run_test(self):
3680
assert not node.getblockchaininfo()['initialblockdownload']
3781
self.wait_until(lambda: all(peer['minfeefilter'] == NORMAL_FEE_FILTER for peer in node.getpeerinfo()))
3882

83+
self.log.info("Check that nodes process the same transaction, even when unsolicited, when no longer in IBD")
84+
peer_txer = self.nodes[0].add_p2p_connection(P2PInterface())
85+
with self.nodes[0].assert_debug_log(expected_msgs=["was not accepted"]):
86+
peer_txer.send_and_ping(msg_tx(tx))
3987

4088
if __name__ == '__main__':
4189
P2PIBDTxRelayTest().main()

test/functional/test_framework/p2p.py

Lines changed: 2 additions & 0 deletions
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)