Skip to content
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

Use the node's configuration to decide if adding a peer with DNS in the enode is allowed #5584

Merged
merged 17 commits into from
Jun 20, 2023

Conversation

matthew1001
Copy link
Contributor

@matthew1001 matthew1001 commented Jun 12, 2023

PR description

Uses the node configuration to decide if admin_addPeer() should allow enodes with DNS in them. Previously this was hard coded to DNS-disabled.

I had to flow the enode DNS configuration through from RunnerBuilder to the JSON RPC method factory so that AdminAddPeer` has access to it. It may be that this isn't necessary, but I couldn't see another way to do it.

Fixed Issue(s)

Fixes #5583

@github-actions
Copy link

github-actions bot commented Jun 12, 2023

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.
  • I thought about the changelog and included a changelog update if required.
  • If my PR includes database changes (e.g. KeyValueSegmentIdentifier) I have thought about compatibility and performed forwards and backwards compatibility tests

@matthew1001 matthew1001 changed the title Add unit test to demonstrate failing admin_addPeer() case Use the node's configuration to decide if adding a peer with DNS in the enode is allowed Jun 12, 2023
@matthew1001 matthew1001 force-pushed the add-peer-dns branch 5 times, most recently from 6acd277 to 7247718 Compare June 12, 2023 15:11
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

Looks good overall. one suggestion about dealing with the Optional.
also could do with a changelog entry

* @param enodeDnsConfiguration the DNS configuration for enodes
* @return the runner builder
*/
public RunnerBuilder enodeDnsConfiguration(
Copy link
Contributor

Choose a reason for hiding this comment

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

better to pass in the actual value (not optional) and do Optional.of() within this method
similar to rpcMaxLogsRange() above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @macfarla that makes sense. I've made that change under the latest commit, along with an update to the change log.

@macfarla
Copy link
Contributor

Hi @matthew1001 I just built besu from this PR locally and getting a parse error from the JSON-RPC

➜  besu-local-nodes git ✗ curl -s -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://be1c3f9aa22ecf9e274040606cc530bb99153997e8dce77a9ea9e85802a0adb80bf78b24d67b0823cf7dca17efdf7f7e5e507b3376224484fa053ac7c2fb8a8b@11.11.11.101:30303"],"id":51}' http://localhost:8545
{
  "jsonrpc" : "2.0",
  "id" : 51,
  "result" : true
}%
➜  besu-local-nodes git ✗ curl -s -H 'content-type:application/json' -X POST --data '{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://be1c3f9aa22ecf9e274040606cc530bb99153997e8dce77a9ea9e85802a0adb80bf78b24d67b0823cf7dca17efdf7f7e5e507b3376224484fa053ac7c2fb8a8b@bozo.bob.net:30303"],"id":51}' http://localhost:8545
{
  "jsonrpc" : "2.0",
  "id" : 51,
  "error" : {
    "code" : -32700,
    "message" : "Parse error"
  }
}%

but besu log message would lead me to believe it worked ok

2023-06-15 10:52:28.409+10:00 | vert.x-eventloop-thread-2 | DEBUG | JsonRpcHttpService | Opened connection from 127.0.0.1:53113. Total of active connections: 1/160
2023-06-15 10:52:28.411+10:00 | vert.x-worker-thread-3 | DEBUG | JsonRpcExecutor | JSON-RPC request -> admin_addPeer ["enode://be1c3f9aa22ecf9e274040606cc530bb99153997e8dce77a9ea9e85802a0adb80bf78b24d67b0823cf7dca17efdf7f7e5e507b3376224484fa053ac7c2fb8a8b@bozo.bob.net:30303"]
2023-06-15 10:52:28.411+10:00 | vert.x-worker-thread-3 | DEBUG | AdminAddPeer | Adding (enode://be1c3f9aa22ecf9e274040606cc530bb99153997e8dce77a9ea9e85802a0adb80bf78b24d67b0823cf7dca17efdf7f7e5e507b3376224484fa053ac7c2fb8a8b@bozo.bob.net:30303) to peers

Can you look into the Parse error?

@matthew1001
Copy link
Contributor Author

Hi @macfarla hmm that's odd. Let me look into it and see why it's still returning a parse error.

@matthew1001
Copy link
Contributor Author

matthew1001 commented Jun 15, 2023

@macfarla I've re-tested locally and with -Xdns-enabled=true set admin_addPeer works correctly for me. Could you check if you had that set and if it's still failing let me know?

I added a unit test for the case where -Xdns-enabled=false as there wasn't one before, and it also made me go back and look at admin_removePeer because I hadn't applied the same logic to that RPC call. The latest commit updates admin_removePeer to follow the same behaviour as admin_addPeer, and also adds a unit test file (really just a port of the test file for admin_addPeer) because there weren't any unit tests for the remove case.

matthew1001 and others added 3 commits June 15, 2023 11:13
Signed-off-by: Matthew Whitehead <[email protected]>
…(but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>
@matthew1001
Copy link
Contributor Author

I've made the following additional changes to make the JSON/RPC errors clearer:

  1. Added a new error string for the case where DNS is disabled but the enode passed in to the RPC call includes a hostname:
{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32100,
        "message": "Enode DNS support is disabled"
    }
}
  1. Added a new error string for the case where enode DNS is supported, but the hostname couldn't be resolved:
{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32100,
        "message": "Cannot resolve enode DNS hostname"
    }
}

Signed-off-by: Matthew Whitehead <[email protected]>
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

couple of nits. I tested it locally and my results match your description. so looking good overall.

@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright © 2023 Kaleido, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to update existing copyright lines, but if you are changing it - it should be Copyright Hyperledger Besu contributors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly I don't actually recall updating this one - must have been when I was adding copyright for the new file. I've reverted it to how it was for now.

@@ -162,6 +162,8 @@ public enum JsonRpcError {
VALUE_NOT_ZERO(-50100, "We cannot transfer ether in a private transaction yet."),

CANT_CONNECT_TO_LOCAL_PEER(-32100, "Cannot add local node as peer."),
CANT_RESOLVE_PEER_ENODE_DNS(-32100, "Cannot resolve enode DNS hostname"),
CANT_USE_PEER_ENODE_DNS(-32100, "Enode DNS support is disabled"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CANT_USE_PEER_ENODE_DNS(-32100, "Enode DNS support is disabled"),
DNS_NOT_ENABLED(-32100, "Enode DNS support is disabled"),

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion for a simpler name. also "X not enabled" matches other error codes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, new commit renames the constant and updates the references to it.

CHANGELOG.md Outdated
@@ -21,6 +21,7 @@ and in case a rollback is needed, before installing a previous version, the migr
- Fix backwards sync bug where chain is rolled back too far, especially when restarting Nimbus [#5497](https://github.com/hyperledger/besu/pull/5497)
- Check to ensure storage and transactions are not closed prior to reading/writing [#5527](https://github.com/hyperledger/besu/pull/5527)
- Fix the unavailability of account code and storage on GraphQl/Bonsai [#5548](https://github.com/hyperledger/besu/pull/5548)
- Use the node's configuration to determine if DNS enode URLs are allowed in calls to `admin_addPeer` and `admin_removePeer` [#5584](https://github.com/hyperledger/besu/pull/5584)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will need to move to next release 23.4.3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've created a new section in the change-log under the latest commit, and removed this line from the 23.4.2 section.

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
@macfarla macfarla enabled auto-merge (squash) June 20, 2023 06:30
@macfarla macfarla merged commit 5bff76f into hyperledger:main Jun 20, 2023
vdamle pushed a commit to kaleido-io/besu that referenced this pull request Jun 20, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
davidkngo pushed a commit to liquichain/besu that referenced this pull request Jun 28, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
davidkngo pushed a commit to liquichain/besu that referenced this pull request Jul 21, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
davidkngo added a commit to liquichain/besu that referenced this pull request Jul 21, 2023
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Chengxuan pushed a commit to kaleido-io/besu that referenced this pull request Dec 13, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Chengxuan pushed a commit to kaleido-io/besu that referenced this pull request Dec 13, 2023
…he enode is allowed (hyperledger#5584)

* Use the node's configuration to decide if adding a peer with DNS in the enode is allowed

Signed-off-by: Matthew Whitehead <[email protected]>

* Update command test mocks

Signed-off-by: Matthew Whitehead <[email protected]>

* Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments. Add a reference in the change log. Fix failing integration test.

Signed-off-by: Matthew Whitehead <[email protected]>

* Add the same DNS-config checking logic to admin_removePeer, along with a unit test file for it

Signed-off-by: Matthew Whitehead <[email protected]>

* Tweak the change log

Signed-off-by: Matthew Whitehead <[email protected]>

* Add clearer error messages for the cases where enode DNS is disabled (but a hostname one has been specified in the URL) or where DNS name resolution failed

Signed-off-by: Matthew Whitehead <[email protected]>

* Spotless Java fixes

Signed-off-by: Matthew Whitehead <[email protected]>

* Fix copyright for new file

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>

* Address PR comments (mainly copyright & constant renaming)

Signed-off-by: Matthew Whitehead <[email protected]>

* move changelog entry to 23.4.4

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

admin_addPeer() uses default configuration for DNS support
2 participants