Reported by @MarcoFalke on #16248 (review)
The bug would mean that if the peer connecting to you is banned, but whitelisted without specific permissions, it would not be able to connect to the node.
The solution is just to move the same line below.
Reported by @MarcoFalke on #16248 (review)
The bug would mean that if the peer connecting to you is banned, but whitelisted without specific permissions, it would not be able to connect to the node.
The solution is just to move the same line below.
Is this safe to do? What are the implications of connecting to a peer that would otherwise be banned?
@gapeman afaik that was the behavior before #16248 (which was not supposed to change existing behavior). @NicolasDorier would be nice to have a test for this.
I refactored it to properly scope some variables. Writing a test so such regression can't happen.
Fixed the bug, and added an anti regression test for setban
utACK a0d2e2b
0 | @@ -0,0 +1,44 @@ 1 | +#!/usr/bin/env python3 2 | +# Copyright (c) 2015-2019 The Bitcoin Core developers 3 | +# Distributed under the MIT software license, see the accompanying 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | +"""Test the setban rpc call.""" 6 | + 7 | +from test_framework.test_node import ErrorMatch
test/functional/rpc_setban.py:7:1: F401 'test_framework.test_node.ErrorMatch' imported but unused
test/functional/rpc_setban.py:39:78: F821 undefined name 'p'
test/functional/rpc_setban.py:41:75: F821 undefined name 'p'
30 | + # Node 1 should be able to reconnect if it has noban permission 31 | + self.restart_node(1, ['-whitelist=127.0.0.1']) 32 | + connect_nodes(self.nodes[0], 1) 33 | + self.assert_has_permission('noban', True) 34 | + 35 | + def assert_has_permission(self, permission, contains):
Maybe pass node in directly and split into assert_has_permission(self, node, permission) and assert_has_no_permission(self, node, permission)
what about assert_equal(True, self.hasPermision(...)) ?
That said, I don't think it should pass the nodes to this method. It is confusing (there is two nodes: the node that is permissioned, and the node on which we want to check permissions).
assert(self.hasPermision(...)) is even simpler.
You could pass both nodes. Or you could document at the top of the test file which hardcoded nodes do what.
Sorry but I think you could just inline this - it's longer as it is with the contains arg.
Travis failed due to lint issue. Maybe rename rpc_setban.py to p2p_whitelist.py?
ACK
As @promag suggested, I instead just inlined the permission checked, it is actually more readable.
I also check in the logs that we really prevent connection because of the ban. I also added a test to setban x remove.
@Sjors rpc_setban is the right name, I really want to test setban, so I added it in the whitelist of authorized term.
Agree inline is more clear. utACK d117f45
ACK d117f4541d4717e83c9396273e92960723622030
<details><summary>Show signature and timestamp</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK d117f4541d4717e83c9396273e92960723622030
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUin2gv9GZKDSUbn62676zj0G6Igb8tzgC2M1Sf2KyEuIR+heCoVYGlyp3rXDbuc
22c5dyDXDnktsyMR3mwo3KLzT/MBY/wc8nDgdzkRUzWt6j+/q8Ex8NTnfbgyGXzr
vBE3bJOfA1y3DCCzpSar4uU/sPUAK+oJ3qF1+62rijDYpC0Jh1UaYMy7AdYQdYQ/
kyO3jorAiwIk0sE7SzJDq3rE7wlHzQ4LCZauCnVft/Y1rOY1IkmYfke3uapR4EVr
Zw7D40jY6RsEDLNh/1odaRqjm01v1uJ5d7mFnqOFCKA7RwdS2NQ0ElbfQ3fAUowm
V7Oola76XE8OvGsj9y+qOwBkX5iMgeNQANb+Pf6poB0ANDh0AKpIkxjSIGGbhKi2
XN9KGRaHLpNBeU69lQDrvsXEzyfl4kSLyO9/k7+qZAtgUTqyLDhi9beqS9Ta0OKF
X7RHymgGIn1zvTOY4WSoPiHIF5ceVDu9S5r/fxr9DHmwPWWEzOE9ztfcSiQw68tY
HRrWUvc+
=qI3j
-----END PGP SIGNATURE-----
Timestamp of file with hash 74a14b73630691da8ffa64e5b597d7fd7246787327bba54579da5c03c881ec01 -
</details>
Milestone
0.19.0