# Discovery v5 *Dmitrii Shmatko* ### .. slides: https://hackmd.io/@0klO-1bXTU-4eDnt-ZnrHg/d#/ --- ## Who am I? - Dmitrii Shmatko from Harmony team - Last 5 years: Java, Ethereum, Python, Node.js, Financial apps - Before: small IT enterprenuer, development management, databases --- ![](https://i.imgur.com/WAZz8FU.png) --- ### Specification Read full [Discovery v5 specification](https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md) ![](https://i.imgur.com/Tj2cNhh.png) What's node ID? ![](https://i.imgur.com/0lDIsaO.png) --- ### Module first! ![](https://i.imgur.com/hAEtXE7.png) --- ### Module structure ![](https://i.imgur.com/CV9Iso8.png) --- ### Client/Server ```java= /** * Netty-specific extension of {@link DiscoveryServer}. * Made to reuse server channel for client. */ public interface NettyDiscoveryServer extends DiscoveryServer { /** * Reuse Netty server channel with client, * so you are able to send packets from the same port */ CompletableFuture<Void> useDatagramChannel( Consumer<NioDatagramChannel> consumer); } ``` --- ### Data flow Pipeline setup: ```java= incomingPipeline .addHandler(new IncomingDataPacker()) .addHandler(new WhoAreYouAttempt(homeNode.getNodeId())) .addHandler(new WhoAreYouSessionResolver(authTagRepo)) .addHandler(new UnknownPacketTagToSender(homeNode)) .addHandler(nodeIdToSession) .addHandler(new UnknownPacketTypeByStatus()) .addHandler(new NotExpectedIncomingPacketHandler()) .addHandler(new WhoAreYouPacketHandler(outgoingPipeline, taskScheduler)) ``` start: ```java= incomingPipeline.build(); Flux.from(discoveryServer.getIncomingPackets()) .subscribe(incomingPipeline::push); ``` --- ### Handler ![](https://i.imgur.com/XI7G2N8.png) --- ### Outgoing pipeline setup: ```java= outgoingPipeline .addHandler(new OutgoingParcelHandler(outgoingSink)) .addHandler(new NodeSessionRequestHandler()) .addHandler(nodeIdToSession) .addHandler(new NewTaskHandler()) .addHandler(new NextTaskHandler(outgoingPipeline, taskScheduler)); ``` usage: ```java= public void sendOutgoing(Packet packet) { logger.trace(() -> String.format("Sending outgoing packet %s in session %s", packet, this)); outgoing.accept(packet); } ``` --- ### ENR ![](https://i.imgur.com/H3btKfw.png) --- ### ENR Specification as defined in [EIP-778](https://eips.ethereum.org/EIPS/eip-778) ![](https://i.imgur.com/5VO03bP.png) --- ### NodeSession ![](https://i.imgur.com/O70wO9j.png) --- ### Discovery Manager ![](https://i.imgur.com/2C1630A.png) --- ### Tests ![](https://i.imgur.com/DtpJr7F.png) --- ### Interop test ![](https://i.imgur.com/zWwjFyW.png) ![](https://i.imgur.com/nknhCDY.png) --- ### Plans - minor polishing and finish - implement topics - topics research --- ### Thank you! You can find discovery implementation [on Github](https://github.com/harmony-dev/beacon-chain-java/pull/189) ### Questions ?!
{"metaMigratedAt":"2023-06-15T01:31:56.443Z","metaMigratedFrom":"YAML","title":"Discovery v5 by Dmitrii Shmatko","breaks":true,"contributors":"[{\"id\":\"d2494efb-56d7-4d4f-b878-39edf999eb1e\",\"add\":3422,\"del\":2761}]"}
    789 views