Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the P2P part of the core protocol #3699

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion how-it-works/1_protocol/01_peer-to-peer-p2p.card.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ title: Peer-to-peer

# Peer-to-peer

The peer-to-peer layer (P2P) of the Internet Computer, the bottommost layer in the protocol stack, is responsible for the secure and reliable communication between the nodes of a subnet. The P2P layer realizes a virtual peer-to-peer broadcast network between the nodes of a subnet, building upon the Internet Protocol (IP) connectivity between the nodes. This makes the P2P layer the communications fabric that connects all the nodes of a subnet. Using P2P, a node can broadcast a network message, also called *artifact*, to all the nodes in the subnet. Artifacts can be things like input to canisters submitted by users or protocol messages (e.g., block proposals) generated by the IC protocol. P2P ensures that artifacts to be broadcast are eventually delivered to all nodes of the subnet. Eventual delivery reflects the asynchronous nature of real-world communication networks, which we assume for the Internet Computer protocol.
The peer-to-peer (P2P) layer serves as the foundation of the Internet Computer’s protocol stack, enabling secure and reliable communication between nodes within a subnet. This layer allows nodes to broadcast messages, such as user inputs to canisters or protocol messages like block proposals. P2P guarantees that all messages are eventually delivered to the necessary nodes, supporting the asynchronous nature of real-world communication networks—a core assumption of the Internet Computer protocol.

[Go deeper](/how-it-works/peer-to-peer-p2p/)
25 changes: 10 additions & 15 deletions how-it-works/1_protocol/01_peer-to-peer-p2p.subpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@ slug: peer-to-peer-p2p

# Peer-to-Peer

The peer-to-peer layer (P2P) of the Internet Computer realizes the reliable and secure communication of network messages, also called _artifacts_, between the nodes of a subnet. Artifacts are the network messages that are to be broadcast in the subnet, including the input to canister smart contracts submitted by users or protocol-originating messages such as the blocks produced by the consensus layer. P2P guarantees the secure eventual broadcast delivery of an artifact to all nodes which require it to make progress. The P2P layer thereby is the communication fabric for the IC protocol stack and is used by the consensus layer, the next layer in the stack above it, to broadcast artifacts to the nodes in the subnet.
The peer-to-peer (P2P) layer in the Internet Computer (IC) enables secure, reliable communication between nodes in a subnet. Broadcast messages, such as user-submitted inputs to canister smart contracts or blocks generated by the consensus layer, are reliably delivered to all nodes necessary for uninterrupted network operation.

It is important to note that broadcast artifacts reach all necessary subnet nodes eventually, that is, no upper bound on when this happens can be given. This _asynchronous communication network_ assumption is used for the ICP's communication and consensus layers as it reflects the properties of real-world networks.
A key feature is the guaranteed message delivery to all required subnet nodes despite varying real-world network conditions and node failures, thus forming the basis for ICPs communication and consensus protocols.

## Gossip protocol
## Abortable Broadcast

The P2P layer builds upon the basic principle of _gossip_. Gossip in communication networks works along the same basic principle as gossip among people: A node in the subnet is connected with a subset of the other nodes of the subnet – its _peers_. Whenever a node receives an artifact from a peer or creates one itself as part of the IC protocol, it gossips this artifact to all its peers. By every node in the network doing exactly this, every artifact _eventually_ propagates through the whole subnet, despite potential connectivity issues or malicious node behavior.
At the heart of the P2P layer is the Abortable Broadcast primitive, which is critical for efficient inter-replica communication in Byzantine Fault Tolerant (BFT) settings. It provides strong delivery guarantees in the presence of network congestion, peer or link failures, and backpressure. By preserving bandwidth and bounding the size of its data structures, Abortable Broadcast prevents overload from malicious peers while ensuring consistency for messages from honest nodes. It resembles a publish–subscribe model, with the added ability to abort in-flight messages when needed.

## Adverts
## QUIC Transport

Whenever a subnet node receives or generates an artifact to be broadcast, the node makes the artifact available to all peers. Every node doing so ensures that the artifact will eventually be delivered to all subnet nodes. However, doing so in a naïve way by simply sending the artifact to all peers would result in nodes receiving as many copies of the same artifact as the node has peers, which unnecessarily consumes networking bandwidth for transmitting duplicate messages and reduces the achievable throughput of the subnet.
The QUIC transport component is a custom gRPC-like library built on top of QUIC, designed to meet the needs of the ICP. This library enables efficient multitenancy of application protocols on the same replica. Key features include proper message multiplexing and caller pushback in the event that consumption is significantly slower than production.

This duplication of delivered artifacts in the naïve approach is mitigated by nodes sending _adverts_ for artifacts to their peers instead of sending the artifacts themselves. An advert specifies its corresponding artifact, but is a small message only containing the hash of the artifact to unambiguously refer to it and some additional metadata. A node only pushes adverts for artifacts to its peers. After receiving an advert, a node may request the corresponding artifact from one or more of its peers who sent it an advert for that artifact.
## Admitance of messages into downstream layers

## Prioritization of artifacts

The P2P layer allows the prioritization of artifacts such that the more crucial artifacts are broadcast throughout the subnet nodes more quickly than the others. Prioritizing some artifacts over others is important to ensure that the protocol can always make progress and not be starved of network bandwidth by "less important" traffic. This principle is well known from traditional networking and applies equally well to a blockchain system.
The P2P interface allows downstream layers to filter incoming messages, accepting only necessary ones while discarding or delaying the admission of others. This optimization reduces the processing load on downstream layers.

## Security

To prevent Denial of Service (DoS) attacks, nodes will only request and accept connections with nodes in the same subnet. Subnet membership is managed by the [Network Nervous System (NNS)](/how-it-works/#Network-Nervous-System). Thanks to the information stored in the NNS canisters P2P can guarantee that all the communication between two nodes is encrypted and authenticated, by using TLS.
To prevent Denial of Service (DoS) attacks, nodes connect only with others in the same subnet, with membership managed by the Network Nervous System (NNS). The NNS registry canister acts as a service discovery mechanism for the P2P layer, enabling P2P to ensure encrypted and authenticated communication between nodes through TLS.

## Go even deeper

[P2P on the IC wiki](<https://wiki.internetcomputer.org/wiki/IC_P2P_(peer_to_peer)_layer>)

[Blogpost on P2P](https://medium.com/dfinity/secure-scalability-the-internet-computers-peer-to-peer-layer-6662d451f2cc)
[Abortable Broadcast paper](<https://arxiv.org/abs/2410.22080>)

[![Watch youtube video](https://i.ytimg.com/vi/HOQb0lKIy9I/maxresdefault.jpg)](https://www.youtube.com/watch?v=HOQb0lKIy9I)
Loading