Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Sep 24, 2024
1 parent 5657249 commit e207f64
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.api.peer.Eth2PeerWithEnr;
import tech.pegasys.teku.api.response.v1.node.Direction;
import tech.pegasys.teku.api.response.v1.node.Peer;
Expand All @@ -31,7 +32,7 @@
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage;

public class NetworkDataProvider {
final Function<NodeId, Optional<String>> enrLookupFunction;
final Function<UInt256, Optional<String>> enrLookupFunction;

private final Eth2P2PNetwork network;

Expand Down Expand Up @@ -96,7 +97,10 @@ public List<Eth2Peer> getEth2Peers() {
public List<Eth2PeerWithEnr> getEth2PeersWithEnr() {
return network
.streamPeers()
.map(eth2Peer -> new Eth2PeerWithEnr(eth2Peer, enrLookupFunction.apply(eth2Peer.getId())))
.map(
eth2Peer ->
new Eth2PeerWithEnr(
eth2Peer, enrLookupFunction.apply(eth2Peer.getDiscoveryNodeId())))
.toList();
}

Expand Down Expand Up @@ -126,7 +130,10 @@ public Optional<Eth2PeerWithEnr> getEth2PeerById(final String peerId) {
final NodeId nodeId = network.parseNodeId(peerId);
return network
.getPeer(nodeId)
.map(eth2Peer -> new Eth2PeerWithEnr(eth2Peer, enrLookupFunction.apply(nodeId)));
.map(
eth2Peer ->
new Eth2PeerWithEnr(
eth2Peer, enrLookupFunction.apply(eth2Peer.getDiscoveryNodeId())));
}

private Peer toPeer(final Eth2Peer eth2Peer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.networking.p2p.peer.NodeId;

/**
* CAUTION: this API is unstable and might be changed in any version in backward incompatible way
Expand All @@ -42,5 +42,5 @@ public interface DiscoveryService {

void updateCustomENRField(String fieldName, Bytes value);

Optional<String> lookupEnr(NodeId nodeId);
Optional<String> lookupEnr(UInt256 nodeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.crypto.SECP256K1.SecretKey;
import org.apache.tuweni.units.bigints.UInt256;
import org.apache.tuweni.units.bigints.UInt64;
import org.ethereum.beacon.discovery.AddressAccessPolicy;
import org.ethereum.beacon.discovery.DiscoverySystem;
Expand All @@ -48,7 +49,6 @@
import tech.pegasys.teku.networking.p2p.discovery.DiscoveryService;
import tech.pegasys.teku.networking.p2p.libp2p.MultiaddrUtil;
import tech.pegasys.teku.networking.p2p.network.config.NetworkConfig;
import tech.pegasys.teku.networking.p2p.peer.NodeId;
import tech.pegasys.teku.service.serviceutils.Service;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsSupplier;
Expand Down Expand Up @@ -305,7 +305,7 @@ public void updateCustomENRField(final String fieldName, final Bytes value) {
}

@Override
public Optional<String> lookupEnr(final NodeId nodeId) {
public Optional<String> lookupEnr(final UInt256 nodeId) {
final Optional<NodeRecord> maybeNodeRecord = discoverySystem.lookupNode(nodeId.toBytes());
return maybeNodeRecord.map(NodeRecord::asEnr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer;
import tech.pegasys.teku.networking.p2p.discovery.DiscoveryService;
import tech.pegasys.teku.networking.p2p.peer.NodeId;

public class NoOpDiscoveryService implements DiscoveryService {

Expand Down Expand Up @@ -66,7 +66,7 @@ public Optional<List<String>> getDiscoveryAddresses() {
public void updateCustomENRField(final String fieldName, final Bytes value) {}

@Override
public Optional<String> lookupEnr(final NodeId nodeId) {
public Optional<String> lookupEnr(final UInt256 nodeId) {
return Optional.empty();
}
}

0 comments on commit e207f64

Please sign in to comment.