Skip to content

Commit cfe22a5

Browse files
author
MarcoFalke
committed
Merge #18530: Add test for -blocksonly and -whitelistforcerelay param interaction
0ea5d70 Updated comment for the condition where a transaction relay is denied (glowang) be01449 Add test for param interaction b/w -blocksonly and -whitelistforcerelay (glowang) Pull request description: Related to: #18428 When -blocksonly is turned on, a node would still relay transactions from whitelisted peers. This funcitonality has not been tested. ACKs for top commit: MarcoFalke: ACK 0ea5d70 Tree-SHA512: 4e99c88281cb518cc67f5f3be7171a7b413933047b5d24a04bb3ff2210a82e914d69079f64cd5bac9206ec435e21a622c8e69cedbc2ccb39d2328ac5c01668e5
2 parents 25ad2c6 + 0ea5d70 commit cfe22a5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,8 +2675,8 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
26752675

26762676
if (msg_type == NetMsgType::TX) {
26772677
// Stop processing the transaction early if
2678-
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
2679-
// or if this peer is supposed to be a block-relay-only peer
2678+
// 1) We are in blocks only mode and peer has no relay permission
2679+
// 2) This peer is a block-relay-only peer
26802680
if ((!g_relay_txes && !pfrom->HasPermission(PF_RELAY)) || (pfrom->m_tx_relay == nullptr))
26812681
{
26822682
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());

test/functional/p2p_blocksonly.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ def run_test(self):
5757
self.nodes[0].p2p.wait_for_tx(txid)
5858
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
5959

60+
self.log.info('Check that txs from whitelisted peers are not rejected and relayed to others')
61+
self.log.info("Restarting node 0 with whitelist permission and blocksonly")
62+
self.restart_node(0, ["-persistmempool=0", "-whitelist=127.0.0.1", "-whitelistforcerelay", "-blocksonly"])
63+
assert_equal(self.nodes[0].getrawmempool(),[])
64+
first_peer = self.nodes[0].add_p2p_connection(P2PInterface())
65+
second_peer = self.nodes[0].add_p2p_connection(P2PInterface())
66+
peer_1_info = self.nodes[0].getpeerinfo()[0]
67+
assert_equal(peer_1_info['whitelisted'], True)
68+
assert_equal(peer_1_info['permissions'], ['noban', 'forcerelay', 'relay', 'mempool'])
69+
peer_2_info = self.nodes[0].getpeerinfo()[1]
70+
assert_equal(peer_2_info['whitelisted'], True)
71+
assert_equal(peer_2_info['permissions'], ['noban', 'forcerelay', 'relay', 'mempool'])
72+
assert_equal(self.nodes[0].testmempoolaccept([sigtx])[0]['allowed'], True)
73+
txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid']
74+
75+
self.log.info('Check that the tx from whitelisted first_peer is relayed to others (ie.second_peer)')
76+
with self.nodes[0].assert_debug_log(["received getdata"]):
77+
first_peer.send_message(msg_tx(FromHex(CTransaction(), sigtx)))
78+
self.log.info('Check that the whitelisted peer is still connected after sending the transaction')
79+
assert_equal(first_peer.is_connected, True)
80+
second_peer.wait_for_tx(txid)
81+
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
82+
self.log.info("Whitelisted peer's transaction is accepted and relayed")
6083

6184
if __name__ == '__main__':
6285
P2PBlocksOnly().main()

0 commit comments

Comments
 (0)