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 #7937

Merged
merged 20 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@

import com.google.common.net.InetAddresses;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Encapsulates the network coordinates of a {@link DiscoveryPeer} as well as serialization logic
* used in various Discovery messages.
*/
public class Endpoint {
private static final Logger log = LoggerFactory.getLogger(Endpoint.class);
vaidikcode marked this conversation as resolved.
Show resolved Hide resolved
private final Optional<String> host;
private final int udpPort;
private final Optional<Integer> tcpPort;
Expand All @@ -49,15 +52,15 @@ public Endpoint(final String host, final int udpPort, final Optional<Integer> tc
}

public static Endpoint fromEnode(final EnodeURL enode) {
final int discoveryPort =
enode
.getDiscoveryPort()
.orElseThrow(
() ->
new IllegalArgumentException(
"Attempt to create a discovery endpoint for an enode with discovery disabled."));
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"

return new Endpoint("defaultHost", 0, Optional.empty());
}

final Optional<Integer> listeningPort = enode.getListeningPort();
return new Endpoint(enode.getIp().getHostAddress(), discoveryPort, listeningPort);
return new Endpoint(enode.getIp().getHostAddress(), discoveryPort.get(), listeningPort);
}

public EnodeURL toEnode(final Bytes nodeId) {
Expand Down