mana-ethereum / mana

Ethereum full node implementation written in Elixir.
Other
274 stars 47 forks source link

Peer Management #639

Open hayesgm opened 5 years ago

hayesgm commented 5 years ago

Currently when we run our sync code, we start two supervisors: ExWire.PeerSupervisor and ExWire.TCP.InboundConnectionsSupervisor. The latter is used for inbound connections, which isn't heavily supported right now. For ExWire.PeerSupervisor, when we're running discovery mode, we connect to peers as they are discovered until we reach a certain count of max peers (currently hard-coded). We don't try to connect to other peers when our connected peers drop, and again, we ignore any inbound connections. This is pretty poor behavior.

This issue is to improve peer connection management. It should do a variety of tasks:

  1. Keep track of all peers (discovered by the discovery protocol, inbound or from bootnodes / reserved peers), even if we decide not to connect. This acts as a pool of nodes we might connect to.
  2. Connect to good peers. This might be from the Kademlia distance formula, or maybe nodes we've connected to in the past, or maybe based on capabilities (e.g. connect, check the caps, and drop the node if it's not useful).
  3. Keep track of dropped connections (maybe a peer disconnected from us) and connect to new nodes when this happens. We should (probably) not reconnect to a peer after it asks to disconnect, but we should keep that peer if we just had a transport error.

This will require a good amount of work, but it's vital to getting a healthy node up and running.

InoMurko commented 5 years ago

Peer rating and reputation system: The idea is that a rating consist of: