From e207f648cbb6ed9d166e04efd16a8313a7ebd267 Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Tue, 24 Sep 2024 16:28:17 +0200 Subject: [PATCH] fixes --- .../tech/pegasys/teku/api/NetworkDataProvider.java | 13 ++++++++++--- .../networking/p2p/discovery/DiscoveryService.java | 4 ++-- .../p2p/discovery/discv5/DiscV5Service.java | 4 ++-- .../p2p/discovery/noop/NoOpDiscoveryService.java | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/data/provider/src/main/java/tech/pegasys/teku/api/NetworkDataProvider.java b/data/provider/src/main/java/tech/pegasys/teku/api/NetworkDataProvider.java index 9bf2f777106..a9095a829de 100644 --- a/data/provider/src/main/java/tech/pegasys/teku/api/NetworkDataProvider.java +++ b/data/provider/src/main/java/tech/pegasys/teku/api/NetworkDataProvider.java @@ -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; @@ -31,7 +32,7 @@ import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage; public class NetworkDataProvider { - final Function> enrLookupFunction; + final Function> enrLookupFunction; private final Eth2P2PNetwork network; @@ -96,7 +97,10 @@ public List getEth2Peers() { public List getEth2PeersWithEnr() { return network .streamPeers() - .map(eth2Peer -> new Eth2PeerWithEnr(eth2Peer, enrLookupFunction.apply(eth2Peer.getId()))) + .map( + eth2Peer -> + new Eth2PeerWithEnr( + eth2Peer, enrLookupFunction.apply(eth2Peer.getDiscoveryNodeId()))) .toList(); } @@ -126,7 +130,10 @@ public Optional 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) { diff --git a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/DiscoveryService.java b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/DiscoveryService.java index c30474f25e5..1ff95b2ab07 100644 --- a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/DiscoveryService.java +++ b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/DiscoveryService.java @@ -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 @@ -42,5 +42,5 @@ public interface DiscoveryService { void updateCustomENRField(String fieldName, Bytes value); - Optional lookupEnr(NodeId nodeId); + Optional lookupEnr(UInt256 nodeId); } diff --git a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/discv5/DiscV5Service.java b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/discv5/DiscV5Service.java index ec5ae4f5426..bb05947a79e 100644 --- a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/discv5/DiscV5Service.java +++ b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/discv5/DiscV5Service.java @@ -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; @@ -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; @@ -305,7 +305,7 @@ public void updateCustomENRField(final String fieldName, final Bytes value) { } @Override - public Optional lookupEnr(final NodeId nodeId) { + public Optional lookupEnr(final UInt256 nodeId) { final Optional maybeNodeRecord = discoverySystem.lookupNode(nodeId.toBytes()); return maybeNodeRecord.map(NodeRecord::asEnr); } diff --git a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/noop/NoOpDiscoveryService.java b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/noop/NoOpDiscoveryService.java index 2379558c03f..32c6f38630f 100644 --- a/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/noop/NoOpDiscoveryService.java +++ b/networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/noop/NoOpDiscoveryService.java @@ -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 { @@ -66,7 +66,7 @@ public Optional> getDiscoveryAddresses() { public void updateCustomENRField(final String fieldName, final Bytes value) {} @Override - public Optional lookupEnr(final NodeId nodeId) { + public Optional lookupEnr(final UInt256 nodeId) { return Optional.empty(); } }