Merge #16631: net: The default whitelistrelay should be true

3b05f0f70fbaee5b5eaa0d1b6f3b9d32f44410bb Reformat p2p_permissions.py (nicolas.dorier)
ce7eac3cb0e7d301db75de24e9a7b0af93c61311 [Fix] The default whitelistrelay should be true (nicolas.dorier)

Pull request description:

  I thought `whitelistrelay` default was `false` when it is `true`.

  The root of the issue come from the fact that all references to `DEFAULT_` are not in the scope of this file, so hard coding of default values are used everywhere in `net.cpp`. I think that in a separate PR we should fix that more fundamentally everywhere.

ACKs for top commit:
  promag:
    ACK 3b05f0f70fbaee5b5eaa0d1b6f3b9d32f44410bb.
  Sjors:
    re-ACK 3b05f0f70fbaee5b5eaa0d1b6f3b9d32f44410bb

Tree-SHA512: f4a75f986fa2adf1a5f1c91605e0d261f7ac5ac8535fb05437d83b8392dbcf5cc1a47d755adcf8ad8dc67a88de28060187200fd3ce06545261a5c7ec0fea831a
This commit is contained in:
Wladimir J. van der Laan 2019-08-19 11:18:47 +02:00 committed by pasta
parent 92bfe50955
commit 909a13082f
5 changed files with 43 additions and 36 deletions

View File

@ -1023,8 +1023,8 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
bool legacyWhitelisted = false; bool legacyWhitelisted = false;
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_ISIMPLICIT)) { if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_ISIMPLICIT)) {
NetPermissions::ClearFlag(permissionFlags, PF_ISIMPLICIT); NetPermissions::ClearFlag(permissionFlags, PF_ISIMPLICIT);
if (gArgs.GetBoolArg("-whitelistforcerelay", false)) NetPermissions::AddFlag(permissionFlags, PF_FORCERELAY); if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permissionFlags, PF_FORCERELAY);
if (gArgs.GetBoolArg("-whitelistrelay", false)) NetPermissions::AddFlag(permissionFlags, PF_RELAY); if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(permissionFlags, PF_RELAY);
NetPermissions::AddFlag(permissionFlags, PF_MEMPOOL); NetPermissions::AddFlag(permissionFlags, PF_MEMPOOL);
NetPermissions::AddFlag(permissionFlags, PF_NOBAN); NetPermissions::AddFlag(permissionFlags, PF_NOBAN);
legacyWhitelisted = true; legacyWhitelisted = true;

View File

@ -49,6 +49,11 @@ class CScheduler;
class CNode; class CNode;
class BanMan; class BanMan;
/** Default for -whitelistrelay. */
static const bool DEFAULT_WHITELISTRELAY = true;
/** Default for -whitelistforcerelay. */
static const bool DEFAULT_WHITELISTFORCERELAY = true;
/** Time between pings automatically sent out for latency probing and keepalive (in seconds). */ /** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
static const int PING_INTERVAL = 2 * 60; static const int PING_INTERVAL = 2 * 60;
/** Time after which to disconnect, after waiting for a ping response (or inactivity). */ /** Time after which to disconnect, after waiting for a ping response (or inactivity). */

View File

