Skip to content

Commit 86d74d8

Browse files
authored
feat(dkg): Implement bcast (#290)
* fix(proto): generated message implements Name * fix(testutil): Public ConstReader * feat(dkg): implement dkg/bcast * feat(dkg): implement example bcast * fix: add example instruction * fix: clippy fmt * fix: update bcast example ues relay * refactor(p2p): make read/write protobuf shareable * fix: address claude comments * fix: update docs * fix: remove unnecessary clone * fix: simplify error * fix: simplify code behaviour * fix: fmt * fix: move bcast new to behaviour * fix: remove PROTOCOL_ID_PREFIX * refactor: handler on_connection_event * fix: using NotifyHandler::Any instead of One * fix: only handle direct connection, not relay * fix: enum error * refactor: add p2p_context to behaviour * feat: add Complete and Fail event for bcast * fix: put local_peer_id to p2p_context * chore: run fmt * fix: use thiserror for Failure * fix: local_peer_id is OnceLock
1 parent a4a2ee5 commit 86d74d8

26 files changed

Lines changed: 2825 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/app/src/log/loki/lokipb/v1/loki.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ pub struct PushRequest {
99
#[prost(message, repeated, tag = "1")]
1010
pub streams: ::prost::alloc::vec::Vec<Stream>,
1111
}
12+
impl ::prost::Name for PushRequest {
13+
const NAME: &'static str = "PushRequest";
14+
const PACKAGE: &'static str = "loki";
15+
fn full_name() -> ::prost::alloc::string::String {
16+
"loki.PushRequest".into()
17+
}
18+
fn type_url() -> ::prost::alloc::string::String {
19+
"type.googleapis.com/loki.PushRequest".into()
20+
}
21+
}
1222
#[derive(Clone, PartialEq, ::prost::Message)]
1323
pub struct Stream {
1424
#[prost(string, tag = "1")]
@@ -18,10 +28,30 @@ pub struct Stream {
1828
#[prost(uint64, tag = "3")]
1929
pub hash: u64,
2030
}
31+
impl ::prost::Name for Stream {
32+
const NAME: &'static str = "Stream";
33+
const PACKAGE: &'static str = "loki";
34+
fn full_name() -> ::prost::alloc::string::String {
35+
"loki.Stream".into()
36+
}
37+
fn type_url() -> ::prost::alloc::string::String {
38+
"type.googleapis.com/loki.Stream".into()
39+
}
40+
}
2141
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
2242
pub struct Entry {
2343
#[prost(message, optional, tag = "1")]
2444
pub timestamp: ::core::option::Option<::prost_types::Timestamp>,
2545
#[prost(string, tag = "2")]
2646
pub line: ::prost::alloc::string::String,
47+
}
48+
impl ::prost::Name for Entry {
49+
const NAME: &'static str = "Entry";
50+
const PACKAGE: &'static str = "loki";
51+
fn full_name() -> ::prost::alloc::string::String {
52+
"loki.Entry".into()
53+
}
54+
fn type_url() -> ::prost::alloc::string::String {
55+
"type.googleapis.com/loki.Entry".into()
56+
}
2757
}

crates/build-proto/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ pub fn compile_protos(proto_dir: &str) -> Result<()> {
1818
}
1919

2020
let mut config = prost_build::Config::new();
21-
config.btree_map(["."]).bytes(["."]).out_dir(proto_dir);
21+
config
22+
.btree_map(["."])
23+
.bytes(["."])
24+
.enable_type_names()
25+
.type_name_domain(["."], "type.googleapis.com")
26+
.out_dir(proto_dir);
2227

2328
config.compile_protos(
2429
&proto_files.iter().map(|p| p.as_path()).collect::<Vec<_>>(),

crates/core/src/corepb/v1/consensus.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ pub struct QbftMsg {
2323
#[prost(bytes = "bytes", tag = "12")]
2424
pub prepared_value_hash: ::prost::bytes::Bytes,
2525
}
26+
impl ::prost::Name for QbftMsg {
27+
const NAME: &'static str = "QBFTMsg";
28+
const PACKAGE: &'static str = "consensus";
29+
fn full_name() -> ::prost::alloc::string::String {
30+
"consensus.QBFTMsg".into()
31+
}
32+
fn type_url() -> ::prost::alloc::string::String {
33+
"type.googleapis.com/consensus.QBFTMsg".into()
34+
}
35+
}
2636
#[derive(Clone, PartialEq, ::prost::Message)]
2737
pub struct QbftConsensusMsg {
2838
/// msg is the message that we send
@@ -35,6 +45,16 @@ pub struct QbftConsensusMsg {
3545
#[prost(message, repeated, tag = "3")]
3646
pub values: ::prost::alloc::vec::Vec<::prost_types::Any>,
3747
}
48+
impl ::prost::Name for QbftConsensusMsg {
49+
const NAME: &'static str = "QBFTConsensusMsg";
50+
const PACKAGE: &'static str = "consensus";
51+
fn full_name() -> ::prost::alloc::string::String {
52+
"consensus.QBFTConsensusMsg".into()
53+
}
54+
fn type_url() -> ::prost::alloc::string::String {
55+
"type.googleapis.com/consensus.QBFTConsensusMsg".into()
56+
}
57+
}
3858
#[derive(Clone, PartialEq, ::prost::Message)]
3959
pub struct SniffedConsensusMsg {
4060
#[prost(message, optional, tag = "1")]
@@ -43,6 +63,16 @@ pub struct SniffedConsensusMsg {
4363
#[prost(message, optional, tag = "2")]
4464
pub msg: ::core::option::Option<QbftConsensusMsg>,
4565
}
66+
impl ::prost::Name for SniffedConsensusMsg {
67+
const NAME: &'static str = "SniffedConsensusMsg";
68+
const PACKAGE: &'static str = "consensus";
69+
fn full_name() -> ::prost::alloc::string::String {
70+
"consensus.SniffedConsensusMsg".into()
71+
}
72+
fn type_url() -> ::prost::alloc::string::String {
73+
"type.googleapis.com/consensus.SniffedConsensusMsg".into()
74+
}
75+
}
4676
#[derive(Clone, PartialEq, ::prost::Message)]
4777
pub struct SniffedConsensusInstance {
4878
#[prost(message, optional, tag = "1")]
@@ -56,10 +86,30 @@ pub struct SniffedConsensusInstance {
5686
#[prost(string, tag = "5")]
5787
pub protocol_id: ::prost::alloc::string::String,
5888
}
89+
impl ::prost::Name for SniffedConsensusInstance {
90+
const NAME: &'static str = "SniffedConsensusInstance";
91+
const PACKAGE: &'static str = "consensus";
92+
fn full_name() -> ::prost::alloc::string::String {
93+
"consensus.SniffedConsensusInstance".into()
94+
}
95+
fn type_url() -> ::prost::alloc::string::String {
96+
"type.googleapis.com/consensus.SniffedConsensusInstance".into()
97+
}
98+
}
5999
#[derive(Clone, PartialEq, ::prost::Message)]
60100
pub struct SniffedConsensusInstances {
61101
#[prost(message, repeated, tag = "1")]
62102
pub instances: ::prost::alloc::vec::Vec<SniffedConsensusInstance>,
63103
#[prost(string, tag = "2")]
64104
pub git_hash: ::prost::alloc::string::String,
105+
}
106+
impl ::prost::Name for SniffedConsensusInstances {
107+
const NAME: &'static str = "SniffedConsensusInstances";
108+
const PACKAGE: &'static str = "consensus";
109+
fn full_name() -> ::prost::alloc::string::String {
110+
"consensus.SniffedConsensusInstances".into()
111+
}
112+
fn type_url() -> ::prost::alloc::string::String {
113+
"type.googleapis.com/consensus.SniffedConsensusInstances".into()
114+
}
65115
}

crates/core/src/corepb/v1/core.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ pub struct Duty {
1414
#[prost(int32, tag = "2")]
1515
pub r#type: i32,
1616
}
17+
impl ::prost::Name for Duty {
18+
const NAME: &'static str = "Duty";
19+
const PACKAGE: &'static str = "core";
20+
fn full_name() -> ::prost::alloc::string::String {
21+
"core.Duty".into()
22+
}
23+
fn type_url() -> ::prost::alloc::string::String {
24+
"type.googleapis.com/core.Duty".into()
25+
}
26+
}
1727
/// core.UnsignedDataSet
1828
#[derive(Clone, PartialEq, ::prost::Message)]
1929
pub struct UnsignedDataSet {
@@ -24,6 +34,16 @@ pub struct UnsignedDataSet {
2434
::prost::bytes::Bytes,
2535
>,
2636
}
37+
impl ::prost::Name for UnsignedDataSet {
38+
const NAME: &'static str = "UnsignedDataSet";
39+
const PACKAGE: &'static str = "core";
40+
fn full_name() -> ::prost::alloc::string::String {
41+
"core.UnsignedDataSet".into()
42+
}
43+
fn type_url() -> ::prost::alloc::string::String {
44+
"type.googleapis.com/core.UnsignedDataSet".into()
45+
}
46+
}
2747
/// core.ParSignedDataSet
2848
#[derive(Clone, PartialEq, ::prost::Message)]
2949
pub struct ParSignedDataSet {
@@ -34,6 +54,16 @@ pub struct ParSignedDataSet {
3454
ParSignedData,
3555
>,
3656
}
57+
impl ::prost::Name for ParSignedDataSet {
58+
const NAME: &'static str = "ParSignedDataSet";
59+
const PACKAGE: &'static str = "core";
60+
fn full_name() -> ::prost::alloc::string::String {
61+
"core.ParSignedDataSet".into()
62+
}
63+
fn type_url() -> ::prost::alloc::string::String {
64+
"type.googleapis.com/core.ParSignedDataSet".into()
65+
}
66+
}
3767
/// core.ParSignedData
3868
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
3969
pub struct ParSignedData {
@@ -46,4 +76,14 @@ pub struct ParSignedData {
4676
/// int
4777
#[prost(int32, tag = "3")]
4878
pub share_idx: i32,
79+
}
80+
impl ::prost::Name for ParSignedData {
81+
const NAME: &'static str = "ParSignedData";
82+
const PACKAGE: &'static str = "core";
83+
fn full_name() -> ::prost::alloc::string::String {
84+
"core.ParSignedData".into()
85+
}
86+
fn type_url() -> ::prost::alloc::string::String {
87+
"type.googleapis.com/core.ParSignedData".into()
88+
}
4989
}

crates/core/src/corepb/v1/parsigex.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ pub struct ParSigExMsg {
1010
pub duty: ::core::option::Option<super::core::Duty>,
1111
#[prost(message, optional, tag = "2")]
1212
pub data_set: ::core::option::Option<super::core::ParSignedDataSet>,
13+
}
14+
impl ::prost::Name for ParSigExMsg {
15+
const NAME: &'static str = "ParSigExMsg";
16+
const PACKAGE: &'static str = "parsigex";
17+
fn full_name() -> ::prost::alloc::string::String {
18+
"parsigex.ParSigExMsg".into()
19+
}
20+
fn type_url() -> ::prost::alloc::string::String {
21+
"type.googleapis.com/parsigex.ParSigExMsg".into()
22+
}
1323
}

crates/core/src/corepb/v1/priority.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ pub struct PriorityResult {
1212
#[prost(message, repeated, tag = "2")]
1313
pub topics: ::prost::alloc::vec::Vec<PriorityTopicResult>,
1414
}
15+
impl ::prost::Name for PriorityResult {
16+
const NAME: &'static str = "PriorityResult";
17+
const PACKAGE: &'static str = "priority";
18+
fn full_name() -> ::prost::alloc::string::String {
19+
"priority.PriorityResult".into()
20+
}
21+
fn type_url() -> ::prost::alloc::string::String {
22+
"type.googleapis.com/priority.PriorityResult".into()
23+
}
24+
}
1525
/// PriorityMsg defines all the priorities and metadata of a single peer in the Prioritiser protocol.
1626
#[derive(Clone, PartialEq, ::prost::Message)]
1727
pub struct PriorityMsg {
@@ -24,6 +34,16 @@ pub struct PriorityMsg {
2434
#[prost(bytes = "bytes", tag = "4")]
2535
pub signature: ::prost::bytes::Bytes,
2636
}
37+
impl ::prost::Name for PriorityMsg {
38+
const NAME: &'static str = "PriorityMsg";
39+
const PACKAGE: &'static str = "priority";
40+
fn full_name() -> ::prost::alloc::string::String {
41+
"priority.PriorityMsg".into()
42+
}
43+
fn type_url() -> ::prost::alloc::string::String {
44+
"type.googleapis.com/priority.PriorityMsg".into()
45+
}
46+
}
2747
/// PriorityTopicProposal defines a single peers proposed priorities for a single topic in the Prioritiser protocol.
2848
#[derive(Clone, PartialEq, ::prost::Message)]
2949
pub struct PriorityTopicProposal {
@@ -32,6 +52,16 @@ pub struct PriorityTopicProposal {
3252
#[prost(message, repeated, tag = "2")]
3353
pub priorities: ::prost::alloc::vec::Vec<::prost_types::Any>,
3454
}
55+
impl ::prost::Name for PriorityTopicProposal {
56+
const NAME: &'static str = "PriorityTopicProposal";
57+
const PACKAGE: &'static str = "priority";
58+
fn full_name() -> ::prost::alloc::string::String {
59+
"priority.PriorityTopicProposal".into()
60+
}
61+
fn type_url() -> ::prost::alloc::string::String {
62+
"type.googleapis.com/priority.PriorityTopicProposal".into()
63+
}
64+
}
3565
/// PriorityTopicResult defines the cluster wide resulting priorities for a
3666
/// single topic in the Prioritiser protocol.
3767
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -42,11 +72,31 @@ pub struct PriorityTopicResult {
4272
#[prost(message, repeated, tag = "2")]
4373
pub priorities: ::prost::alloc::vec::Vec<PriorityScoredResult>,
4474
}
75+
impl ::prost::Name for PriorityTopicResult {
76+
const NAME: &'static str = "PriorityTopicResult";
77+
const PACKAGE: &'static str = "priority";
78+
fn full_name() -> ::prost::alloc::string::String {
79+
"priority.PriorityTopicResult".into()
80+
}
81+
fn type_url() -> ::prost::alloc::string::String {
82+
"type.googleapis.com/priority.PriorityTopicResult".into()
83+
}
84+
}
4585
/// PriorityScoredResult defines the cluster wide priority score in the Prioritiser protocol.
4686
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
4787
pub struct PriorityScoredResult {
4888
#[prost(message, optional, tag = "1")]
4989
pub priority: ::core::option::Option<::prost_types::Any>,
5090
#[prost(int64, tag = "2")]
5191
pub score: i64,
92+
}
93+
impl ::prost::Name for PriorityScoredResult {
94+
const NAME: &'static str = "PriorityScoredResult";
95+
const PACKAGE: &'static str = "priority";
96+
fn full_name() -> ::prost::alloc::string::String {
97+
"priority.PriorityScoredResult".into()
98+
}
99+
fn type_url() -> ::prost::alloc::string::String {
100+
"type.googleapis.com/priority.PriorityScoredResult".into()
101+
}
52102
}

crates/dkg/Cargo.toml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ publish.workspace = true
99
[dependencies]
1010
prost.workspace = true
1111
prost-types.workspace = true
12+
thiserror.workspace = true
13+
libp2p.workspace = true
14+
futures.workspace = true
15+
tokio.workspace = true
16+
sha2.workspace = true
17+
tracing.workspace = true
18+
either.workspace = true
19+
k256.workspace = true
20+
pluto-k1util.workspace = true
21+
pluto-p2p.workspace = true
1222
pluto-cluster.workspace = true
1323
pluto-crypto.workspace = true
1424
pluto-eth1wrap.workspace = true
@@ -17,17 +27,22 @@ hex.workspace = true
1727
rand.workspace = true
1828
serde.workspace = true
1929
serde_json.workspace = true
20-
thiserror.workspace = true
21-
tokio.workspace = true
22-
tracing.workspace = true
2330
url.workspace = true
2431
zeroize.workspace = true
2532

2633
[build-dependencies]
2734
pluto-build-proto.workspace = true
2835

2936
[dev-dependencies]
37+
anyhow.workspace = true
38+
clap.workspace = true
39+
hex.workspace = true
3040
pluto-cluster = { workspace = true, features = ["test-cluster"] }
41+
pluto-core.workspace = true
42+
pluto-testutil.workspace = true
43+
pluto-tracing.workspace = true
44+
serde_json.workspace = true
45+
tokio-util.workspace = true
3146
tempfile.workspace = true
3247

3348
[lints]

0 commit comments

Comments
 (0)