Skip to content

Commit 4c7323f

Browse files
authored
refactor(pkg/p2p): swap GossipSub by FloodSub (#3263)
* refactor(pkg/p2p): swap GossipSub by FloodSub * docs + cl
1 parent 77b39d4 commit 4c7323f

6 files changed

Lines changed: 37 additions & 36 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The project uses a zero-dependency core package pattern:
6565

6666
### P2P Architecture
6767

68-
- Built on libp2p with GossipSub and Kademlia DHT
68+
- Built on libp2p with FloodSub and Kademlia DHT
6969
- Nodes advertise capabilities (full/light, DA layers)
7070
- Automatic peer discovery with rendezvous points
7171

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changes
1313

14+
- Improve P2P gossiping by switching pubsub internals from `GossipSub` to `FloodSub` [#3263](https://github.com/evstack/ev-node/pull/3263)
1415
- Add `sequencer_blocks_synchronized_total` Prometheus counter metric tracking blocks synced by source (DA/P2P) [#3259](https://github.com/evstack/ev-node/pull/3259)
1516
- Make it easier to override `DefaultMaxBlobSize` by ldflags [#3235](https://github.com/evstack/ev-node/pull/3235)
1617
- Add solo sequencer (simple in memory single sequencer without force inclusion) [#3235](https://github.com/evstack/ev-node/pull/3235)

docs/adr/adr-003-peer-discovery.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Libp2p provides multiple ways to discover peers (DHT, mDNS, PubSub peer exchange
1111
## Proposed network architecture
1212

1313
1. There will be a set of well-known, application-agnostic seed nodes. Every Evolve client will be able to connect to such node, addresses will be saved in configuration.
14-
- This does not limit applications as they can still create independent networks with separate set of seed nodes.
14+
- This does not limit applications as they can still create independent networks with separate set of seed nodes.
1515
2. Nodes in the network will serve DHT. It will be used for active peer discovery. Client of each optimistic network will be able to find other peers in this particular network.
16-
- All nodes will cooperate on the same DHT.
17-
- ChainID will be used to advertise that client participates in a particular optimistic network.
16+
- All nodes will cooperate on the same DHT.
17+
- ChainID will be used to advertise that client participates in a particular optimistic network.
1818
3. Nodes from multiple networks will help with peer discovery (via single DHT).
19-
4. After connecting to nodes found in DHT, GossipSub will handle peer lists for clients.
19+
4. After connecting to nodes found in DHT, FloodSub will handle peer lists for clients.
2020

2121
### Pros
2222

@@ -30,11 +30,11 @@ Libp2p provides multiple ways to discover peers (DHT, mDNS, PubSub peer exchange
3030
## Alternatives
3131

3232
1. Joining public IPFS DHT for peer discovery.
33-
- pros: large network - finding peers should be very easy
34-
- cons: we may affect public IPFS network stability in case of misconfiguration, possibly lot of unrelated traffic
33+
- pros: large network - finding peers should be very easy
34+
- cons: we may affect public IPFS network stability in case of misconfiguration, possibly lot of unrelated traffic
3535
2. Custom peer-exchange protocol.
36-
- pros: full flexibility of implementation
37-
- cons: need to create from scratch and test
36+
- pros: full flexibility of implementation
37+
- cons: need to create from scratch and test
3838
3. Re-use of existing peer discovery mechanism like `discv5`
39-
- pros: ready & battle-tested software
40-
- cons: use different network stack, requires lot of integration
39+
- pros: ready & battle-tested software
40+
- cons: use different network stack, requires lot of integration

docs/overview/architecture.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Evolve uses a modular architecture where each component has a well-defined inter
4141

4242
The block package is the heart of ev-node. It's organized into specialized components:
4343

44-
| Component | Responsibility | Runs On |
45-
|-----------|---------------|---------|
46-
| **Executor** | Produces blocks by getting batches from sequencer and executing via execution layer | Aggregator only |
47-
| **Reaper** | Scrapes transactions from execution layer mempool and submits to sequencer | Aggregator only |
48-
| **Syncer** | Coordinates block sync from DA layer and P2P network | All nodes |
49-
| **Submitter** | Submits blocks to DA layer and tracks inclusion | Aggregator only |
50-
| **Cache** | Manages in-memory state for headers, data, and pending submissions | All nodes |
44+
| Component | Responsibility | Runs On |
45+
| ------------- | ----------------------------------------------------------------------------------- | --------------- |
46+
| **Executor** | Produces blocks by getting batches from sequencer and executing via execution layer | Aggregator only |
47+
| **Reaper** | Scrapes transactions from execution layer mempool and submits to sequencer | Aggregator only |
48+
| **Syncer** | Coordinates block sync from DA layer and P2P network | All nodes |
49+
| **Submitter** | Submits blocks to DA layer and tracks inclusion | Aggregator only |
50+
| **Cache** | Manages in-memory state for headers, data, and pending submissions | All nodes |
5151

5252
### Component Interaction
5353

@@ -81,12 +81,12 @@ The block package is the heart of ev-node. It's organized into specialized compo
8181

8282
Evolve supports several node configurations:
8383

84-
| Type | Block Production | Full Validation | DA Submission | Use Case |
85-
|------|-----------------|-----------------|---------------|----------|
86-
| **Aggregator** | Yes | Yes | Yes | Block producer (sequencer) |
87-
| **Full Node** | No | Yes | No | RPC provider, validator |
88-
| **Light Node** | No | Headers only | No | Mobile, embedded clients |
89-
| **Attester** | No | Yes | No | Soft consensus participant |
84+
| Type | Block Production | Full Validation | DA Submission | Use Case |
85+
| -------------- | ---------------- | --------------- | ------------- | -------------------------- |
86+
| **Aggregator** | Yes | Yes | Yes | Block producer (sequencer) |
87+
| **Full Node** | No | Yes | No | RPC provider, validator |
88+
| **Light Node** | No | Headers only | No | Mobile, embedded clients |
89+
| **Attester** | No | Yes | No | Soft consensus participant |
9090

9191
### Aggregator
9292

@@ -158,7 +158,7 @@ User Tx → Execution Layer Mempool
158158

159159
Built on libp2p with:
160160

161-
- **GossipSub** for transaction and block propagation
161+
- **FloodSub** for transaction and block propagation
162162
- **Kademlia DHT** for peer discovery
163163
- **Topics**: `{chainID}-tx`, `{chainID}-header`, `{chainID}-data`
164164

pkg/p2p/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ type P2PConfig struct {
5151

5252
### Configuration Parameters
5353

54-
| Parameter | Description | Default | Example |
55-
|-----------|-------------|---------|---------|
56-
| ListenAddress | The address where the node listens for incoming P2P connections | `/ip4/0.0.0.0/tcp/7676` | `/ip4/0.0.0.0/tcp/7676` |
57-
| Seeds | Comma-separated list of seed nodes (bootstrap nodes) | "" | `/ip4/1.2.3.4/tcp/7676/p2p/12D3KooWA8EXV3KjBxEU...,/ip4/5.6.7.8/tcp/7676/p2p/12D3KooWJN9ByvD...` |
58-
| BlockedPeers | Comma-separated list of peer IDs to block | "" | `12D3KooWA8EXV3KjBxEU...,12D3KooWJN9ByvD...` |
59-
| AllowedPeers | Comma-separated list of peer IDs to explicitly allow | "" | `12D3KooWA8EXV3KjBxEU...,12D3KooWJN9ByvD...` |
54+
| Parameter | Description | Default | Example |
55+
| ------------- | --------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------ |
56+
| ListenAddress | The address where the node listens for incoming P2P connections | `/ip4/0.0.0.0/tcp/7676` | `/ip4/0.0.0.0/tcp/7676` |
57+
| Seeds | Comma-separated list of seed nodes (bootstrap nodes) | "" | `/ip4/1.2.3.4/tcp/7676/p2p/12D3KooWA8EXV3KjBxEU...,/ip4/5.6.7.8/tcp/7676/p2p/12D3KooWJN9ByvD...` |
58+
| BlockedPeers | Comma-separated list of peer IDs to block | "" | `12D3KooWA8EXV3KjBxEU...,12D3KooWJN9ByvD...` |
59+
| AllowedPeers | Comma-separated list of peer IDs to explicitly allow | "" | `12D3KooWA8EXV3KjBxEU...,12D3KooWJN9ByvD...` |
6060

6161
## libp2p Components
6262

@@ -69,7 +69,7 @@ graph LR
6969
Client --> DHT["Kademlia DHT"]
7070
Client --> Discovery["Routing Discovery"]
7171
Client --> Gater["Connection Gater"]
72-
Client --> PubSub["GossipSub PubSub"]
72+
Client --> PubSub["FloodSub PubSub"]
7373
7474
Host --> Transport["Transport Protocols"]
7575
Host --> Security["Security Protocols"]
@@ -96,7 +96,7 @@ graph LR
9696
- Used for finding other peers within the same network
9797
- Bootstrapped with seed nodes defined in configuration
9898

99-
3. **GossipSub**: Publish-subscribe protocol for message dissemination
99+
3. **FloodSub**: Publish-subscribe protocol for message dissemination
100100
- Used for gossiping transactions, headers, and blocks
101101
- Provides efficient message propagation with reduced bandwidth overhead
102102
- Supports message validation through custom validators
@@ -118,7 +118,7 @@ sequenceDiagram
118118
participant P as P2P Client
119119
participant H as libp2p Host
120120
participant D as DHT
121-
participant G as GossipSub
121+
participant G as FloodSub
122122
participant N as Network/Other Peers
123123
124124
A->>P: NewClient(config, chainID, datastore, logger, metrics)
@@ -163,7 +163,7 @@ The P2P clients in full and light nodes handle transaction validation differentl
163163

164164
## Message Gossiping
165165

166-
Messages (transactions, blocks, etc.) are gossiped through the network using GossipSub topics. The topic format is:
166+
Messages (transactions, blocks, etc.) are gossiped through the network using FloodSub topics. The topic format is:
167167

168168
`<chainID>+<topicSuffix>`
169169

pkg/p2p/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func (c *Client) tryConnect(ctx context.Context, peer peer.AddrInfo) {
450450

451451
func (c *Client) setupGossiping(ctx context.Context) error {
452452
var err error
453-
c.ps, err = pubsub.NewGossipSub(ctx, c.host)
453+
c.ps, err = pubsub.NewFloodSub(ctx, c.host)
454454
if err != nil {
455455
return err
456456
}

0 commit comments

Comments
 (0)