From 6ec4b6a3ad821559eeaa8c93c45a73c72b305c6e Mon Sep 17 00:00:00 2001 From: Daniel Knopik <107140945+dknopik@users.noreply.github.com> Date: Mon, 16 Dec 2024 06:11:25 +0100 Subject: [PATCH 1/2] Enforce alphabetically ordered cargo deps (#71) Co-authored-by: Mac L --- .github/workflows/test-suite.yml | 15 +++++++++++++++ Cargo.toml | 12 ++++++------ anchor/Cargo.toml | 6 +++--- anchor/client/Cargo.toml | 25 ++++++++++++------------- anchor/common/ssv_types/Cargo.toml | 6 +++--- anchor/common/version/Cargo.toml | 2 +- anchor/http_api/Cargo.toml | 4 ++-- anchor/http_metrics/Cargo.toml | 4 ++-- anchor/network/Cargo.toml | 16 ++++++++-------- anchor/processor/Cargo.toml | 10 +++++----- anchor/qbft/Cargo.toml | 4 ++-- 11 files changed, 59 insertions(+), 45 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index ca6e98a..8877949 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -192,3 +192,18 @@ jobs: # cache-target: release # - name: Run Makefile to trigger the bash script # run: make cli + cargo-sort: + name: cargo-sort + needs: [check-labels] + if: needs.check-labels.outputs.skip_ci != 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Get latest version of stable Rust + uses: moonrepo/setup-rust@v1 + with: + channel: stable + cache-target: release + bins: cargo-sort + - name: Run cargo sort to check if Cargo.toml files are sorted + run: cargo sort --check --workspace diff --git a/Cargo.toml b/Cargo.toml index 8fd1fda..aa1e61d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,13 +3,13 @@ members = [ "anchor", "anchor/client", + "anchor/common/ssv_types", "anchor/common/version", "anchor/http_api", "anchor/http_metrics", "anchor/network", "anchor/processor", "anchor/qbft", - "anchor/common/ssv_types", ] resolver = "2" @@ -21,11 +21,11 @@ client = { path = "anchor/client" } qbft = { path = "anchor/qbft" } http_api = { path = "anchor/http_api" } http_metrics = { path = "anchor/http_metrics" } -network = { path ="anchor/network"} -version = { path ="anchor/common/version"} +network = { path = "anchor/network" } +version = { path = "anchor/common/version" } processor = { path = "anchor/processor" } ssv_types = { path = "anchor/common/ssv_types" } -lighthouse_network = { git = "https://github.com/sigp/lighthouse", branch = "unstable"} +lighthouse_network = { git = "https://github.com/sigp/lighthouse", branch = "unstable" } task_executor = { git = "https://github.com/sigp/lighthouse", branch = "unstable", default-features = false, features = [ "tracing", ] } metrics = { git = "https://github.com/agemanning/lighthouse", branch = "modularize-vc" } validator_metrics = { git = "https://github.com/agemanning/lighthouse", branch = "modularize-vc" } @@ -36,12 +36,12 @@ types = { git = "https://github.com/sigp/lighthouse", branch = "unstable" } derive_more = { version = "1.0.0", features = ["full"] } async-channel = "1.9" axum = "0.7.7" -clap = { version = "4.5.15", features = ["derive", "wrap_help"]} +clap = { version = "4.5.15", features = ["derive", "wrap_help"] } discv5 = "0.8.0" dirs = "5.0.1" either = "1.13.0" futures = "0.3.30" -tower-http = {version = "0.6", features = ["cors"] } +tower-http = { version = "0.6", features = ["cors"] } hyper = "1.4" num_cpus = "1" parking_lot = "0.12" diff --git a/anchor/Cargo.toml b/anchor/Cargo.toml index 1c9dd15..7cbea88 100644 --- a/anchor/Cargo.toml +++ b/anchor/Cargo.toml @@ -6,16 +6,16 @@ authors = ["Sigma Prime "] rust-version = "1.81.0" [dependencies] -task_executor = { workspace = true } -sensitive_url = { workspace = true } async-channel = { workspace = true } clap = { workspace = true } +client = { workspace = true } dirs = { workspace = true } futures = { workspace = true } +sensitive_url = { workspace = true } serde = { workspace = true } +task_executor = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } -client = { workspace = true } tracing-subscriber = { workspace = true } [dev-dependencies] diff --git a/anchor/client/Cargo.toml b/anchor/client/Cargo.toml index 2b1e53e..dfb3c40 100644 --- a/anchor/client/Cargo.toml +++ b/anchor/client/Cargo.toml @@ -9,22 +9,21 @@ name = "client" path = "src/lib.rs" [dependencies] -task_executor = { workspace = true } -http_api = { workspace = true } -version = { workspace = true } -http_metrics = { workspace = true } clap = { workspace = true } -serde = { workspace = true } -strum = { workspace = true } -sensitive_url = { workspace = true } dirs = { workspace = true } +ethereum_hashing = "0.7.0" +fdlimit = "0.3" +http_api = { workspace = true } +http_metrics = { workspace = true } hyper = { workspace = true } -tracing = { workspace = true } network = { workspace = true } -unused_port = { workspace = true } -tokio = { workspace = true } parking_lot = { workspace = true } processor = { workspace = true } -# Local dependencies -fdlimit = "0.3" -ethereum_hashing = "0.7.0" +sensitive_url = { workspace = true } +serde = { workspace = true } +strum = { workspace = true } +task_executor = { workspace = true } +tokio = { workspace = true } +tracing = { workspace = true } +unused_port = { workspace = true } +version = { workspace = true } diff --git a/anchor/common/ssv_types/Cargo.toml b/anchor/common/ssv_types/Cargo.toml index 1d6b713..5741ce1 100644 --- a/anchor/common/ssv_types/Cargo.toml +++ b/anchor/common/ssv_types/Cargo.toml @@ -5,7 +5,7 @@ edition = { workspace = true } authors = ["Sigma Prime "] [dependencies] -types = { workspace = true} -openssl = { workspace = true } -derive_more = { workspace = true } base64 = { workspace = true } +derive_more = { workspace = true } +openssl = { workspace = true } +types = { workspace = true } diff --git a/anchor/common/version/Cargo.toml b/anchor/common/version/Cargo.toml index a893e3c..6ab3a7a 100644 --- a/anchor/common/version/Cargo.toml +++ b/anchor/common/version/Cargo.toml @@ -8,4 +8,4 @@ git-version = "0.3.9" target_info = "0.1.0" [dev-dependencies] -regex = "1.11" \ No newline at end of file +regex = "1.11" diff --git a/anchor/http_api/Cargo.toml b/anchor/http_api/Cargo.toml index 9873a81..7769bf0 100644 --- a/anchor/http_api/Cargo.toml +++ b/anchor/http_api/Cargo.toml @@ -9,9 +9,9 @@ name = "http_api" path = "src/lib.rs" [dependencies] -task_executor = { workspace = true } axum = { workspace = true } -slot_clock = { workspace = true } serde = { workspace = true } +slot_clock = { workspace = true } +task_executor = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } diff --git a/anchor/http_metrics/Cargo.toml b/anchor/http_metrics/Cargo.toml index 7048b70..fbf931c 100644 --- a/anchor/http_metrics/Cargo.toml +++ b/anchor/http_metrics/Cargo.toml @@ -5,12 +5,12 @@ edition = "2021" [dependencies] axum = { workspace = true } +metrics = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true } +tokio = { workspace = true } tower-http = { workspace = true } tracing = { workspace = true } -tokio = { workspace = true } validator_metrics = { workspace = true } -metrics = { workspace = true } # Group dependencies warp_utils = { git = "https://github.com/agemanning/lighthouse", branch = "modularize-vc" } diff --git a/anchor/network/Cargo.toml b/anchor/network/Cargo.toml index 73801a6..b3b9946 100644 --- a/anchor/network/Cargo.toml +++ b/anchor/network/Cargo.toml @@ -5,16 +5,16 @@ edition = { workspace = true } authors = ["Sigma Prime "] [dependencies] -tokio = { workspace = true } -libp2p = { version = "0.54", default-features = false, features = ["identify", "yamux", "noise", "secp256k1", "tcp", "tokio", "macros", "gossipsub", "quic", "ping"] } -futures = { workspace = true } -task_executor = { workspace = true } -version = { workspace = true } -lighthouse_network = { workspace = true} +dirs = { workspace = true } discv5 = { workspace = true } -dirs = { workspace = true } +futures = { workspace = true } +libp2p = { version = "0.54", default-features = false, features = ["identify", "yamux", "noise", "secp256k1", "tcp", "tokio", "macros", "gossipsub", "quic", "ping"] } +lighthouse_network = { workspace = true } serde = { workspace = true } +task_executor = { workspace = true } +tokio = { workspace = true } tracing = { workspace = true } +version = { workspace = true } [dev-dependencies] -async-channel = { workspace = true } \ No newline at end of file +async-channel = { workspace = true } diff --git a/anchor/processor/Cargo.toml b/anchor/processor/Cargo.toml index c0e5c01..c81984c 100644 --- a/anchor/processor/Cargo.toml +++ b/anchor/processor/Cargo.toml @@ -5,13 +5,13 @@ authors = ["Sigma Prime Date: Tue, 17 Dec 2024 05:27:12 +0100 Subject: [PATCH 2/2] Add gossipsub behaviour (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: jking-aus <72330194+jking-aus@users.noreply.github.com> Co-authored-by: João Oliveira --- anchor/network/src/behaviour.rs | 6 ++-- anchor/network/src/network.rs | 62 +++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/anchor/network/src/behaviour.rs b/anchor/network/src/behaviour.rs index 23e88fe..f52459a 100644 --- a/anchor/network/src/behaviour.rs +++ b/anchor/network/src/behaviour.rs @@ -1,5 +1,5 @@ use libp2p::swarm::NetworkBehaviour; -use libp2p::{identify, ping}; +use libp2p::{gossipsub, identify, ping}; #[derive(NetworkBehaviour)] pub struct AnchorBehaviour { @@ -7,6 +7,6 @@ pub struct AnchorBehaviour { pub identify: identify::Behaviour, /// Used for connection health checks. pub ping: ping::Behaviour, - // /// The routing pub-sub mechanism for Anchor. - // pub gossipsub: gossipsub::Behaviour, + /// The routing pub-sub mechanism for Anchor. + pub gossipsub: gossipsub::Behaviour, } diff --git a/anchor/network/src/network.rs b/anchor/network/src/network.rs index 1b4192b..dc0325a 100644 --- a/anchor/network/src/network.rs +++ b/anchor/network/src/network.rs @@ -1,17 +1,22 @@ use crate::behaviour::AnchorBehaviour; +use crate::behaviour::AnchorBehaviourEvent; use crate::keypair_utils::load_private_key; use crate::transport::build_transport; use crate::Config; use futures::StreamExt; use libp2p::core::muxing::StreamMuxerBox; use libp2p::core::transport::Boxed; +use libp2p::gossipsub::{MessageAuthenticity, ValidationMode}; use libp2p::identity::Keypair; use libp2p::multiaddr::Protocol; -use libp2p::{futures, identify, ping, PeerId, Swarm, SwarmBuilder}; +use libp2p::swarm::SwarmEvent; +use libp2p::{futures, gossipsub, identify, ping, PeerId, Swarm, SwarmBuilder}; +use lighthouse_network::discv5::enr::k256::sha2::{Digest, Sha256}; use std::num::{NonZeroU8, NonZeroUsize}; use std::pin::Pin; +use std::time::Duration; use task_executor::TaskExecutor; -use tracing::info; +use tracing::{info, log}; pub struct Network { swarm: Swarm, @@ -74,8 +79,22 @@ impl Network { pub async fn run(mut self) { loop { tokio::select! { - _swarm_message = self.swarm.select_next_some() => { - // TODO handle and match swarm messages + swarm_message = self.swarm.select_next_some() => { + match swarm_message { + SwarmEvent::Behaviour(behaviour_event) => match behaviour_event { + AnchorBehaviourEvent::Gossipsub(_ge) => { + // TODO handle gossipsub events + }, + // TODO handle other behaviour events + _ => { + log::debug!("Unhandled behaviour event: {:?}", behaviour_event); + } + }, + // TODO handle other swarm events + _ => { + log::debug!("Unhandled swarm event: {:?}", swarm_message); + } + } } // TODO match input channels } @@ -84,8 +103,7 @@ impl Network { } fn build_anchor_behaviour(local_keypair: Keypair) -> AnchorBehaviour { - // setup gossipsub - // discv5 + // TODO setup discv5 let identify = { let local_public_key = local_keypair.public(); let identify_config = identify::Config::new("anchor".into(), local_public_key) @@ -94,10 +112,40 @@ fn build_anchor_behaviour(local_keypair: Keypair) -> AnchorBehaviour { identify::Behaviour::new(identify_config) }; + // TODO those values might need to be parameterized based on the network + let slots_per_epoch = 32; + let seconds_per_slot = 12; + let duplicate_cache_time = Duration::from_secs(slots_per_epoch * seconds_per_slot); // 6.4 min + + let gossip_message_id = move |message: &gossipsub::Message| { + gossipsub::MessageId::from(&Sha256::digest(&message.data)[..20]) + }; + + // TODO Add Topic Message Validator and Subscription Filter + let config = gossipsub::ConfigBuilder::default() + .duplicate_cache_time(duplicate_cache_time) + .message_id_fn(gossip_message_id) + .flood_publish(false) + .validation_mode(ValidationMode::Strict) + .mesh_n(8) //D + .mesh_n_low(6) // Dlo + .mesh_n_high(12) // Dhi + .mesh_outbound_min(4) // Dout + .heartbeat_interval(Duration::from_millis(700)) + .history_length(6) + .history_gossip(4) + .max_ihave_length(1500) + .max_ihave_messages(32) + .build() + .unwrap(); + + let gossipsub = + gossipsub::Behaviour::new(MessageAuthenticity::Signed(local_keypair), config).unwrap(); + AnchorBehaviour { identify, ping: ping::Behaviour::default(), - // gossipsub: gossipsub::Behaviour::default(), + gossipsub, } }