Skip to content

Conversation

brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Nov 1, 2022

Built this PR on top of #17167 (that's been closed due to inactivity but had some Concept ACK). So, it allows whitelisting outbound peers.

This PR adds a new RPC addpermissionflags to be able to set up permission flags -whitelist thru RPC, so we don't need to restart our node if we want to add new flags.

E.g.

$ ./src/bitcoin-cli addpermissionflags ["noban", "mempool", "in", "out"] "127.0.0.1"

@brunoerg brunoerg changed the title rpc, p2p: allow whitelisting outgoing connections (17167) + add addwhitelist RPC rpc, p2p: add addwhitelist RPC Nov 1, 2022
@brunoerg brunoerg force-pushed the 2022-10-whitelist-rpc branch 2 times, most recently from 0220d6c to d14fbaa Compare November 1, 2022 19:23
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 1, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK stickies-v, hernanmarino
Approach ACK pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27114 (p2p: Allow whitelisting outgoing connections by brunoerg)
  • #26988 (rpc: Add test-only RPC getaddrmaninfo for new/tried table address count by stratospher)
  • #26837 (I2P network optimizations by vasild)
  • #25515 (net, test: Virtualise CConnman and add initial PeerManager unit tests by dergoegge)
  • #24748 (test/BIP324: functional tests for v2 P2P encryption by stratospher)
  • #24545 (BIP324: Enable v2 P2P encrypted transport by dhruv)
  • #17783 (util: Fix -norpcwhitelist, -norpcallowip, and similar corner case behavior by ryanofsky)
  • #17581 (refactor: Remove settings merge reverse precedence code by ryanofsky)
  • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
  • #17493 (util: Forbid ambiguous multiple assignments in config file by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to specify as [String "IP" or Number nodeid, [list of permissions], [list of permissions to remove]] or similar.

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK-ish, in that whitelisting shouldn't require a node restart.

Where I'm not 100% sure (as commented), is that this conceptually feels much more like a persistent setting instead of the ephemeral nature (i.e. effect gone after node restart) that these RPC commands have. Could be a source of confusion?

src/rpc/net.cpp Outdated
@@ -272,6 +272,49 @@ static RPCHelpMan getpeerinfo()
};
}

static RPCHelpMan addwhitelist()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question rather than a suggestion: should the docs highlight that these permissions do not persist beyond a node reboot? Intuitively, I'd have expected this kind of effect to be persistent, so maybe highlighting that is useful if I'm not the only one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intuitive for me these permissions aren't persistent since there is no way to remove them (thinking about a follow-up adding an option for removal in this RPC), but sounds goods for me to add it in the docs to clarify.

@@ -104,11 +117,11 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
return true;
}

bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error)
bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of adding extra out-parameters, I think util::Result would be more appropriate here (but also a bit of an overhaul so wouldn't be opposed to doing it in follow-up)

@brunoerg brunoerg marked this pull request as draft November 8, 2022 14:17
@brunoerg
Copy link
Contributor Author

brunoerg commented Nov 8, 2022

I changed it to draft to work on some stuff some reviewers suggested here. Gonna advertise when it ready for review.

@brunoerg brunoerg force-pushed the 2022-10-whitelist-rpc branch from cf50266 to 174d746 Compare November 11, 2022 19:10
@brunoerg brunoerg force-pushed the 2022-10-whitelist-rpc branch from 174d746 to df5d400 Compare November 11, 2022 19:36
@brunoerg brunoerg changed the title rpc, p2p: add addwhitelist RPC rpc, p2p: add addpermissionflags RPC Nov 11, 2022
@brunoerg brunoerg force-pushed the 2022-10-whitelist-rpc branch from df5d400 to 153e86e Compare November 12, 2022 14:19
@brunoerg
Copy link
Contributor Author

Force-pushed changing the approach and addressing reviews!

static RPCHelpMan addpermissionflags()
{
return RPCHelpMan{"addpermissionflags",
"\nAdd permission flags to the peers using the given IP address (e.g. 1.2.3.4) or\n"
Copy link

@codo1 codo1 Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took a while before I realized the added permission flags are only applied to new peers (connecting after the rpc command). Not sure if that should have been obvious to me. Maybe change "peers" to "future peers" or something similar?

@brunoerg brunoerg changed the title rpc, p2p: add addpermissionflags RPC rpc, p2p: add addpermissionflags RPC and allow whitelisting outbound Feb 13, 2023
Comment on lines 996 to 1001
// Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds).
std::vector<NetWhitelistPermissions> vWhitelistedRange;
// Whitelisted ranges for outgoing connections.
std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that making the members public is good, it breaks the class encapsulation and allows multiple threads to access/modify the fields without any contention (read/write operations should be guarded).

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK, run automated tests (unit, functional & fuzz), pending of manual testing.

Regarding whitelisting outbound connections found some comments from @gmaxwell & @laanwj here.

Please add "Review club" label (*).

Copy link
Contributor

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review more soon, but here are a couple of instances where changes are not in the correct commits. Each commit should compile (and all tests should pass, but I didn't check that).

Copy link
Contributor

@hernanmarino hernanmarino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested ACK. This might help with a couple of functional tests.

@brunoerg brunoerg marked this pull request as draft February 16, 2023 20:31
@brunoerg
Copy link
Contributor Author

Converted it to draft to address suggestions and re-build it on top of #27114.

@@ -21,9 +21,10 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
namespace {

// Parse the following format: "perm1,perm2@xxxxxx"
bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, size_t& readen, bilingual_str& error)
bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, ConnectionDirection* output_connection_direction, size_t& readen, bilingual_str& error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: while the other parameter is output_connection_direction, isn't it good idea to change output to output_permission_flags or output_permissions?

@@ -85,7 +98,7 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
{
NetPermissionFlags flags;
size_t offset;
if (!TryParsePermissionFlags(str, flags, offset, error)) return false;
if (!TryParsePermissionFlags(str, flags, nullptr, offset, error)) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why not using ConnectionDirection::None rather than nullptr to make it more clear?

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

2 similar comments
@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@brunoerg
Copy link
Contributor Author

Closing it to focus on other approach.

@brunoerg brunoerg closed this Jan 12, 2024
@bitcoin bitcoin locked and limited conversation to collaborators Jan 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.