Please describe your proposed solution
To implement a P2P networking layer compatible with Cardano, we'll focus on the following individual components:
<u>Peer Discovery</u>
A mechanism to establish which peers are participating in the network without relying on a static topology. In our scope, peer discovery includes:
- Ledger Relays: our component will be able to discover peers by inspecting the ledger state and accessing relay information available in SPO registration certificates.
- Peer-sharing: our component will be able to request known peers from already connected nodes using the peer-sharing mini-protocol.
- Bootstrap Topology: our component will accept a bootstrapping configuration that specifies an initial set of known peers to use as seed for crawling new peers using peer-sharing.
<u>Outbound Routing</u>
A component that manages the outbound traffic to peers using different heuristics with the goal of optimizing overall network efficiency. In our scope, the routing heuristics will include:
- Health Checks: our component will monitor outbound connections at the TCP level and at the application level using the Ouroboros keep-alive mini-protocol.
- Random Churn: to avoid getting stuck on a local maxima of efficiency, our component will introduce a configurable level of chaos by eagerly switching to random new peers from the list of all available.
- Latency Score: our component will keep a ranking of peers in terms of network performance by computing a rolling average of the chain-sync latency of each. This dynamic ranking will be used as score to prioritize connections.
<u>Inbound Monitor</u>
A component that is in charge of monitoring inbound connections with the goal of optimizing efficiency and to mitigate abuses / attacks.
- Max connections: our component will keep track of the total amount of connections and restrict any new connections after a configurable max threshold has been reached.
- Rate-limiting / Throttling: our component will keep track of data throughput metrics for each peer and throttle the communication using a known algorithm such as "leaky bucket".
- Inactivity Churn: our component will measure inactivity span for each peer and disconnect peers that exceed a configurable max threshold.
The approach we're planning to use for the implementation of these components consists on taking the Haskell node as inspiration for the overall mechanics but without doing a strict reverse engineering of its current architecture. We believe that copying the exact implementation might not provide the benefits we're looking for in terms of node diversity.
It's important to note that many P2P interactions in Cardano are not part of a specification and, thus, not mandatory.