Skip to content

Conversation

@brunoerg
Copy link
Contributor

This PR:

  • Adds test coverage for an invalid command in addnode.
  • Rename test_getaddednodeinfo to test_addnode_getaddednodeinfo and its log since this function also tests addnode and it doesn't worth to split into 2 ones.
  • Makes it clear in docs that node in addnode refers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id.
  • Some small improv/clean-up: use const where possible, rename some vars, and remove the check for nullance for command since it's a non-optional field.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 22, 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
ACK jonatack, theStack, achow101

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:

  • #28331 (BIP324 integration by sipa)
  • #24748 (test/BIP324: functional tests for v2 P2P encryption by stratospher)

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.

@brunoerg brunoerg changed the title p2p, rpc, test: getpeerinfo clean-ups + add test coverage for invalid command p2p, rpc, test: getpeerinfo improv + add test coverage for invalid command Oct 28, 2022
@achow101 achow101 requested a review from mzumsande April 25, 2023 15:20
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK 40660d517022b30e3ab4dcf852a6c86502fa97f3

@brunoerg
Copy link
Contributor Author

CI failure seems unrelated to these changes.

@maflcko
Copy link
Member

maflcko commented May 30, 2023

CI failure seems unrelated to these changes.

Thanks, fixed in #27777

@brunoerg brunoerg changed the title p2p, rpc, test: getpeerinfo improv + add test coverage for invalid command p2p, rpc, test: addnode improv + add test coverage for invalid command May 31, 2023
@brunoerg brunoerg force-pushed the 2022-10-getpeerinfo-improv branch from 40660d5 to c2349d6 Compare May 31, 2023 23:43
@brunoerg brunoerg requested a review from theStack August 1, 2023 14:12
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK c2349d6a04832d9c96a8746fc588bae8fc85376d

The only change since my last ACK was adapting the first commit's subject (s/getpeerinfo/addnode/). Sorry for late re-review, I must have missed the force-push two months ago.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK c2349d6a04832d9c96a8746fc588bae8fc85376d

some non-blocking suggestions

Edit: suggest dropping "p2p" from the PR title and the first commit title.

1. Use const where possible;
2. Rename variables to make them clearer;
3. There is no need to check whether `command` is null since it's a non-optional field.
@brunoerg brunoerg force-pushed the 2022-10-getpeerinfo-improv branch from c2349d6 to f52cb02 Compare August 2, 2023 13:31
@brunoerg brunoerg changed the title p2p, rpc, test: addnode improv + add test coverage for invalid command rpc, test: addnode improv + add test coverage for invalid command Aug 2, 2023
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK f52cb02

Two non-blocking suggestions.

self.nodes[0].addnode(node=ip_port, command='remove')
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# check that an invalid command returns an error
assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port, command='abc')
Copy link
Member

Choose a reason for hiding this comment

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

"remove the check for nullance for command since it's a non-optional field"

while here, maybe test that assertion

-        # check that an invalid command returns an error
+        # check that an invalid or missing command returns an error
         assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port, command='abc')
+        assert_raises_rpc_error(-1, 'addnode "node" "command"', self.nodes[0].addnode, node=ip_port)

if (!connman.RemoveAddedNode(strNode)) {
if (!connman.RemoveAddedNode(node_arg)) {
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
}
Copy link
Member

Choose a reason for hiding this comment

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

suggestion while touching this

-    if (command == "onetry")
-    {
+    if (command == "onetry") {
         CAddress addr;
         connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL);
         return UniValue::VNULL;
-    }
-
-    if (command == "add")
-    {
+    } elsif (command == "add") {
         if (!connman.AddNode(node_arg)) {
             throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
         }
-    }
-    else if (command == "remove")
-    {
+    } else if (command == "remove") {
         if (!connman.RemoveAddedNode(node_arg)) {
             throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
         }

@DrahtBot DrahtBot requested a review from theStack August 2, 2023 13:47
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK f52cb02

@achow101 achow101 self-assigned this Sep 20, 2023
@achow101
Copy link
Member

ACK f52cb02

@achow101 achow101 merged commit 5027d41 into bitcoin:master Sep 21, 2023
Copy link

@jonesk7734 jonesk7734 left a comment

Choose a reason for hiding this comment

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

Ok

Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 25, 2023
…for invalid command

f52cb02 doc: make it clear that `node` in `addnode` refers to the node's address (brunoerg)
effd1ef test: `addnode` with an invalid command should throw an error (brunoerg)
56b27b8 rpc, refactor: clean-up `addnode` (brunoerg)

Pull request description:

  This PR:

  - Adds test coverage for an invalid `command` in `addnode`.
  - Rename `test_getaddednodeinfo` to `test_addnode_getaddednodeinfo` and its log since this function also tests `addnode` and it doesn't worth to split into 2 ones.
  - Makes it clear in docs that `node` in `addnode` refers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id.
  - Some small improv/clean-up: use `const` where possible, rename some vars, and remove the check for nullance for `command` since it's a non-optional field.

ACKs for top commit:
  achow101:
    ACK f52cb02
  jonatack:
    ACK f52cb02
  theStack:
    re-ACK f52cb02

Tree-SHA512: e4a69e58b784e233463945b4d55a401957f9fe4562c129f59216a44f44fb3221d3449ac578fb35e665ca654c6ade2e741b72c3df78040f7527229c77b6c5b82e
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 26, 2023
…for invalid command

f52cb02 doc: make it clear that `node` in `addnode` refers to the node's address (brunoerg)
effd1ef test: `addnode` with an invalid command should throw an error (brunoerg)
56b27b8 rpc, refactor: clean-up `addnode` (brunoerg)

Pull request description:

  This PR:

  - Adds test coverage for an invalid `command` in `addnode`.
  - Rename `test_getaddednodeinfo` to `test_addnode_getaddednodeinfo` and its log since this function also tests `addnode` and it doesn't worth to split into 2 ones.
  - Makes it clear in docs that `node` in `addnode` refers to the node's address. It seemed a little weird for me "The node (see getpeerinfo for nodes)", it could mean a lot of things e.g. the node id.
  - Some small improv/clean-up: use `const` where possible, rename some vars, and remove the check for nullance for `command` since it's a non-optional field.

ACKs for top commit:
  achow101:
    ACK f52cb02
  jonatack:
    ACK f52cb02
  theStack:
    re-ACK f52cb02

Tree-SHA512: e4a69e58b784e233463945b4d55a401957f9fe4562c129f59216a44f44fb3221d3449ac578fb35e665ca654c6ade2e741b72c3df78040f7527229c77b6c5b82e
@bitcoin bitcoin locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants