-
Notifications
You must be signed in to change notification settings - Fork 38.2k
rpc, p2p: allow disconnectnode with subnet
#26576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
This changes the behavior of |
I think this is the same logic for E.g.: diff --git a/test/functional/p2p_disconnect_ban.py b/test/functional/p2p_disconnect_ban.py
index 0acb5abac..f90a14cdb 100755
--- a/test/functional/p2p_disconnect_ban.py
+++ b/test/functional/p2p_disconnect_ban.py
@@ -13,7 +13,7 @@ from test_framework.util import (
class DisconnectBanTest(BitcoinTestFramework):
def set_test_params(self):
- self.num_nodes = 2
+ self.num_nodes = 3
self.supports_cli = False
def run_test(self):
@@ -27,7 +27,7 @@ class DisconnectBanTest(BitcoinTestFramework):
self.log.info("Test setban and listbanned RPCs")
self.log.info("setban: successfully ban single IP address")
- assert_equal(len(self.nodes[1].getpeerinfo()), 2) # node1 should have 2 connections to node0 at this point
+ assert_equal(len(self.nodes[1].getpeerinfo()), 3) # node1 should have 2 connections to node0 at this point
self.nodes[1].setban(subnet="127.0.0.1", command="add")
self.wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0, timeout=10)
assert_equal(len(self.nodes[1].getpeerinfo()), 0) # all nodes must be disconnected at this point
@@ -123,6 +123,7 @@ class DisconnectBanTest(BitcoinTestFramework):
assert not [node for node in self.nodes[0].getpeerinfo() if node['id'] == id1]
self.log.info("disconnectnode: successfully disconnect node by subnet")
+ self.connect_nodes(0, 2)
self.nodes[0].disconnectnode(address='127.0.0.1/24')
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0, timeout=10) |
dergoegge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~0 I don't really see the use case here. What would be the reason for disconnecting by subnet besides banning spammy peers? In that case setban seems more appropriate.
This also seems out of scope for the disconnectnode rpc as it is meant (judging by the name and api right now) to disconnect a single node.
|
Concept ACK |
Its about providing options. Alice could disconnect a subnet and Bob could could ban same subnet for 1 hour. |
Alice could just ban for a couple seconds to achieve the same, no? |
Yes. Although I am not aware if its possible using bitcoin-qt (GUI) |
fcd014a to
23f4c2c
Compare
I use |
|
@brunoerg you can already achieve that by using e.g. disconnects you from a subnet by banning it for 1 second. |
It seems a bad UX for me, if I want to disconnect, what comes to my mind is the |
|
Concept ACK I would recommend updating the description with a more clear use case, as I also wasn't convinced this was a good change until I read through the discussion and saw your comments @brunoerg
Counter argument: as mentioned in the description, Lines 826 to 829 in 38d06e1
so why not make the RPC expose the full functionality? I think I'd be more annoyed if I saw that I think disconnecting from all ports on the same IP seems like a compelling enough use case for a very small change. EDIT:
It would be great to see some of these listed in the description as well |
|
@josibake thank you, I just updated the description.
Yea, I only opened this one because the change would be really small, and since |
josibake
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crACK 23f4c2c
| "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n", | ||
| { | ||
| {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"}, | ||
| {"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node or subnet"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great to add an example for subnets in the help section below.
| Updated RPCs | ||
| ---------- | ||
|
|
||
| - RPC `disconnectnode` now accepts a subnet into `address` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The release notes could be a bit more detailed, maybe mentioning that this aligns DisconnectNode and the disconnectnode rpc. It's nice to have at least a summary of the motivation in the release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe mentioning that this aligns DisconnectNode and the disconnectnode rpc.
Internal APIs really don't seem like they belong here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth to mention this in a release note, seems like a specific code nuance to be exposed. Isn't it?
| } else { | ||
| success = connman.DisconnectNode(address_arg.get_str()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not drop this entirely? Seems like a bug specifying an IP won't disconnect all nodes connecting from that IP...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, maybe this should be split into a bugfix commit before adding subnet support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's really a bug. It seems like this was the expected behavior (due to examples and docs - e.g. having to specify port). However, I also think it should be able to disconnect all nodes from an IP. I'm gonna address it.
|
This PR does not seem to have conceptual support. Please leave a comment if you would like this to be reopened. |
Maybe update the doc to mention the alternative command for this use case? |
SGTM |
Github-Pull: bitcoin#26576 Rebased-From: b2e3edc
Github-Pull: bitcoin#26576 Rebased-From: ad39ede
Since
disconnectnodefunction allows to be used with a subnet, e.g.:bitcoin/src/net.h
Lines 826 to 829 in 38d06e1
bitcoin/src/net.cpp
Lines 2589 to 2601 in 38d06e1
This PR adds support for
subnetinaddressparameter indisconnectnodeRPC. When passing a string with/inaddress, it is gonna recognize it as asubnet.. It allows us to disconnect multiple nodes from all ports on the same IP. The only way to do it before was banning them for 1sec which seems a bad UX.Also, when there are multiples nodes connected to a node in a functional test and we want to disconnect them all, we could call
disconnectnodewith a subnet instead of callingdisconnect_nodesmultiple times.A simple example: