From 046d0b2ee4905c5e1006e50091b5c03778d6396f Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Fri, 20 Oct 2023 10:33:45 -0500 Subject: [PATCH] add peer tracker condition, p2p to P2P, use absolute links instead of relative --- p2p/p2p.md | 22 ++++++++++++---------- specs/src/README.md | 15 +++++++++------ sync/sync.md | 3 ++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/p2p/p2p.md b/p2p/p2p.md index 8501a8de..9b47750e 100644 --- a/p2p/p2p.md +++ b/p2p/p2p.md @@ -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 (`//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 (`//header-sub/v0.0.1`) is configurable based on `networkID` parameter used to initialize the subscriber service. The Subscriber implements the following interface: @@ -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. @@ -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. @@ -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 @@ -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] @@ -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 diff --git a/specs/src/README.md b/specs/src/README.md index 1585cf2b..285d47eb 100644 --- a/specs/src/README.md +++ b/specs/src/README.md @@ -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] @@ -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 diff --git a/sync/sync.md b/sync/sync.md index 05ead750..6ffc6d00 100644 --- a/sync/sync.md +++ b/sync/sync.md @@ -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. @@ -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