Network

Introduction

All the full nodes in the P2P network should share peers’ network information and consensus data to help other peers connect to more active and honest peers and synchronize blocks in the DAG quickly and efficiently. Light nodes can also obtain consensus data via connecting to full nodes.

P2P network is not included in the consensus rules, so users can use different network protocols alternatively such as some dedicated network for relaying transactions and blocks used by mining pools.

Here we provide a simple network protocol as the reference.

Join the P2P network

Peer Discovery

A new full node discover peers mainly in 3 ways:

  1. P2P Seeds

    P2P seeds don’ t participate in the synchronization of consensus data and just share network information of peers. A peer can get other peers’ information via DNS seeds or IP seeds which are saved in the config file. DNS seeds like pascal.ieda.ust.hk:7877 are currently maintained by EPIC developers and the peer will only connect to the DNS seeds if DNS seeds exist in the config file since they are safer and more stable. The peer will connect to all the seeds when he starts the network, and will disconnect these seeds after exchanging the address information.

  2. Network address book

    Once having an address book, the peer can directly connect to the proper peers via the address book.

  3. Specified by the user

    Users can specify the network addresses in the command line like —connect 127.0.1.1:7877 as the parameters when starting the program or by sending a RPC command to connect to extra peers.

Connecting To Peers

In order to finish P2P connection, peers need to complete the version handshake to confirm basic version information of each other like version number, service, time, etc. If the version information matches, the peer will send an acknowledgement message to confirm it. The version handshake finishes if both peers confirm the version messages. Here’s the data structure of the version_msg :

  • version_msg

Periodical tasks

Share address messages

Peers will exchange address message that contains many network addresses of other peers during the version handshake. Moreover, peers will broadcast their own addresses to neighbors periodically and neighbors will relay these address messages.

Ping and Pong

A usual way to implement the heart detect.

Synchronize data

Initial synchronization

Every time when a peer starts the network, he needs to finish the initial synchronization to obtain the latest blocks. The peer starts the initial synchronization by choosing one neightbor that has larger height than himself to synchronize block data (usually in the form of batches of blocks, which is called Bundle). If the neighbor is not active or the peer reaches the same height a the neighbor, the peer will choose another neighbor to start another round synchronization util his block data is up-to-date enough, which means current time - current block time < threshold.

We suggest that a peer should start mining after finishing the initial synchronization in order to decrease the probability of forking.

Synchronization between two peers

The synchronization process happens between the Peer and DAG modules. Their roles in short, Peer processes messages received from the network, and requests data from DAG accordingly. Detailed workflow is listed below.

Note:

  • API functions are marked in the form:

ModuleName#function_name(arguments: [arg1, arg2, ...], return: if any)

synchronization messages

Here’s the data structures of the sync messages used above.

GetInv

Inv

GetData

Bundle

Last updated