Skip to content

Commit

Permalink
add peer tracker condition, p2p to P2P, use absolute links instead of…
Browse files Browse the repository at this point in the history
… relative
  • Loading branch information
Ganesha Upadhyaya authored and Ganesha Upadhyaya committed Oct 20, 2023
1 parent ba4f255 commit 046d0b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
22 changes: 12 additions & 10 deletions p2p/p2p.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# P2P

The p2p package mainly contains two services:
The P2P package mainly contains two services:

1) Subscriber
2) Exchange

## Subscriber

Subscriber is a service that manages gossip of headers among the nodes in the p2p network by using [libp2p][libp2p] and its [pubsub][pubsub] modules. The pubsub topic used for gossip (`/<networkID>/header-sub/v0.0.1`) is configurable based on `networkID` parameter used to initialize the subscriber service.
Subscriber is a service that manages gossip of headers among the nodes in the P2P network by using [libp2p][libp2p] and its [pubsub][pubsub] modules. The pubsub topic used for gossip (`/<networkID>/header-sub/v0.0.1`) is configurable based on `networkID` parameter used to initialize the subscriber service.

The Subscriber implements the following interface:

Expand All @@ -27,25 +27,26 @@ type Subscriber[H Header[H]] interface {
}
```

The `Subscribe()` method allows listening to any new headers that are published to the p2p network. The `SetVerifier()` method allows for setting a custom verifier that will be executed upon receiving any new headers from the p2p network. This is a very useful customization for the consumers of go-header library to pass any custom logic as part of the pubsub.
The `Subscribe()` method allows listening to any new headers that are published to the P2P network. The `SetVerifier()` method allows for setting a custom verifier that will be executed upon receiving any new headers from the P2P network. This is a very useful customization for the consumers of go-header library to pass any custom logic as part of the pubsub.

## Exchange

An exchange is a combination of:

* Exchange: a client for requesting headers from the p2p network (outbound)
* ExchangeServer: a p2p server for handling inbound header requests
* Exchange: a client for requesting headers from the P2P network (outbound)
* ExchangeServer: a P2P server for handling inbound header requests

### Exchange Client

Exchange defines a client for requesting headers from the p2p network. An exchange client is initialized using self [host.Host][host], a list of peers in the form of slice [peer.IDSlice][peer], and a [connection gater][gater] for blocking and allowing nodes. Optional parameters like `ChainID` and `NetworkID` can also be passed. The exchange client also maintains a list of trusted peers via a peer tracker. The peer tracker discovers peers until `len(connected)+len(disconnected)` will not reach the limit(`maxPeerTrackerSize` for now it is 100) and `len(connected)>len(disconnected)`.
Exchange defines a client for requesting headers from the P2P network. An exchange client is initialized using self [host.Host][host], a list of peers in the form of slice [peer.IDSlice][peer], and a [connection gater][gater] for blocking and allowing nodes. Optional parameters like `ChainID` and `NetworkID` can also be passed. The exchange client also maintains a list of trusted peers via a peer tracker. The peer tracker discovers peers until `len(connected)+len(disconnected)` will not reach the limit(`maxPeerTrackerSize` for now it is 100) and `len(connected)>len(disconnected)`.

#### Peer Tracker

The three main functionalities of the peer tracker are:

* bootstrap
* track
* gc
* garbage collection (gc)

When the exchange client is started, it bootstraps the peer tracker using the set of trusted peers used to initialize the exchange client.

Expand Down Expand Up @@ -108,7 +109,7 @@ The `GetVerifiedRange` differs from `GetRangeByHeight` as it ensures that the re

### Exchange Server

ExchangeServer represents the server-side component (p2p server) for responding to inbound header requests. The exchange server needs to be initialized using self [host.Host][host] and a [store](../specs/src/specs/store.md). Optional `ServerParameters` as shown below, can be set during the server initialization.
ExchangeServer represents the server-side component (P2P server) for responding to inbound header requests. The exchange server needs to be initialized using self [host.Host][host] and a [store][store]. Optional `ServerParameters` as shown below, can be set during the server initialization.

```
// ServerParameters is the set of parameters that must be configured for the exchange.
Expand Down Expand Up @@ -160,7 +161,7 @@ enum StatusCode {
}
```

The request handler utilizes its local [store](../specs/src/specs/store.md) for serving the header requests and only up to `MaxRangeRequestSize` of 512 headers can be requested while requesting headers by range. If the requested range is not available, the range is reset to whatever is available.
The request handler utilizes its local [store][store] for serving the header requests and only up to `MaxRangeRequestSize` of 512 headers can be requested while requesting headers by range. If the requested range is not available, the range is reset to whatever is available.

### Session

Expand Down Expand Up @@ -198,11 +199,11 @@ func DefaultClientParameters() ClientParameters {
## Metrics

Currently only following metrics are collected:

* P2P header exchange response size
* Duration of the get headers request in seconds
* Total synced headers


# References

[1] [libp2p][libp2p]
Expand All @@ -220,3 +221,4 @@ Currently only following metrics are collected:
[host]: https://github.com/libp2p/go-libp2p/core/host
[peer]: https://github.com/libp2p/go-libp2p/core/peer
[gater]: https://github.com/libp2p/go-libp2p/p2p/net/conngater
[store]: https://github.com/celestiaorg/go-header/blob/main/store/store.md
15 changes: 9 additions & 6 deletions specs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

Welcome to the go-header Specifications.

go-header is a library for syncing blockchain data such as block headers over the p2p network. It contains services for requesting and receiving headers from the p2p network, serving header requests from other nodes in the p2p network, storing headers, and syncing historical headers in case of fallbacks.
go-header is a library for syncing blockchain data such as block headers over the P2P network. It contains services for requesting and receiving headers from the P2P network, serving header requests from other nodes in the P2P network, storing headers, and syncing historical headers in case of fallbacks.

|Component|Description|
|---|---|
|[p2p.Subscriber](../../p2p/p2p.md)|listens for new headers from the p2p network|
|[p2p.ExchangeServer](../../p2p/p2p.md)|serve header requests from other nodes in the p2p network|
|[p2p.Exchange](../../p2p/p2p.md)|client that requests headers from other nodes in the p2p network|
|[store.Store](../../store/store.md)|storing headers and making them available for access by other services such as exchange and syncer|
|[sync.Syncer](../../sync/sync.md)|syncing of historical and new headers from the p2p network|
|[p2p.Subscriber][p2p]|listens for new headers from the P2P network|
|[p2p.ExchangeServer][p2p]|serve header requests from other nodes in the P2P network|
|[p2p.Exchange][p2p]|client that requests headers from other nodes in the P2P network|
|[store.Store][store]|storing headers and making them available for access by other services such as exchange and syncer|
|[sync.Syncer][sync]|syncing of historical and new headers from the P2P network|

The go-header library makes it easy to be used by other projects by defining a clear interface (as described below). An example usage is defined in [headertest/dummy_header.go][dummy header]

Expand Down Expand Up @@ -53,3 +53,6 @@ type Header[H any] interface {
[1] [Dummy Header][dummy header]

[dummy header]: https://github.com/celestiaorg/go-header/blob/main/headertest/dummy_header.go
[p2p]: https://github.com/celestiaorg/go-header/blob/main/p2p/p2p.md
[store]: https://github.com/celestiaorg/go-header/blob/main/store/store.md
[sync]: https://github.com/celestiaorg/go-header/blob/main/sync/sync.md
3 changes: 2 additions & 1 deletion sync/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ There are two main processes running in Syncer:
For creating a new instance of the Syncer following components are needed:

* A getter, e.g., [Exchange][exchange]
* A [Store](../../../store/store.md)
* A [Store][store]
* A [Subscriber][subscriber]
* Additional options such as block time. More options as described below.

Expand Down Expand Up @@ -93,3 +93,4 @@ When a new network head is received which gets validated and set as subjective h

[exchange]: https://github.com/celestiaorg/go-header/blob/main/p2p/exchange.go
[subscriber]: https://github.com/celestiaorg/go-header/blob/main/p2p/subscriber.go
[store]: https://github.com/celestiaorg/go-header/blob/main/store/store.md

0 comments on commit 046d0b2

Please sign in to comment.