Skip to content

Commit fa66a7d

Browse files
author
MarcoFalke
committed
p2p: Rename fBlocksOnly, Add test
The new name describes better what the bool does and also limits the confusion of the three different concepts: * fBlocksOnly (This bool to skip tx invs) * -blocksonly (A setting to ignore incoming txs) * block-relay-only (A connection type in the block-relay-only P2P graph)
1 parent fac66d0 commit fa66a7d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,13 +2909,13 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
29092909
return;
29102910
}
29112911

2912-
// We won't accept tx inv's if we're in blocks-only mode, or this is a
2912+
// Reject tx INVs when the -blocksonly setting is enabled, or this is a
29132913
// block-relay-only peer
2914-
bool fBlocksOnly = m_ignore_incoming_txs || (pfrom.m_tx_relay == nullptr);
2914+
bool reject_tx_invs{m_ignore_incoming_txs || (pfrom.m_tx_relay == nullptr)};
29152915

29162916
// Allow peers with relay permission to send data other than blocks in blocks only mode
29172917
if (pfrom.HasPermission(NetPermissionFlags::Relay)) {
2918-
fBlocksOnly = false;
2918+
reject_tx_invs = false;
29192919
}
29202920

29212921
LOCK(cs_main);
@@ -2954,7 +2954,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
29542954
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
29552955

29562956
pfrom.AddKnownTx(inv.hash);
2957-
if (fBlocksOnly) {
2957+
if (reject_tx_invs) {
29582958
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom.GetId());
29592959
pfrom.fDisconnect = true;
29602960
return;

test/functional/p2p_blocksonly.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import time
88

9-
from test_framework.messages import msg_tx
9+
from test_framework.messages import msg_tx, msg_inv, CInv, MSG_WTX
1010
from test_framework.p2p import P2PInterface, P2PTxInvStore
1111
from test_framework.test_framework import BitcoinTestFramework
1212
from test_framework.util import assert_equal
@@ -33,12 +33,19 @@ def blocksonly_mode_tests(self):
3333
self.nodes[0].add_p2p_connection(P2PInterface())
3434
tx, txid, wtxid, tx_hex = self.check_p2p_tx_violation()
3535

36+
self.log.info('Check that tx invs also violate the protocol')
37+
self.nodes[0].add_p2p_connection(P2PInterface())
38+
with self.nodes[0].assert_debug_log(['transaction (0000000000000000000000000000000000000000000000000000000000001234) inv sent in violation of protocol, disconnecting peer']):
39+
self.nodes[0].p2ps[0].send_message(msg_inv([CInv(t=MSG_WTX, h=0x1234)]))
40+
self.nodes[0].p2ps[0].wait_for_disconnect()
41+
del self.nodes[0].p2ps[0]
42+
3643
self.log.info('Check that txs from rpc are not rejected and relayed to other peers')
3744
tx_relay_peer = self.nodes[0].add_p2p_connection(P2PInterface())
3845
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True)
3946

4047
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True)
41-
with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer=1'.format(wtxid)]):
48+
with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer'.format(wtxid)]):
4249
self.nodes[0].sendrawtransaction(tx_hex)
4350
tx_relay_peer.wait_for_tx(txid)
4451
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)

0 commit comments

Comments
 (0)