Skip to content

Commit

Permalink
Add test for param interaction b/w -blocksonly and -whitelistforcerelay
Browse files Browse the repository at this point in the history
Summary:
Updated comment for the condition where a transaction relay is denied

This is a backport of Core [[bitcoin/bitcoin#18530 | PR18530]]

Test Plan: test/functional/test_runner.py p2p_blocksonly

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9145
  • Loading branch information
glowang authored and PiRK committed Feb 8, 2021
1 parent 50f24cc commit 5abc699
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,9 +3333,8 @@ void PeerManager::ProcessMessage(const Config &config, CNode &pfrom,

if (msg_type == NetMsgType::TX) {
// Stop processing the transaction early if
// We are in blocks only mode and peer is either not whitelisted or
// whitelistrelay is off or if this peer is supposed to be a
// block-relay-only peer
// 1) We are in blocks only mode and peer has no relay permission
// 2) This peer is a block-relay-only peer
if ((!g_relay_txes && !pfrom.HasPermission(PF_RELAY)) ||
(pfrom.m_tx_relay == nullptr)) {
LogPrint(BCLog::NET,
Expand Down
38 changes: 38 additions & 0 deletions test/functional/p2p_blocksonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,44 @@ def run_test(self):
self.nodes[0].p2p.wait_for_tx(txid)
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)

self.log.info(
'Check that txs from whitelisted peers are not rejected and relayed to others')
self.log.info(
"Restarting node 0 with whitelist permission and blocksonly")
self.restart_node(0,
["-persistmempool=0",
"-whitelist=127.0.0.1",
"-whitelistforcerelay",
"-blocksonly"])
assert_equal(self.nodes[0].getrawmempool(), [])
first_peer = self.nodes[0].add_p2p_connection(P2PInterface())
second_peer = self.nodes[0].add_p2p_connection(P2PInterface())
peer_1_info = self.nodes[0].getpeerinfo()[0]
assert_equal(peer_1_info['whitelisted'], True)
assert_equal(
peer_1_info['permissions'], [
'noban', 'forcerelay', 'relay', 'mempool'])
peer_2_info = self.nodes[0].getpeerinfo()[1]
assert_equal(peer_2_info['whitelisted'], True)
assert_equal(
peer_2_info['permissions'], [
'noban', 'forcerelay', 'relay', 'mempool'])
assert_equal(
self.nodes[0].testmempoolaccept(
[sigtx])[0]['allowed'], True)
txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid']

self.log.info(
'Check that the tx from whitelisted first_peer is relayed to others (ie.second_peer)')
with self.nodes[0].assert_debug_log(["received getdata"]):
first_peer.send_message(msg_tx(FromHex(CTransaction(), sigtx)))
self.log.info(
'Check that the whitelisted peer is still connected after sending the transaction')
assert_equal(first_peer.is_connected, True)
second_peer.wait_for_tx(txid)
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
self.log.info("Whitelisted peer's transaction is accepted and relayed")


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

0 comments on commit 5abc699

Please sign in to comment.