koinos / koinos-p2p

The p2p microservice orchestrates the distribution of blocks and transactions between peers.
MIT License
6 stars 4 forks source link

State Machine #40

Closed mvandeberg closed 3 years ago

mvandeberg commented 3 years ago

As a Koinos node operator, I want the p2p microservice to be able to move between sync and gossips modes for each peer as needed to keep my and other's nodes in sync.

We may be able to replace the sync protocol with a simple RPC wrapper https://github.com/libp2p/go-libp2p-gorpc

Sync Manager Algorithm: Connect to N peers (protocol contains chain id check irreversible fork check) Get head block for each peer Target sync block is (min(peer_head_blocks) - my_head_block) / 2 (perhaps maximum of 100k) For each peer, request block id at target sync block height, separating peers in to different forks depending on response For each fork, make batch requests to get caught up to head block id at height for that fork If our node is now within delta D blocks of peer, switch it to gossip mode Repeat until all peers are in gossip mode

All new connections are added as "sync mode" New connections register themselves to a manager. The manager tracks head blocks and potential forks and delegates batch requests to peers to get all peers. (Can pipeline between peers) When a peer has no more new blocks to provide, the manager sets the node to "gossip mode" (hang up and dial peer in gossip mode)

Future optimization: Combine both modes in to a single protocol with combined RPC model