@ -48,10 +48,6 @@ struct ChainTxData;
struct LockPoints; struct LockPoints;
/** Default for -whitelistrelay. */
static const bool DEFAULT_WHITELISTRELAY = true;
/** Default for -whitelistforcerelay. */
static const bool DEFAULT_WHITELISTFORCERELAY = true;
/** Default for -minrelaytxfee, minimum relay fee for transactions */ /** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
//! -maxtxfee default //! -maxtxfee default

66
test/functional/p2p_permissions.py Normal file → Executable file
View File

@ -23,18 +23,24 @@ class P2PPermissionsTests(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.checkpermission( self.checkpermission(
# relay permission added # default permissions (no specific permissions)
["-whitelist=127.0.0.1", "-whitelistrelay"], ["-whitelist=127.0.0.1"],
["relay", "noban", "mempool"], ["relay", "noban", "mempool"],
True) True)
self.checkpermission( self.checkpermission(
# forcerelay and relay permission added # relay permission removed (no specific permissions)
# Legacy parameter interaction which set whitelistrelay to true ["-whitelist=127.0.0.1", "-whitelistrelay=0"],
# if whitelistforcerelay is true ["noban", "mempool"],
["-whitelist=127.0.0.1", "-whitelistforcerelay"], True)
["forcerelay", "relay", "noban", "mempool"],
True) self.checkpermission(
# forcerelay and relay permission added
# Legacy parameter interaction which set whitelistrelay to true
# if whitelistforcerelay is true
["-whitelist=127.0.0.1", "-whitelistforcerelay"],
["forcerelay", "relay", "noban", "mempool"],
True)
# Let's make sure permissions are merged correctly # Let's make sure permissions are merged correctly
# For this, we need to use whitebind instead of bind # For this, we need to use whitebind instead of bind
@ -42,35 +48,35 @@ class P2PPermissionsTests(BitcoinTestFramework):
ip_port = "127.0.0.1:{}".format(p2p_port(1)) ip_port = "127.0.0.1:{}".format(p2p_port(1))
self.replaceinconfig(1, "bind=127.0.0.1", "whitebind=bloomfilter,forcerelay@" + ip_port) self.replaceinconfig(1, "bind=127.0.0.1", "whitebind=bloomfilter,forcerelay@" + ip_port)
self.checkpermission( self.checkpermission(
["-whitelist=noban@127.0.0.1" ], ["-whitelist=noban@127.0.0.1" ],
# Check parameter interaction forcerelay should activate relay # Check parameter interaction forcerelay should activate relay
["noban", "bloomfilter", "forcerelay", "relay" ], ["noban", "bloomfilter", "forcerelay", "relay" ],
False) False)
self.replaceinconfig(1, "whitebind=bloomfilter,forcerelay@" + ip_port, "bind=127.0.0.1") self.replaceinconfig(1, "whitebind=bloomfilter,forcerelay@" + ip_port, "bind=127.0.0.1")
self.checkpermission( self.checkpermission(
# legacy whitelistrelay should be ignored # legacy whitelistrelay should be ignored
["-whitelist=noban,mempool@127.0.0.1", "-whitelistrelay"], ["-whitelist=noban,mempool@127.0.0.1", "-whitelistrelay"],
["noban", "mempool"], ["noban", "mempool"],
False) False)
self.checkpermission( self.checkpermission(
# legacy whitelistforcerelay should be ignored # legacy whitelistforcerelay should be ignored
["-whitelist=noban,mempool@127.0.0.1", "-whitelistforcerelay"], ["-whitelist=noban,mempool@127.0.0.1", "-whitelistforcerelay"],
["noban", "mempool"], ["noban", "mempool"],
False) False)
self.checkpermission( self.checkpermission(
# missing mempool permission to be considered legacy whitelisted # missing mempool permission to be considered legacy whitelisted
["-whitelist=noban@127.0.0.1"], ["-whitelist=noban@127.0.0.1"],
["noban"], ["noban"],
False) False)
self.checkpermission( self.checkpermission(
# all permission added # all permission added
["-whitelist=all@127.0.0.1"], ["-whitelist=all@127.0.0.1"],
["forcerelay", "noban", "mempool", "bloomfilter", "relay"], ["forcerelay", "noban", "mempool", "bloomfilter", "relay"],
False) False)
self.stop_node(1) self.stop_node(1)
self.nodes[1].assert_start_raises_init_error(["-whitelist=oopsie@127.0.0.1"], "Invalid P2P permission", match=ErrorMatch.PARTIAL_REGEX) self.nodes[1].assert_start_raises_init_error(["-whitelist=oopsie@127.0.0.1"], "Invalid P2P permission", match=ErrorMatch.PARTIAL_REGEX)

0
test/functional/rpc_setban.py Normal file → Executable file
View File