Skip to content

Commit 8546ddd

Browse files
authored
feat(dkg): implement sync (#311)
* fix: correct sync proto * feat: add read/write fixed size proto * feat: initial implementation of sync * fix: skip relay connection handler * refactor: simplify sync client * refactor: inline functions * fix: don't need to self-manage pending dial * fix: simplify code write/read proto * feat: add events * feat: implement example sync * fix: clear server connected state * fix: simplify code * fix: sync example allow a peer is disconnected * fix: clippy * fix: retry connect when dial fail * fix: Client cancel will stop outbound stream * fix: remove decode and encode error * fix: check stop_rx when return canceled * fix: drop duplicated inbound sync * fix: initial backoff on retry * fix: don't retry on NegotiationFailed * fix: check server error on await_all_Shutdown * fix: add comments * refactor: avoid double hash * fix: fmt * fix: address comments * fix: set max msg size to 32MB for sync msg * fix: update sync example * fix: sync example now use pluto create cluster * fix: bcast example now use pluto create cluster * fix: update sync example to use the p2p_context in side node * fix: change log level of relay event * fix: remove PartialEq and Eq on error * fix: address comments * fix: clippy * fix: duplicate key in cargo.toml * fix: test * fix: single lock for client state * fix: finish should acquire the lock once * fix: call server.clear_connected on ConnectionClosed * fix: handler sleep more when the outbound is claimed * fix: check all type of relay io error * fix: add PeerRttObserved event * fix: retry on NoAddresses also * fix: make state.error one-shot, only retain the first error * fix: handle NoAddresses retry properly, wait a time * refactor: simplify retry logic * fix: add more test for edge cases * doc: add documentation for for sync package * doc: add documentation for for sync package * fix: compile error after merge
1 parent e8099c8 commit 8546ddd

15 files changed

Lines changed: 3370 additions & 54 deletions

File tree

crates/dkg/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ license.workspace = true
77
publish.workspace = true
88

99
[dependencies]
10+
bon.workspace = true
1011
prost.workspace = true
1112
prost-types.workspace = true
1213
thiserror.workspace = true
13-
bon.workspace = true
1414
libp2p.workspace = true
1515
futures.workspace = true
1616
tokio.workspace = true
@@ -51,7 +51,6 @@ pluto-cluster = { workspace = true, features = ["test-cluster"] }
5151
pluto-testutil.workspace = true
5252
pluto-tracing.workspace = true
5353
serde_json.workspace = true
54-
tokio-util.workspace = true
5554
tempfile.workspace = true
5655
wiremock.workspace = true
5756

crates/dkg/examples/bcast.rs

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,45 @@
1-
//! Relay-based example for the DKG reliable-broadcast protocol.
2-
//!
3-
//! This example follows the same high-level shape as the `bootnode` example:
4-
//! - load a local private key from a data directory
5-
//! - load cluster peers from `cluster-lock.json`
6-
//! - resolve relay URLs with `bootnode::new_relays`
7-
//! - create relay reservations and relay routing
8-
//! - run `bcast` over relay-mediated connectivity
1+
//! Example for the DKG reliable-broadcast protocol.
92
//!
103
//! To try it locally:
114
//!
125
//! ```text
13-
//! # Terminal 1: start a relay server
14-
//! cargo run -p pluto-relay-server --example relay_server
6+
//! # Data preparation: create a local 3-node cluster fixture
7+
//! cargo run -p pluto-cli -- create cluster \
8+
//! --cluster-dir /tmp/pluto-bcast-demo \
9+
//! --name bcast-demo \
10+
//! --network holesky \
11+
//! --nodes 3 \
12+
//! --num-validators 1 \
13+
//! --insecure-keys \
14+
//! --fee-recipient-addresses 0x000000000000000000000000000000000000dead \
15+
//! --withdrawal-addresses 0x000000000000000000000000000000000000dead
1516
//!
16-
//! # Terminals 2-4: run three node directories from the same cluster
17+
//! # Run in 3 terminals against the generated node directories
1718
//! cargo run -p pluto-dkg --example bcast -- \
18-
//! --relays http://127.0.0.1:8888 \
19-
//! --data-dir /path/to/node0
19+
//! --relays https://0.relay.obol.tech,https://1.relay.obol.tech \
20+
//! --data-dir /tmp/pluto-bcast-demo/node0
2021
//!
2122
//! cargo run -p pluto-dkg --example bcast -- \
22-
//! --relays http://127.0.0.1:8888 \
23-
//! --data-dir /path/to/node1
23+
//! --relays https://0.relay.obol.tech,https://1.relay.obol.tech \
24+
//! --data-dir /tmp/pluto-bcast-demo/node1
2425
//!
2526
//! cargo run -p pluto-dkg --example bcast -- \
26-
//! --relays http://127.0.0.1:8888 \
27-
//! --data-dir /path/to/node2
27+
//! --relays https://0.relay.obol.tech,https://1.relay.obol.tech \
28+
//! --data-dir /tmp/pluto-bcast-demo/node2
2829
//! ```
2930
//!
30-
//! Assumption:
31-
//! - the three data directories already exist
32-
//! - each one belongs to one node in the same cluster
33-
//!
34-
//! Required files in each data directory:
35-
//! - `charon-enr-private-key`
36-
//! - `cluster-lock.json`
31+
//! For stable local repros or CI-style runs, prefer a self-hosted relay
32+
//! instead of shared public relays.
3733
//!
38-
//! Expected flow:
39-
//! 1. Each node loads the same cluster peer order from the lock file.
40-
//! 2. Nodes resolve the configured relays and establish relay reservations.
41-
//! 3. The relay router dials known cluster peers through relay circuits.
42-
//! 4. Once all cluster peers are connected, each node sends one signed
43-
//! `DemoTick`.
44-
//! 5. Receiver logs show inbound signature requests and final broadcasts.
45-
//!
46-
//! Success signals:
34+
//! What to expect:
35+
//! - all nodes must use the same `--relays` value
4736
//! - `Relay reservation accepted`
48-
//! - `Connection established` with `peer_type="CLUSTER"`
49-
//! - `Cluster connectivity update connected=2 expected=2`
5037
//! - `Sending broadcast`
5138
//! - `Received signature request`
5239
//! - `Received broadcast`
5340
//!
54-
//! Transient relay warnings can occur during startup and reconnects. The demo
55-
//! is healthy once all cluster peers are connected and the single broadcast is
56-
//! delivered.
57-
//!
5841
//! The demo uses a single fixed message ID because `bcast` is intended for
5942
//! one-shot protocol-step messages, not a changing heartbeat stream.
60-
#![allow(missing_docs)]
6143
6244
use std::{
6345
collections::{HashMap, HashSet},
@@ -110,7 +92,8 @@ struct Args {
11092
relays: Vec<String>,
11193

11294
/// Data directory containing `charon-enr-private-key` and
113-
/// `cluster-lock.json`.
95+
/// `cluster-lock.json`, typically one of the `nodeN/` directories produced
96+
/// by `pluto create cluster`.
11497
#[arg(long)]
11598
data_dir: PathBuf,
11699

0 commit comments

Comments
 (0)