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


Specification

Read full Discovery v5 specification

What's node ID?


Module first!


Module structure


Client/Server

/** * 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:

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:

incomingPipeline.build(); Flux.from(discoveryServer.getIncomingPackets()) .subscribe(incomingPipeline::push);

Handler


Outgoing pipeline

setup:

outgoingPipeline .addHandler(new OutgoingParcelHandler(outgoingSink)) .addHandler(new NodeSessionRequestHandler()) .addHandler(nodeIdToSession) .addHandler(new NewTaskHandler()) .addHandler(new NextTaskHandler(outgoingPipeline, taskScheduler));

usage:

public void sendOutgoing(Packet packet) { logger.trace(() -> String.format("Sending outgoing packet %s in session %s", packet, this)); outgoing.accept(packet); }

ENR


ENR Specification

as defined in EIP-778


NodeSession


Discovery Manager


Tests


Interop test



Plans

  • minor polishing and finish
  • implement topics
  • topics research

Thank you!

You can find discovery implementation on Github

Questions ?!

Select a repo