Teku networking

Network endpoints

Localhost net interface:

  • JSON API
  • Metrics
  • Validator

External net interface:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

Libp2p

Main Libp2p essenses

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

Basic Libp2p Pipeline Sample

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

TCP Socket
   ^
Multistream: /noise
   ^ 
Noise (Negotiator then Cipher)
   ^   (secured connection)
Multistream: /mplex/6.7.0 or /yamux (not supported yet)
   ^ 
Mplex stream multiplexer
   ^  ^  ^  ^  ^   (Streams)
Multistream: /ipfs/id/1.0.0, 
             /ipfs/ping/1.0.0, 
             /meshsub/1.1.0,  (Gossip 1.1)
             /eth2/beacon_chain/req/<method>/<ver> (Eth2 RPC)
   ^  ^  ^  ^  ^ 
Negotiated Protocol Handler

Implementation overview

https://github.com/libp2p/jvm-libp2p

Architecture

  • built with Netty
  • expose a lot of Netty API: Channel, ChannelPipeline, ChannelHandler, ByteBuf
  • Libp2p Connection, Stream are essntially Netty Channels
  • All libp2p components like security handlers, multiplexers, protocol selectros, protocl bindings are essentially Netty ChannelHandlers

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

Components

Minimal Libp2p spec subset required for implementing Eth2 node

  • Transport:
    โ€“ TCP
    โ€“ WebSocket (disabled in Teku now)
  • Security:
    โ€“ Plain (for tesing only)
    โ€“ Secio (disabled in Teku now)
    โ€“ Noise-XX-25519-ChaChaPoly-SHA256 (Spec)
  • Stream multiplexing: only mplex (Spec)
  • Protocols bindings:
    โ€“Gossip 1.1: Generic pubsub spec, Gossip (v1.0 + v1.1) spec
    โ€“Ping
    โ€“Identity
  • No Connection manager
  • No Libp2p discovery (Just MDns which is kind of standalone service now)

Maturity

The JVM library can still be assumed as beta-version:

  • The first version was implemented in just 2.5 months with minimal testing and without any compatibility tests: aka Alpha version
  • While adoping it in Teku many compatibility and reliablity issues were fixed, a number of unit tests were added (though still far from acceptable coverage): aka Beta version

Teku integration

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’

Overview

networking:p2p module: Eth2 agnostic Libp2p binding. Contains generic classes for RPC, subscriptions
networking:eth module: Extends p2p classes for Eth2 specific functions

Configuration of Libp2p host: LibP2PNetwork.java

  • Eth2 RPC methods (Spec, BeaconChainMethods.java): raw Libp2p Streams
    โ€“ /eth2/beacon_chain/req/status
    โ€“ /eth2/beacon_chain/req/ping
    โ€“ /eth2/beacon_chain/req/metadata
    โ€“ /eth2/beacon_chain/req/beacon_blocks_by_root
    โ€“ /eth2/beacon_chain/req/beacon_blocks_by_range
  • Eth2 pubsub topics (Spec, tech.pegasys.teku.networking.eth2.gossip package): Gossip 1.1 topics:
    โ€“ beacon_block: new blocks broadcasting (BlockTopicHandler.java)
    โ€“ beacon_attestation_{subnet_id}: unaggregated attestations broadcasting to the subnet subnet_id
    โ€“ beacon_aggregate_and_proof aggregated attestations broadcasting to be included in future blocks
    โ€“ voluntary_exit, proposer_slashing, attester_slashing

Eth2 RPC

  • /eth2/beacon_chain/req/* protocol ID
  • A new Stream per each request/response (RpcHandler.java)
  • [snappy[ssz[request|response]]] (Snappy framing variant)
  • Response may contain several chunks. Each chunk may be fragmented to several snappy frames. (IMO good place for hacking)
    Response sample respCode len1 [chunk-1-1] len2 [chunk-2-1][chunk-2-2]

Eth2 pubsub

  • beacon_attestation_{subnet_id} topics subscriptions are volatile. A validator node needs to change subnet subscriptions on per epoch basis.
  • [snappy[ssz[message]]] (Snappy block variant)
  • Specific Gossip parameters (LibP2PNetwork.createGossip()) for Eth2 network (Gossip 1.1 parameters are yet to be defined)

Discovery

Spec: https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md
JVM Implementation: https://github.com/PegaSysEng/discovery

  • Netty UDP
  • RLP encoding
  • Contains ENR field with peer attestation subnet subscriptions to better handle frequently changed beacon_attestation_{subnet_id} Gossip subscriptions

Maturity may also be considered as Beta

Blst library