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

handling IllegalArgumentException caused by Discovery Disabled Nodes in Endpoint.fromEnode #7937

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

vaidikcode
Copy link
Contributor

Signed-off-by: vaidikcode [email protected]

PR description

This PR modifies the Endpoint.fromEnode method to handle cases where discovery is disabled for a given EnodeURL more gracefully. Previously, the method threw an IllegalArgumentException when getDiscoveryPort returned an empty Optional, leading to potential disruptions in the system.

Fixed Issue(s)

#7887

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

Signed-off-by: vaidikcode <[email protected]>
Optional<Integer> discoveryPort = enode.getDiscoveryPort();

if (discoveryPort.isEmpty()) {
log.warn("Attempted to create a discovery endpoint for a node with discovery disabled: {}", enode);
Copy link
Contributor

Choose a reason for hiding this comment

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

if the discovery port is empty, the default port will be used, right? Can we add a test for the expected outcome?

And in that case, should this log be moved to debug? "Using default port for enode"

Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[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.

looking good just a suggestion on naming and the exception in the test

when(enodeWithNoDiscovery.getIp()).thenReturn(InetAddress.getByName("127.0.0.1"));
}
catch (UnknownHostException e) {
log.debug("Failed to resolve the Host Address ");
Copy link
Contributor

Choose a reason for hiding this comment

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

prob wouldn't catch this exception in the test, you can mark the test method throws that ex. (what would happen if this exception occurred? would the test pass or fail? should it pass or fail?)

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 don't believe this will significantly impact the test's primary function. Should I proceed with Throws it?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I would keep this logic out of the test altogether

vaidikcode and others added 2 commits November 29, 2024 04:11
Signed-off-by: vaidikcode <[email protected]>
…iscovery/Endpoint.java

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Vaidik <[email protected]>
@macfarla
Copy link
Contributor

macfarla commented Dec 6, 2024

@vaidikcode quick fix needed to resolve compile error

@vaidikcode
Copy link
Contributor Author

Hi @macfarla , I’ve reviewed the code, and my IntelliJ IDE shows no compile errors. Could you please clarify the specific error or issue you are encountering?

@macfarla
Copy link
Contributor

/Users/sm/workspace/b2/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/Endpoint.java:59: error: cannot find symbol
      log.debug("Discovery disabled for enode {}. Using default port {}.", enode, defaultPort);
      ^
  symbol:   variable log
  location: class Endpoint
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

@macfarla macfarla self-assigned this Dec 11, 2024
@macfarla
Copy link
Contributor

spotless is required to pass. converting to draft since it's not ready to review

@macfarla macfarla marked this pull request as draft December 11, 2024 05:23
@vaidikcode vaidikcode marked this pull request as ready for review December 11, 2024 07:47
@macfarla macfarla marked this pull request as draft December 13, 2024 03:20
@macfarla
Copy link
Contributor

there is a unit test failure, have you run this locally?

/home/runner/work/besu/besu/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java:910: warning: [AddressSelection] Prefer InetAddress.getAllByName to APIs that convert a hostname to a single IP address

    when(enodeWithNoDiscovery.getIp()).thenReturn(InetAddress.getByName("127.0.0.1"));
                                                                       ^
> Task :ethereum:p2p:compileTestJava
    (see https://errorprone.info/bugpattern/AddressSelection)
  Did you mean 'when(enodeWithNoDiscovery.getIp()).thenReturn(InetAddress.getLoopbackAddress());'?
error: warnings found and -Werror specified

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.

2 participants