diff --git a/.github/workflows/protobuf_conformance.yaml b/.github/workflows/protobuf_conformance.yaml index 6027b84f..eac65e28 100644 --- a/.github/workflows/protobuf_conformance.yaml +++ b/.github/workflows/protobuf_conformance.yaml @@ -28,7 +28,7 @@ jobs: path: "protobuf" - uses: mozilla-actions/sccache-action@v0.0.3 - name: build test - run: cargo build -p schema --bin conformance_test + run: cargo build -p zksync_consensus_schema --bin conformance_test working-directory: "this/node" - name: Cache Bazel uses: actions/cache@v3 diff --git a/docs/architecture.md b/docs/architecture.md index e2e5e863..15fc4cd5 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -8,7 +8,7 @@ The architecture of era-bft loosely follows the [Actor model](https://en.wikiped The actor crates are where the vast majority of the work is done. Each of them maintains its own separate state and communicate with each other through message passing. We have the following actor crates: -- the `consensus` crate implements the logic for the consensus algorithm. +- the `bft` crate implements the logic for the consensus algorithm. - the `executor` crate is responsible for parsing the configuration parameters given by the user, and initializing the actors and the storage. It's basically the bootloader for the node. It also dispatches messages between the rest of the actors. They all send messages to the executor and it then converts and forwards the messages to the desired destination. This improves the encapsulation of the actors. @@ -44,7 +44,7 @@ This section provides a physical map of folders & files in this repository. - `/actors`: Crates that implement specific actor components. - - `/consensus`: The consensus actor. + - `/bft`: The consensus actor. - `/executor`: The actor orchestrator. - `/network`: The networking actor. - `/sync_blocks`: The block syncing actor. @@ -58,4 +58,4 @@ This section provides a physical map of folders & files in this repository. - `/storage`: Storage layer for the node. - `/utils`: Collection of small utilities. - - `/tools`: Utility binaries needed to work with and test the node. \ No newline at end of file + - `/tools`: Utility binaries needed to work with and test the node. diff --git a/node/Cargo.lock b/node/Cargo.lock index 4bde4f56..920b83f9 100644 --- a/node/Cargo.lock +++ b/node/Cargo.lock @@ -558,43 +558,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "concurrency" -version = "0.1.0" -dependencies = [ - "anyhow", - "once_cell", - "pin-project", - "rand", - "sha2", - "thiserror", - "time", - "tokio", - "tracing", - "tracing-subscriber", - "vise", -] - -[[package]] -name = "consensus" -version = "0.1.0" -dependencies = [ - "anyhow", - "concurrency", - "crypto", - "network", - "once_cell", - "rand", - "roles", - "schema", - "storage", - "thiserror", - "tokio", - "tracing", - "utils", - "vise", -] - [[package]] name = "const-oid" version = "0.9.5" @@ -679,25 +642,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crypto" -version = "0.1.0" -dependencies = [ - "anyhow", - "ark-bn254", - "ark-ec", - "ark-serialize", - "blst", - "criterion", - "ed25519-dalek", - "hex", - "num-traits", - "rand", - "sha2", - "thiserror", - "tracing", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -855,26 +799,6 @@ dependencies = [ "libc", ] -[[package]] -name = "executor" -version = "0.1.0" -dependencies = [ - "anyhow", - "concurrency", - "consensus", - "crypto", - "network", - "rand", - "roles", - "schema", - "storage", - "sync_blocks", - "tokio", - "tracing", - "utils", - "vise", -] - [[package]] name = "fastrand" version = "2.0.0" @@ -1302,30 +1226,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "network" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "concurrency", - "crypto", - "im", - "once_cell", - "pin-project", - "pretty_assertions", - "rand", - "roles", - "schema", - "snow", - "test-casing", - "thiserror", - "tokio", - "tracing", - "utils", - "vise", -] - [[package]] name = "nom" version = "7.1.3" @@ -1926,22 +1826,6 @@ dependencies = [ "librocksdb-sys", ] -[[package]] -name = "roles" -version = "0.1.0" -dependencies = [ - "anyhow", - "bit-vec", - "concurrency", - "crypto", - "hex", - "rand", - "schema", - "serde", - "tracing", - "utils", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -1991,28 +1875,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schema" -version = "0.1.0" -dependencies = [ - "anyhow", - "bit-vec", - "concurrency", - "once_cell", - "prettyplease 0.2.12", - "prost", - "prost-build", - "prost-reflect", - "prost-reflect-build", - "protoc-bin-vendored", - "quick-protobuf", - "rand", - "serde", - "serde_json", - "syn 2.0.32", - "tokio", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -2175,25 +2037,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "storage" -version = "0.1.0" -dependencies = [ - "anyhow", - "assert_matches", - "async-trait", - "concurrency", - "rand", - "rocksdb", - "roles", - "schema", - "tempfile", - "test-casing", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "strsim" version = "0.10.0" @@ -2228,25 +2071,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_blocks" -version = "0.1.0" -dependencies = [ - "anyhow", - "assert_matches", - "async-trait", - "concurrency", - "network", - "rand", - "roles", - "storage", - "test-casing", - "thiserror", - "tokio", - "tracing", - "utils", -] - [[package]] name = "tempfile" version = "3.7.1" @@ -2376,27 +2200,6 @@ dependencies = [ "syn 2.0.32", ] -[[package]] -name = "tools" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "concurrency", - "consensus", - "crypto", - "executor", - "rand", - "roles", - "schema", - "storage", - "tokio", - "tracing", - "tracing-subscriber", - "utils", - "vise-exporter", -] - [[package]] name = "tower-service" version = "0.3.2" @@ -2499,14 +2302,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "utils" -version = "0.1.0" -dependencies = [ - "concurrency", - "thiserror", -] - [[package]] name = "valuable" version = "0.1.0" @@ -2802,6 +2597,211 @@ dependencies = [ "syn 2.0.32", ] +[[package]] +name = "zksync_concurrency" +version = "0.1.0" +dependencies = [ + "anyhow", + "once_cell", + "pin-project", + "rand", + "sha2", + "thiserror", + "time", + "tokio", + "tracing", + "tracing-subscriber", + "vise", +] + +[[package]] +name = "zksync_consensus_bft" +version = "0.1.0" +dependencies = [ + "anyhow", + "once_cell", + "rand", + "thiserror", + "tokio", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_schema", + "zksync_consensus_storage", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_crypto" +version = "0.1.0" +dependencies = [ + "anyhow", + "ark-bn254", + "ark-ec", + "ark-serialize", + "blst", + "criterion", + "ed25519-dalek", + "hex", + "num-traits", + "rand", + "sha2", + "thiserror", + "tracing", +] + +[[package]] +name = "zksync_consensus_executor" +version = "0.1.0" +dependencies = [ + "anyhow", + "rand", + "tokio", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_bft", + "zksync_consensus_crypto", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_schema", + "zksync_consensus_storage", + "zksync_consensus_sync_blocks", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_network" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "im", + "once_cell", + "pin-project", + "pretty_assertions", + "rand", + "snow", + "test-casing", + "thiserror", + "tokio", + "tracing", + "vise", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_roles", + "zksync_consensus_schema", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_roles" +version = "0.1.0" +dependencies = [ + "anyhow", + "bit-vec", + "hex", + "rand", + "serde", + "tracing", + "zksync_concurrency", + "zksync_consensus_crypto", + "zksync_consensus_schema", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_schema" +version = "0.1.0" +dependencies = [ + "anyhow", + "bit-vec", + "once_cell", + "prettyplease 0.2.12", + "prost", + "prost-build", + "prost-reflect", + "prost-reflect-build", + "protoc-bin-vendored", + "quick-protobuf", + "rand", + "serde", + "serde_json", + "syn 2.0.32", + "tokio", + "zksync_concurrency", +] + +[[package]] +name = "zksync_consensus_storage" +version = "0.1.0" +dependencies = [ + "anyhow", + "assert_matches", + "async-trait", + "rand", + "rocksdb", + "tempfile", + "test-casing", + "thiserror", + "tokio", + "tracing", + "zksync_concurrency", + "zksync_consensus_roles", + "zksync_consensus_schema", +] + +[[package]] +name = "zksync_consensus_sync_blocks" +version = "0.1.0" +dependencies = [ + "anyhow", + "assert_matches", + "async-trait", + "rand", + "test-casing", + "thiserror", + "tokio", + "tracing", + "zksync_concurrency", + "zksync_consensus_network", + "zksync_consensus_roles", + "zksync_consensus_storage", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_tools" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "rand", + "tokio", + "tracing", + "tracing-subscriber", + "vise-exporter", + "zksync_concurrency", + "zksync_consensus_bft", + "zksync_consensus_crypto", + "zksync_consensus_executor", + "zksync_consensus_roles", + "zksync_consensus_schema", + "zksync_consensus_storage", + "zksync_consensus_utils", +] + +[[package]] +name = "zksync_consensus_utils" +version = "0.1.0" +dependencies = [ + "thiserror", + "zksync_concurrency", +] + [[package]] name = "zstd-sys" version = "2.0.8+zstd.1.5.5" diff --git a/node/Cargo.toml b/node/Cargo.toml index e1a35c99..6e2b1185 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = [ "libs/concurrency", - "actors/consensus", + "actors/bft", "libs/crypto", "actors/executor", "actors/network", @@ -21,6 +21,18 @@ homepage = "https://matter-labs.io/" license = "MIT" [workspace.dependencies] +zksync_concurrency = { path = "libs/concurrency" } +zksync_consensus_bft = { path = "actors/bft" } +zksync_consensus_crypto = { path = "libs/crypto" } +zksync_consensus_executor = { path = "actors/executor" } +zksync_consensus_network = { path = "actors/network" } +zksync_consensus_sync_blocks = { path = "actors/sync_blocks" } +zksync_consensus_roles = { path = "libs/roles" } +zksync_consensus_schema = { path = "libs/schema" } +zksync_consensus_storage = { path = "libs/storage" } +zksync_consensus_tools = { path = "tools" } +zksync_consensus_utils = { path = "libs/utils" } + anyhow = "1" assert_matches = "1.5.0" async-trait = "0.1.71" @@ -78,7 +90,7 @@ panic = 'abort' [profile.release] panic = 'abort' -[profile.dev.package.crypto] +[profile.dev.package.zksync_consensus_crypto] opt-level = 3 # Compile all the external dependencies with optimizations, because diff --git a/node/actors/consensus/Cargo.toml b/node/actors/bft/Cargo.toml similarity index 51% rename from node/actors/consensus/Cargo.toml rename to node/actors/bft/Cargo.toml index b47c0d4f..5f61f2cf 100644 --- a/node/actors/consensus/Cargo.toml +++ b/node/actors/bft/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "consensus" +name = "zksync_consensus_bft" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,6 +7,14 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_crypto.workspace = true +zksync_consensus_network.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_schema.workspace = true +zksync_consensus_storage.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true once_cell.workspace = true rand.workspace = true @@ -14,14 +22,5 @@ thiserror.workspace = true tracing.workspace = true vise.workspace = true -concurrency = { path = "../../libs/concurrency" } -crypto = { path = "../../libs/crypto" } -roles = { path = "../../libs/roles" } -schema = { path = "../../libs/schema" } -storage = { path = "../../libs/storage" } -utils = { path = "../../libs/utils" } - -network = { path = "../network" } - [dev-dependencies] tokio.workspace = true diff --git a/node/actors/consensus/src/inner.rs b/node/actors/bft/src/inner.rs similarity index 93% rename from node/actors/consensus/src/inner.rs rename to node/actors/bft/src/inner.rs index 57acc7a5..56f8d57a 100644 --- a/node/actors/consensus/src/inner.rs +++ b/node/actors/bft/src/inner.rs @@ -4,9 +4,10 @@ use crate::{ io::{InputMessage, OutputMessage}, misc, }; -use roles::validator; use tracing::instrument; -use utils::pipe::ActorPipe; +use zksync_consensus_roles::validator; +use zksync_consensus_schema as schema; +use zksync_consensus_utils::pipe::ActorPipe; /// The ConsensusInner struct, it contains data to be shared with the state machines. This is never supposed /// to be modified, except by the Consensus struct. diff --git a/node/actors/consensus/src/io.rs b/node/actors/bft/src/io.rs similarity index 86% rename from node/actors/consensus/src/io.rs rename to node/actors/bft/src/io.rs index 775920b0..3636e051 100644 --- a/node/actors/consensus/src/io.rs +++ b/node/actors/bft/src/io.rs @@ -1,7 +1,7 @@ //! Input and output messages for the Consensus actor. These are processed by the executor actor. -use network::io::{ConsensusInputMessage, ConsensusReq}; -use roles::validator; +use zksync_consensus_network::io::{ConsensusInputMessage, ConsensusReq}; +use zksync_consensus_roles::validator; /// All the messages that other actors can send to the Consensus actor. #[derive(Debug)] diff --git a/node/actors/consensus/src/leader/mod.rs b/node/actors/bft/src/leader/mod.rs similarity index 100% rename from node/actors/consensus/src/leader/mod.rs rename to node/actors/bft/src/leader/mod.rs diff --git a/node/actors/consensus/src/leader/replica_commit.rs b/node/actors/bft/src/leader/replica_commit.rs similarity index 97% rename from node/actors/consensus/src/leader/replica_commit.rs rename to node/actors/bft/src/leader/replica_commit.rs index dd676f8c..fa7ea5cf 100644 --- a/node/actors/consensus/src/leader/replica_commit.rs +++ b/node/actors/bft/src/leader/replica_commit.rs @@ -1,9 +1,9 @@ use super::StateMachine; use crate::{inner::ConsensusInner, metrics}; -use concurrency::{ctx, metrics::LatencyHistogramExt as _}; -use network::io::{ConsensusInputMessage, Target}; -use roles::validator; use tracing::instrument; +use zksync_concurrency::{ctx, metrics::LatencyHistogramExt as _}; +use zksync_consensus_network::io::{ConsensusInputMessage, Target}; +use zksync_consensus_roles::validator; /// Errors that can occur when processing a "replica commit" message. #[derive(Debug, thiserror::Error)] diff --git a/node/actors/consensus/src/leader/replica_prepare.rs b/node/actors/bft/src/leader/replica_prepare.rs similarity index 98% rename from node/actors/consensus/src/leader/replica_prepare.rs rename to node/actors/bft/src/leader/replica_prepare.rs index 275f31f8..e15c1626 100644 --- a/node/actors/consensus/src/leader/replica_prepare.rs +++ b/node/actors/bft/src/leader/replica_prepare.rs @@ -1,11 +1,11 @@ use super::StateMachine; use crate::{inner::ConsensusInner, metrics}; -use concurrency::ctx; -use network::io::{ConsensusInputMessage, Target}; use rand::Rng; -use roles::validator; use std::collections::HashMap; use tracing::instrument; +use zksync_concurrency::ctx; +use zksync_consensus_network::io::{ConsensusInputMessage, Target}; +use zksync_consensus_roles::validator; /// Errors that can occur when processing a "replica prepare" message. #[derive(Debug, thiserror::Error)] diff --git a/node/actors/consensus/src/leader/state_machine.rs b/node/actors/bft/src/leader/state_machine.rs similarity index 97% rename from node/actors/consensus/src/leader/state_machine.rs rename to node/actors/bft/src/leader/state_machine.rs index a92ed26f..4380de83 100644 --- a/node/actors/consensus/src/leader/state_machine.rs +++ b/node/actors/bft/src/leader/state_machine.rs @@ -1,11 +1,11 @@ use crate::{metrics, ConsensusInner}; -use concurrency::{ctx, metrics::LatencyHistogramExt as _, time}; -use roles::validator; use std::{ collections::{BTreeMap, HashMap}, unreachable, }; use tracing::instrument; +use zksync_concurrency::{ctx, metrics::LatencyHistogramExt as _, time}; +use zksync_consensus_roles::validator; /// The StateMachine struct contains the state of the leader. This is a simple state machine. We just store /// replica messages and produce leader messages (including proposing blocks) when we reach the threshold for diff --git a/node/actors/consensus/src/leader/tests.rs b/node/actors/bft/src/leader/tests.rs similarity index 95% rename from node/actors/consensus/src/leader/tests.rs rename to node/actors/bft/src/leader/tests.rs index 2010b08f..dbdd156e 100644 --- a/node/actors/consensus/src/leader/tests.rs +++ b/node/actors/bft/src/leader/tests.rs @@ -1,7 +1,7 @@ use crate::testonly; -use concurrency::ctx; use rand::{rngs::StdRng, Rng, SeedableRng}; -use roles::validator; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator; // TODO(bruno): This only tests a particular case, not the whole method. #[tokio::test] diff --git a/node/actors/consensus/src/lib.rs b/node/actors/bft/src/lib.rs similarity index 96% rename from node/actors/consensus/src/lib.rs rename to node/actors/bft/src/lib.rs index db5c02c5..dcc0b142 100644 --- a/node/actors/consensus/src/lib.rs +++ b/node/actors/bft/src/lib.rs @@ -17,12 +17,12 @@ use crate::io::{InputMessage, OutputMessage}; use anyhow::Context as _; -use concurrency::ctx; use inner::ConsensusInner; -use roles::validator; -use storage::FallbackReplicaStateStore; use tracing::{info, instrument}; -use utils::pipe::ActorPipe; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator; +use zksync_consensus_storage::FallbackReplicaStateStore; +use zksync_consensus_utils::pipe::ActorPipe; mod inner; pub mod io; diff --git a/node/actors/consensus/src/metrics.rs b/node/actors/bft/src/metrics.rs similarity index 98% rename from node/actors/consensus/src/metrics.rs rename to node/actors/bft/src/metrics.rs index 46d61dfb..461403f7 100644 --- a/node/actors/consensus/src/metrics.rs +++ b/node/actors/bft/src/metrics.rs @@ -2,6 +2,7 @@ use std::time::Duration; use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics, Unit}; +use zksync_consensus_schema as schema; const PAYLOAD_SIZE_BUCKETS: Buckets = Buckets::exponential((4 * schema::kB) as f64..=(4 * schema::MB) as f64, 4.0); diff --git a/node/actors/consensus/src/misc.rs b/node/actors/bft/src/misc.rs similarity index 100% rename from node/actors/consensus/src/misc.rs rename to node/actors/bft/src/misc.rs diff --git a/node/actors/consensus/src/replica/block.rs b/node/actors/bft/src/replica/block.rs similarity index 97% rename from node/actors/consensus/src/replica/block.rs rename to node/actors/bft/src/replica/block.rs index 5591bf4b..92985b74 100644 --- a/node/actors/consensus/src/replica/block.rs +++ b/node/actors/bft/src/replica/block.rs @@ -1,7 +1,7 @@ use super::StateMachine; use crate::{inner::ConsensusInner, io::OutputMessage}; -use roles::validator; use tracing::{info, instrument}; +use zksync_consensus_roles::validator; impl StateMachine { /// Tries to build a finalized block from the given CommitQC. We simply search our diff --git a/node/actors/consensus/src/replica/leader_commit.rs b/node/actors/bft/src/replica/leader_commit.rs similarity index 98% rename from node/actors/consensus/src/replica/leader_commit.rs rename to node/actors/bft/src/replica/leader_commit.rs index f5bcd1da..ba0fd3e6 100644 --- a/node/actors/consensus/src/replica/leader_commit.rs +++ b/node/actors/bft/src/replica/leader_commit.rs @@ -1,9 +1,9 @@ use super::StateMachine; use crate::inner::ConsensusInner; use anyhow::Context as _; -use concurrency::ctx; -use roles::validator; use tracing::instrument; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator; /// Errors that can occur when processing a "leader commit" message. #[derive(Debug, thiserror::Error)] diff --git a/node/actors/consensus/src/replica/leader_prepare.rs b/node/actors/bft/src/replica/leader_prepare.rs similarity index 98% rename from node/actors/consensus/src/replica/leader_prepare.rs rename to node/actors/bft/src/replica/leader_prepare.rs index 74501136..47b21744 100644 --- a/node/actors/consensus/src/replica/leader_prepare.rs +++ b/node/actors/bft/src/replica/leader_prepare.rs @@ -1,11 +1,11 @@ use super::StateMachine; use crate::inner::ConsensusInner; use anyhow::Context as _; -use concurrency::ctx; -use network::io::{ConsensusInputMessage, Target}; -use roles::validator; use std::collections::HashMap; use tracing::instrument; +use zksync_concurrency::ctx; +use zksync_consensus_network::io::{ConsensusInputMessage, Target}; +use zksync_consensus_roles::validator; /// Errors that can occur when processing a "leader prepare" message. #[derive(Debug, thiserror::Error)] diff --git a/node/actors/consensus/src/replica/mod.rs b/node/actors/bft/src/replica/mod.rs similarity index 100% rename from node/actors/consensus/src/replica/mod.rs rename to node/actors/bft/src/replica/mod.rs diff --git a/node/actors/consensus/src/replica/new_view.rs b/node/actors/bft/src/replica/new_view.rs similarity index 92% rename from node/actors/consensus/src/replica/new_view.rs rename to node/actors/bft/src/replica/new_view.rs index 078fe488..f9571f2c 100644 --- a/node/actors/consensus/src/replica/new_view.rs +++ b/node/actors/bft/src/replica/new_view.rs @@ -1,10 +1,10 @@ use super::StateMachine; use crate::ConsensusInner; use anyhow::Context as _; -use concurrency::ctx; -use network::io::{ConsensusInputMessage, Target}; -use roles::validator; use tracing::instrument; +use zksync_concurrency::ctx; +use zksync_consensus_network::io::{ConsensusInputMessage, Target}; +use zksync_consensus_roles::validator; impl StateMachine { /// This blocking method is used whenever we start a new view. diff --git a/node/actors/consensus/src/replica/state_machine.rs b/node/actors/bft/src/replica/state_machine.rs similarity index 96% rename from node/actors/consensus/src/replica/state_machine.rs rename to node/actors/bft/src/replica/state_machine.rs index ecc846ce..a3a3e983 100644 --- a/node/actors/consensus/src/replica/state_machine.rs +++ b/node/actors/bft/src/replica/state_machine.rs @@ -1,10 +1,11 @@ use crate::{metrics, ConsensusInner}; use anyhow::Context as _; -use concurrency::{ctx, metrics::LatencyHistogramExt as _, scope, time}; -use roles::validator; use std::collections::{BTreeMap, HashMap}; -use storage::{FallbackReplicaStateStore, StorageError}; use tracing::instrument; +use zksync_concurrency::{ctx, metrics::LatencyHistogramExt as _, scope, time}; +use zksync_consensus_roles::validator; +use zksync_consensus_storage as storage; +use zksync_consensus_storage::{FallbackReplicaStateStore, StorageError}; /// The StateMachine struct contains the state of the replica. This is the most complex state machine and is responsible /// for validating and voting on blocks. When participating in consensus we are always a replica. diff --git a/node/actors/consensus/src/replica/tests.rs b/node/actors/bft/src/replica/tests.rs similarity index 89% rename from node/actors/consensus/src/replica/tests.rs rename to node/actors/bft/src/replica/tests.rs index 09fd17b7..8fb3aedc 100644 --- a/node/actors/consensus/src/replica/tests.rs +++ b/node/actors/bft/src/replica/tests.rs @@ -1,12 +1,12 @@ use crate::testonly; -use concurrency::{ctx, scope, time}; -use network::io::{ConsensusInputMessage, Target}; use rand::Rng; -use roles::validator::{self, ViewNumber}; +use zksync_concurrency::{ctx, scope, testonly::abort_on_panic, time}; +use zksync_consensus_network::io::{ConsensusInputMessage, Target}; +use zksync_consensus_roles::validator::{self, ViewNumber}; #[tokio::test] async fn start_new_view_not_leader() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::ManualClock::new()); let rng = &mut ctx.rng(); diff --git a/node/actors/consensus/src/replica/timer.rs b/node/actors/bft/src/replica/timer.rs similarity index 91% rename from node/actors/consensus/src/replica/timer.rs rename to node/actors/bft/src/replica/timer.rs index 4df7b7da..c5231fa8 100644 --- a/node/actors/consensus/src/replica/timer.rs +++ b/node/actors/bft/src/replica/timer.rs @@ -1,7 +1,7 @@ use super::StateMachine; use crate::metrics; -use concurrency::{ctx, metrics::LatencyGaugeExt as _, time}; use tracing::instrument; +use zksync_concurrency::{ctx, metrics::LatencyGaugeExt as _, time}; impl StateMachine { /// The base duration of the timeout. diff --git a/node/actors/consensus/src/testonly/fuzz.rs b/node/actors/bft/src/testonly/fuzz.rs similarity index 99% rename from node/actors/consensus/src/testonly/fuzz.rs rename to node/actors/bft/src/testonly/fuzz.rs index e4b95c78..ce6c155c 100644 --- a/node/actors/consensus/src/testonly/fuzz.rs +++ b/node/actors/bft/src/testonly/fuzz.rs @@ -1,5 +1,5 @@ use rand::{seq::SliceRandom, Rng}; -use roles::validator; +use zksync_consensus_roles::validator; /// Trait that allows us to mutate types. It's an approach to fuzzing that instead of starting with completely random inputs /// (which will basically always fail on the first check), starts from a real valid message and modifies a single value to diff --git a/node/actors/consensus/src/testonly/make.rs b/node/actors/bft/src/testonly/make.rs similarity index 90% rename from node/actors/consensus/src/testonly/make.rs rename to node/actors/bft/src/testonly/make.rs index f13fb425..ca99edec 100644 --- a/node/actors/consensus/src/testonly/make.rs +++ b/node/actors/bft/src/testonly/make.rs @@ -4,11 +4,11 @@ use crate::{ io::{InputMessage, OutputMessage}, Consensus, }; -use concurrency::ctx; -use roles::validator; use std::sync::Arc; -use storage::{FallbackReplicaStateStore, InMemoryStorage}; -use utils::pipe::{self, DispatcherPipe}; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator; +use zksync_consensus_storage::{FallbackReplicaStateStore, InMemoryStorage}; +use zksync_consensus_utils::pipe::{self, DispatcherPipe}; /// This creates a mock Consensus struct for unit tests. pub async fn make_consensus( diff --git a/node/actors/consensus/src/testonly/mod.rs b/node/actors/bft/src/testonly/mod.rs similarity index 89% rename from node/actors/consensus/src/testonly/mod.rs rename to node/actors/bft/src/testonly/mod.rs index 6b47b7cb..ed47074d 100644 --- a/node/actors/consensus/src/testonly/mod.rs +++ b/node/actors/bft/src/testonly/mod.rs @@ -1,9 +1,9 @@ //! This module contains utilities that are only meant for testing purposes. use crate::io::InputMessage; -use concurrency::oneshot; -use network::io::ConsensusReq; use rand::{distributions::Standard, prelude::Distribution, Rng}; +use zksync_concurrency::oneshot; +use zksync_consensus_network::io::ConsensusReq; #[cfg(test)] mod fuzz; diff --git a/node/actors/consensus/src/testonly/node.rs b/node/actors/bft/src/testonly/node.rs similarity index 94% rename from node/actors/consensus/src/testonly/node.rs rename to node/actors/bft/src/testonly/node.rs index 6d93a7f8..ae8b6f68 100644 --- a/node/actors/consensus/src/testonly/node.rs +++ b/node/actors/bft/src/testonly/node.rs @@ -1,10 +1,11 @@ use super::Fuzz; use crate::io; -use concurrency::{ctx, ctx::channel, scope}; -use network::io::ConsensusInputMessage; use rand::Rng; -use roles::validator; -use utils::pipe::DispatcherPipe; +use zksync_concurrency::{ctx, ctx::channel, scope}; +use zksync_consensus_network as network; +use zksync_consensus_network::io::ConsensusInputMessage; +use zksync_consensus_roles::validator; +use zksync_consensus_utils::pipe::DispatcherPipe; /// A struct containing metrics information. Right now it's just a finalized block. #[derive(Debug)] diff --git a/node/actors/consensus/src/testonly/run.rs b/node/actors/bft/src/testonly/run.rs similarity index 95% rename from node/actors/consensus/src/testonly/run.rs rename to node/actors/bft/src/testonly/run.rs index a5d09c7a..d1eb3eae 100644 --- a/node/actors/consensus/src/testonly/run.rs +++ b/node/actors/bft/src/testonly/run.rs @@ -1,15 +1,16 @@ use super::{Behavior, Metrics, Node}; use crate::{testonly, Consensus}; use anyhow::Context; -use concurrency::{ctx, ctx::channel, oneshot, scope, signal}; -use roles::validator; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; -use storage::{FallbackReplicaStateStore, InMemoryStorage}; use tracing::Instrument as _; -use utils::pipe; +use zksync_concurrency::{ctx, ctx::channel, oneshot, scope, signal}; +use zksync_consensus_network as network; +use zksync_consensus_roles::validator; +use zksync_consensus_storage::{FallbackReplicaStateStore, InMemoryStorage}; +use zksync_consensus_utils::pipe; #[derive(Clone, Copy)] pub(crate) enum Network { @@ -153,8 +154,8 @@ async fn run_nodes( } for (_, recv) in network_recv { s.spawn(async { + use zksync_consensus_network::io; let mut recv = recv; - use network::io; while let Ok(io::InputMessage::Consensus(message)) = recv.recv(ctx).await { let msg = || { diff --git a/node/actors/consensus/src/tests.rs b/node/actors/bft/src/tests.rs similarity index 95% rename from node/actors/consensus/src/tests.rs rename to node/actors/bft/src/tests.rs index 41723316..a7f65479 100644 --- a/node/actors/consensus/src/tests.rs +++ b/node/actors/bft/src/tests.rs @@ -2,10 +2,10 @@ use crate::{ misc::consensus_threshold, testonly::{Behavior, Network, Test}, }; -use concurrency::ctx; +use zksync_concurrency::{ctx, testonly::abort_on_panic}; async fn run_test(behavior: Behavior, network: Network) { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(1.)); const NODES: usize = 11; diff --git a/node/actors/executor/Cargo.toml b/node/actors/executor/Cargo.toml index 701a0a03..9bbe7188 100644 --- a/node/actors/executor/Cargo.toml +++ b/node/actors/executor/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "executor" +name = "zksync_consensus_executor" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,21 +7,20 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_bft.workspace = true +zksync_consensus_crypto.workspace = true +zksync_consensus_network.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_schema.workspace = true +zksync_consensus_storage.workspace = true +zksync_consensus_sync_blocks.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true rand.workspace = true tracing.workspace = true vise.workspace = true -concurrency = { path = "../../libs/concurrency" } -crypto = { path = "../../libs/crypto" } -roles = { path = "../../libs/roles" } -schema = { path = "../../libs/schema" } -storage = { path = "../../libs/storage" } -utils = { path = "../../libs/utils" } - -consensus = { path = "../consensus" } -network = { path = "../network" } -sync_blocks = { path = "../sync_blocks" } - [dev-dependencies] tokio.workspace = true diff --git a/node/actors/executor/src/config/mod.rs b/node/actors/executor/src/config/mod.rs index 178728ac..4ab296fa 100644 --- a/node/actors/executor/src/config/mod.rs +++ b/node/actors/executor/src/config/mod.rs @@ -1,14 +1,16 @@ //! Module to create the configuration for the consensus node. use anyhow::Context as _; -use crypto::{read_required_text, Text, TextFmt}; -use network::{consensus, gossip}; -use roles::{node, validator}; -use schema::{proto::executor::config as proto, read_required, required, ProtoFmt}; use std::{ collections::{HashMap, HashSet}, net, }; +use zksync_consensus_crypto::{read_required_text, Text, TextFmt}; +use zksync_consensus_network::{consensus, gossip}; +use zksync_consensus_roles::{node, validator}; +use zksync_consensus_schema::{ + proto::executor::config as proto, read_required, required, ProtoFmt, +}; #[cfg(test)] mod tests; diff --git a/node/actors/executor/src/config/tests.rs b/node/actors/executor/src/config/tests.rs index d296ea8a..7b1ab797 100644 --- a/node/actors/executor/src/config/tests.rs +++ b/node/actors/executor/src/config/tests.rs @@ -1,11 +1,11 @@ use super::{ConsensusConfig, ExecutorConfig, GossipConfig}; -use concurrency::ctx; use rand::{ distributions::{Distribution, Standard}, Rng, }; -use roles::{node, validator}; -use schema::testonly::test_encode_random; +use zksync_concurrency::ctx; +use zksync_consensus_roles::{node, validator}; +use zksync_consensus_schema::testonly::test_encode_random; fn make_addr(rng: &mut R) -> std::net::SocketAddr { std::net::SocketAddr::new(std::net::IpAddr::from(rng.gen::<[u8; 16]>()), rng.gen()) diff --git a/node/actors/executor/src/io.rs b/node/actors/executor/src/io.rs index b659fec9..76b1df00 100644 --- a/node/actors/executor/src/io.rs +++ b/node/actors/executor/src/io.rs @@ -1,20 +1,22 @@ //! Module to manage the communication between actors. It simply converts and forwards messages from and to each different actor. use crate::metrics; -use concurrency::{ +use tracing::instrument; +use zksync_concurrency::{ ctx::{self, channel}, scope, }; -use consensus::io::{ +use zksync_consensus_bft::io::{ InputMessage as ConsensusInputMessage, OutputMessage as ConsensusOutputMessage, }; -use network::io::{InputMessage as NetworkInputMessage, OutputMessage as NetworkOutputMessage}; -use roles::validator::FinalBlock; -use sync_blocks::io::{ +use zksync_consensus_network::io::{ + InputMessage as NetworkInputMessage, OutputMessage as NetworkOutputMessage, +}; +use zksync_consensus_roles::validator::FinalBlock; +use zksync_consensus_sync_blocks::io::{ InputMessage as SyncBlocksInputMessage, OutputMessage as SyncBlocksOutputMessage, }; -use tracing::instrument; -use utils::pipe::DispatcherPipe; +use zksync_consensus_utils::pipe::DispatcherPipe; /// The IO dispatcher, it is the main struct to handle actor messages. It simply contains a sender and a receiver for /// a pair of channels for each actor. This of course allows us to send and receive messages to and from each actor. diff --git a/node/actors/executor/src/lib.rs b/node/actors/executor/src/lib.rs index a8c7f5ee..9de73fdd 100644 --- a/node/actors/executor/src/lib.rs +++ b/node/actors/executor/src/lib.rs @@ -2,13 +2,14 @@ use crate::io::Dispatcher; use anyhow::Context as _; -use concurrency::{ctx, ctx::channel, net, scope}; -use consensus::Consensus; -use roles::{node, validator, validator::FinalBlock}; use std::{mem, sync::Arc}; -use storage::{FallbackReplicaStateStore, ReplicaStateStore, WriteBlockStore}; -use sync_blocks::SyncBlocks; -use utils::pipe; +use zksync_concurrency::{ctx, ctx::channel, net, scope}; +use zksync_consensus_bft::{misc::consensus_threshold, Consensus}; +use zksync_consensus_network as network; +use zksync_consensus_roles::{node, validator, validator::FinalBlock}; +use zksync_consensus_storage::{FallbackReplicaStateStore, ReplicaStateStore, WriteBlockStore}; +use zksync_consensus_sync_blocks::SyncBlocks; +use zksync_consensus_utils::pipe; mod config; mod io; @@ -180,9 +181,9 @@ impl Executor { None }; - let sync_blocks_config = sync_blocks::Config::new( + let sync_blocks_config = zksync_consensus_sync_blocks::Config::new( validator_set.clone(), - consensus::misc::consensus_threshold(validator_set.len()), + consensus_threshold(validator_set.len()), )?; let sync_blocks = SyncBlocks::new( ctx, diff --git a/node/actors/executor/src/testonly.rs b/node/actors/executor/src/testonly.rs index c3ae74f2..36fcdcf9 100644 --- a/node/actors/executor/src/testonly.rs +++ b/node/actors/executor/src/testonly.rs @@ -1,15 +1,14 @@ //! Testing extensions for node executor. - use crate::config::{ConsensusConfig, ExecutorConfig, GossipConfig}; -use concurrency::net; -use consensus::testonly::make_genesis; -use network::testonly::Instance; use rand::Rng; -use roles::{ +use std::collections::HashMap; +use zksync_concurrency::net; +use zksync_consensus_bft::testonly::make_genesis; +use zksync_consensus_network::testonly::Instance; +use zksync_consensus_roles::{ node, validator::{self, Payload}, }; -use std::collections::HashMap; /// Full validator configuration. #[derive(Debug)] diff --git a/node/actors/executor/src/tests.rs b/node/actors/executor/src/tests.rs index 606818a8..5e540f50 100644 --- a/node/actors/executor/src/tests.rs +++ b/node/actors/executor/src/tests.rs @@ -1,10 +1,9 @@ //! High-level tests for `Executor`. - use super::*; use crate::testonly::FullValidatorConfig; -use concurrency::sync; -use roles::validator::{BlockNumber, Payload}; -use storage::{BlockStore, InMemoryStorage, StorageError}; +use zksync_concurrency::{sync, testonly::abort_on_panic}; +use zksync_consensus_roles::validator::{BlockNumber, Payload}; +use zksync_consensus_storage::{BlockStore, InMemoryStorage, StorageError}; async fn store_final_blocks( ctx: &ctx::Ctx, @@ -48,7 +47,7 @@ impl FullValidatorConfig { #[tokio::test] async fn executing_single_validator() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::root(); let rng = &mut ctx.rng(); @@ -76,7 +75,7 @@ async fn executing_single_validator() { #[tokio::test] async fn executing_validator_and_external_node() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(20.0)); let rng = &mut ctx.rng(); diff --git a/node/actors/network/Cargo.toml b/node/actors/network/Cargo.toml index cfa3643b..30fd0e9a 100644 --- a/node/actors/network/Cargo.toml +++ b/node/actors/network/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "network" +name = "zksync_consensus_network" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,6 +7,12 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_crypto.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_schema.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true async-trait.workspace = true im.workspace = true @@ -18,12 +24,6 @@ thiserror.workspace = true tracing.workspace = true vise.workspace = true -concurrency = { path = "../../libs/concurrency" } -crypto = { path = "../../libs/crypto" } -roles = { path = "../../libs/roles" } -schema = { path = "../../libs/schema" } -utils = { path = "../../libs/utils" } - [dev-dependencies] pretty_assertions.workspace = true test-casing.workspace = true diff --git a/node/actors/network/src/consensus/handshake/mod.rs b/node/actors/network/src/consensus/handshake/mod.rs index 5d6d309f..fa304488 100644 --- a/node/actors/network/src/consensus/handshake/mod.rs +++ b/node/actors/network/src/consensus/handshake/mod.rs @@ -1,9 +1,9 @@ use crate::{frame, noise}; use anyhow::Context as _; -use concurrency::{ctx, time}; -use crypto::ByteFmt; -use roles::{node, validator}; -use schema::{proto::network::consensus as proto, read_required, ProtoFmt}; +use zksync_concurrency::{ctx, time}; +use zksync_consensus_crypto::ByteFmt; +use zksync_consensus_roles::{node, validator}; +use zksync_consensus_schema::{proto::network::consensus as proto, read_required, ProtoFmt}; #[cfg(test)] mod testonly; diff --git a/node/actors/network/src/consensus/handshake/testonly.rs b/node/actors/network/src/consensus/handshake/testonly.rs index 2b346bc6..d05848df 100644 --- a/node/actors/network/src/consensus/handshake/testonly.rs +++ b/node/actors/network/src/consensus/handshake/testonly.rs @@ -7,7 +7,7 @@ use rand::{ distributions::{Distribution, Standard}, Rng, }; -use roles::{node, validator}; +use zksync_consensus_roles::{node, validator}; impl Distribution for Standard { fn sample(&self, rng: &mut R) -> Handshake { diff --git a/node/actors/network/src/consensus/handshake/tests.rs b/node/actors/network/src/consensus/handshake/tests.rs index f4960826..ed49c14d 100644 --- a/node/actors/network/src/consensus/handshake/tests.rs +++ b/node/actors/network/src/consensus/handshake/tests.rs @@ -1,18 +1,19 @@ use super::*; use crate::{frame, noise, testonly}; -use concurrency::{ctx, io, scope}; use rand::Rng; -use roles::validator; +use zksync_concurrency::{ctx, io, scope, testonly::abort_on_panic}; +use zksync_consensus_roles::validator; +use zksync_consensus_schema::testonly::test_encode_random; #[test] fn test_schema_encode_decode() { let rng = &mut ctx::test_root(&ctx::RealClock).rng(); - schema::testonly::test_encode_random::<_, Handshake>(rng); + test_encode_random::<_, Handshake>(rng); } #[tokio::test] async fn test_session_id_mismatch() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -79,7 +80,7 @@ async fn test_session_id_mismatch() { #[tokio::test] async fn test_peer_mismatch() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -109,7 +110,7 @@ async fn test_peer_mismatch() { #[tokio::test] async fn test_invalid_signature() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); diff --git a/node/actors/network/src/consensus/runner.rs b/node/actors/network/src/consensus/runner.rs index d6098fe9..9d1c9995 100644 --- a/node/actors/network/src/consensus/runner.rs +++ b/node/actors/network/src/consensus/runner.rs @@ -3,9 +3,9 @@ use super::handshake; use crate::{io, noise, preface, rpc, State}; use anyhow::Context as _; -use concurrency::{ctx, ctx::channel, oneshot, scope, sync, time}; -use roles::validator; use std::{collections::HashMap, sync::Arc}; +use zksync_concurrency::{ctx, ctx::channel, oneshot, scope, sync, time}; +use zksync_consensus_roles::validator; /// How often we should retry to establish a connection to a validator. /// TODO(gprusak): once it becomes relevant, choose a more appropriate retry strategy. diff --git a/node/actors/network/src/consensus/state.rs b/node/actors/network/src/consensus/state.rs index 07c2c65b..e8521283 100644 --- a/node/actors/network/src/consensus/state.rs +++ b/node/actors/network/src/consensus/state.rs @@ -1,6 +1,6 @@ use crate::pool::PoolWatch; -use roles::{validator, validator::ValidatorSet}; use std::collections::HashSet; +use zksync_consensus_roles::{validator, validator::ValidatorSet}; /// Configuration of the consensus network. #[derive(Debug, Clone)] diff --git a/node/actors/network/src/consensus/tests.rs b/node/actors/network/src/consensus/tests.rs index 089e47ec..a0b6be73 100644 --- a/node/actors/network/src/consensus/tests.rs +++ b/node/actors/network/src/consensus/tests.rs @@ -1,15 +1,15 @@ use super::*; use crate::{io, preface, rpc, run_network, testonly}; use anyhow::Context as _; -use concurrency::{ctx, net, scope}; use rand::Rng; -use roles::validator; use tracing::Instrument as _; -use utils::pipe; +use zksync_concurrency::{ctx, net, scope, testonly::abort_on_panic}; +use zksync_consensus_roles::validator; +use zksync_consensus_utils::pipe; #[tokio::test] async fn test_one_connection_per_validator() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -66,7 +66,7 @@ async fn test_one_connection_per_validator() { #[tokio::test(flavor = "multi_thread")] async fn test_address_change() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(20.)); let rng = &mut ctx.rng(); @@ -144,7 +144,7 @@ async fn test_address_change() { /// encrypted authenticated multiplexed stream. #[tokio::test] async fn test_transmission() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); diff --git a/node/actors/network/src/event.rs b/node/actors/network/src/event.rs index 48a317a6..68d9ab6a 100644 --- a/node/actors/network/src/event.rs +++ b/node/actors/network/src/event.rs @@ -1,7 +1,7 @@ //! Mechanism for network State to report internal events. //! It is used in tests to await a specific state. use crate::State; -use roles::{node, validator}; +use zksync_consensus_roles::{node, validator}; impl State { /// Sends an event to the `self.events` channel. diff --git a/node/actors/network/src/frame.rs b/node/actors/network/src/frame.rs index d88fa8ef..f865be95 100644 --- a/node/actors/network/src/frame.rs +++ b/node/actors/network/src/frame.rs @@ -1,7 +1,8 @@ //! Simple frame encoding format (length ++ value) for protobuf messages, //! since protobuf messages do not have delimiters. use crate::{mux, noise::bytes}; -use concurrency::{ctx, io}; +use zksync_concurrency::{ctx, io}; +use zksync_consensus_schema as schema; /// Reads a raw frame of bytes from the stream and interprets it as proto. /// A `frame : [u8]` is encoded as `L ++ frame`, where `L` is diff --git a/node/actors/network/src/gossip/handshake/mod.rs b/node/actors/network/src/gossip/handshake/mod.rs index f8d8ba83..9114ac0d 100644 --- a/node/actors/network/src/gossip/handshake/mod.rs +++ b/node/actors/network/src/gossip/handshake/mod.rs @@ -1,10 +1,10 @@ use super::Config; use crate::{frame, noise}; use anyhow::Context as _; -use concurrency::{ctx, time}; -use crypto::ByteFmt; -use roles::node; -use schema::{proto::network::gossip as proto, read_required, required, ProtoFmt}; +use zksync_concurrency::{ctx, time}; +use zksync_consensus_crypto::ByteFmt; +use zksync_consensus_roles::node; +use zksync_consensus_schema::{proto::network::gossip as proto, read_required, required, ProtoFmt}; #[cfg(test)] mod testonly; diff --git a/node/actors/network/src/gossip/handshake/testonly.rs b/node/actors/network/src/gossip/handshake/testonly.rs index c11d4d39..d45531d2 100644 --- a/node/actors/network/src/gossip/handshake/testonly.rs +++ b/node/actors/network/src/gossip/handshake/testonly.rs @@ -7,7 +7,7 @@ use rand::{ distributions::{Distribution, Standard}, Rng, }; -use roles::node; +use zksync_consensus_roles::node; impl Distribution for Standard { fn sample(&self, rng: &mut R) -> Handshake { diff --git a/node/actors/network/src/gossip/handshake/tests.rs b/node/actors/network/src/gossip/handshake/tests.rs index 3807e3e4..39c26457 100644 --- a/node/actors/network/src/gossip/handshake/tests.rs +++ b/node/actors/network/src/gossip/handshake/tests.rs @@ -1,14 +1,15 @@ use super::*; use crate::{frame, noise, testonly}; -use concurrency::{ctx, io, scope}; use rand::Rng; -use roles::node; use std::collections::{HashMap, HashSet}; +use zksync_concurrency::{ctx, io, scope, testonly::abort_on_panic}; +use zksync_consensus_roles::node; +use zksync_consensus_schema::testonly::test_encode_random; #[test] fn test_schema_encode_decode() { let rng = &mut ctx::test_root(&ctx::RealClock).rng(); - schema::testonly::test_encode_random::<_, Handshake>(rng); + test_encode_random::<_, Handshake>(rng); } fn make_cfg(rng: &mut R) -> Config { @@ -23,7 +24,7 @@ fn make_cfg(rng: &mut R) -> Config { #[tokio::test] async fn test_session_id_mismatch() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -91,7 +92,7 @@ async fn test_session_id_mismatch() { #[tokio::test] async fn test_peer_mismatch() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -121,7 +122,7 @@ async fn test_peer_mismatch() { #[tokio::test] async fn test_invalid_signature() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); diff --git a/node/actors/network/src/gossip/runner.rs b/node/actors/network/src/gossip/runner.rs index 4e240355..f614e663 100644 --- a/node/actors/network/src/gossip/runner.rs +++ b/node/actors/network/src/gossip/runner.rs @@ -6,15 +6,15 @@ use crate::{ }; use anyhow::Context; use async_trait::async_trait; -use concurrency::{ +use std::sync::Arc; +use tracing::Instrument as _; +use zksync_concurrency::{ ctx::{self, channel}, oneshot, scope, sync::{self, watch}, time, }; -use roles::{node, validator}; -use std::sync::Arc; -use tracing::Instrument as _; +use zksync_consensus_roles::{node, validator}; /// How often we should retry to establish a connection to a validator. /// TODO(gprusak): once it becomes relevant, choose a more appropriate retry strategy. diff --git a/node/actors/network/src/gossip/state.rs b/node/actors/network/src/gossip/state.rs index 49bd4bb5..c40f3cd6 100644 --- a/node/actors/network/src/gossip/state.rs +++ b/node/actors/network/src/gossip/state.rs @@ -1,10 +1,10 @@ use crate::{io::SyncState, pool::PoolWatch, rpc, watch::Watch}; -use concurrency::sync::{self, watch, Mutex}; -use roles::{node, validator}; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; +use zksync_concurrency::sync::{self, watch, Mutex}; +use zksync_consensus_roles::{node, validator}; /// Mapping from validator::PublicKey to a signed validator::NetAddress. /// Represents the currents state of node's knowledge about the validator endpoints. diff --git a/node/actors/network/src/gossip/tests.rs b/node/actors/network/src/gossip/tests.rs index b3c44754..8091b352 100644 --- a/node/actors/network/src/gossip/tests.rs +++ b/node/actors/network/src/gossip/tests.rs @@ -1,26 +1,28 @@ use super::*; use crate::{event::Event, io, preface, rpc, rpc::Rpc as _, run_network, testonly}; use anyhow::Context as _; -use concurrency::{ - ctx::{self, channel}, - oneshot, scope, - sync::{watch, Mutex}, - time, -}; use pretty_assertions::assert_eq; use rand::Rng; -use roles::validator::{self, BlockNumber, FinalBlock}; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; use test_casing::{test_casing, Product}; use tracing::Instrument as _; -use utils::pipe; +use zksync_concurrency::{ + ctx::{self, channel}, + oneshot, scope, + sync::{watch, Mutex}, + testonly::abort_on_panic, + time, +}; +use zksync_consensus_roles as roles; +use zksync_consensus_roles::validator::{self, BlockNumber, FinalBlock}; +use zksync_consensus_utils::pipe; #[tokio::test] async fn test_one_connection_per_node() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -148,7 +150,7 @@ impl View { #[tokio::test] async fn test_validator_addrs() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let rng = &mut ctx::test_root(&ctx::RealClock).rng(); let keys: Vec = (0..8).map(|_| rng.gen()).collect(); @@ -231,7 +233,7 @@ fn to_addr_map(addrs: &ValidatorAddrs) -> HashMap = testonly::Instance::new(rng, 10, 1); @@ -275,7 +277,7 @@ const NETWORK_CONNECTIVITY_CASES: [(usize, usize); 5] = [(2, 1), (3, 2), (5, 3), #[tokio::test(flavor = "multi_thread")] #[tracing::instrument(level = "trace")] async fn syncing_blocks(node_count: usize, gossip_peers: usize) { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(20.0)); let ctx = &ctx.with_timeout(time::Duration::seconds(200)); @@ -396,7 +398,7 @@ async fn uncoordinated_block_syncing( (node_count, gossip_peers): (usize, usize), state_generation_interval: time::Duration, ) { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(20.0)); let ctx = &ctx.with_timeout(time::Duration::seconds(200)); @@ -480,7 +482,7 @@ async fn run_mock_uncoordinated_dispatcher( #[test_casing(5, NETWORK_CONNECTIVITY_CASES)] #[tokio::test] async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::ManualClock::new()); let rng = &mut ctx.rng(); @@ -593,7 +595,7 @@ async fn run_get_block_dispatcher( /// the AccountData that is present in the network from the previous run. #[tokio::test] async fn validator_node_restart() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let clock = &ctx::ManualClock::new(); let ctx = &ctx::test_root(clock); let rng = &mut ctx.rng(); @@ -677,7 +679,7 @@ async fn validator_node_restart() { /// to receive all updates in 2 rounds of communication. #[tokio::test] async fn rate_limiting() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let clock = &ctx::ManualClock::new(); let ctx = &ctx::test_root(clock); let rng = &mut ctx.rng(); diff --git a/node/actors/network/src/io.rs b/node/actors/network/src/io.rs index ab0a4f36..1f7a3c7e 100644 --- a/node/actors/network/src/io.rs +++ b/node/actors/network/src/io.rs @@ -1,6 +1,6 @@ #![allow(missing_docs)] -use concurrency::oneshot; -use roles::{node, validator}; +use zksync_concurrency::oneshot; +use zksync_consensus_roles::{node, validator}; /// All the messages that other actors can send to the Network actor. #[derive(Debug)] diff --git a/node/actors/network/src/metrics.rs b/node/actors/network/src/metrics.rs index 77cda040..8503b7da 100644 --- a/node/actors/network/src/metrics.rs +++ b/node/actors/network/src/metrics.rs @@ -1,7 +1,6 @@ //! General-purpose network metrics. use crate::state::State; -use concurrency::{ctx, io, net}; use std::{ net::SocketAddr, pin::Pin, @@ -11,6 +10,7 @@ use std::{ use vise::{ Collector, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, GaugeGuard, Metrics, Unit, }; +use zksync_concurrency::{ctx, io, net}; /// Metered TCP stream. #[pin_project::pin_project] diff --git a/node/actors/network/src/mux/config.rs b/node/actors/network/src/mux/config.rs index 88066f2d..62ef1e20 100644 --- a/node/actors/network/src/mux/config.rs +++ b/node/actors/network/src/mux/config.rs @@ -1,5 +1,5 @@ use super::StreamId; -use concurrency::sync; +use zksync_concurrency::sync; /// Maximal frame size. pub(crate) const MAX_FRAME_SIZE: u64 = u16::MAX as u64; diff --git a/node/actors/network/src/mux/handshake.rs b/node/actors/network/src/mux/handshake.rs index 08450864..83ac6a52 100644 --- a/node/actors/network/src/mux/handshake.rs +++ b/node/actors/network/src/mux/handshake.rs @@ -1,7 +1,8 @@ use super::CapabilityId; use anyhow::Context as _; -use schema::{proto::network::mux as proto, required}; use std::collections::HashMap; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::mux as proto, required}; pub(super) struct Handshake { /// Maximal supported number of the accept streams per capability. diff --git a/node/actors/network/src/mux/mod.rs b/node/actors/network/src/mux/mod.rs index 472d61ba..fc3f021c 100644 --- a/node/actors/network/src/mux/mod.rs +++ b/node/actors/network/src/mux/mod.rs @@ -79,8 +79,8 @@ //! both sides of the connection can enforce. use crate::{frame, noise::bytes}; use anyhow::Context as _; -use concurrency::{ctx, ctx::channel, io, scope, sync}; use std::{collections::BTreeMap, sync::Arc}; +use zksync_concurrency::{ctx, ctx::channel, io, scope, sync}; mod config; mod handshake; diff --git a/node/actors/network/src/mux/reusable_stream.rs b/node/actors/network/src/mux/reusable_stream.rs index c196827e..a0fe6a14 100644 --- a/node/actors/network/src/mux/reusable_stream.rs +++ b/node/actors/network/src/mux/reusable_stream.rs @@ -3,8 +3,8 @@ use super::{ Config, FrameKind, Header, ReadStream, RunError, Stream, StreamId, StreamKind, WriteStream, }; use crate::noise::bytes; -use concurrency::{ctx, ctx::channel, oneshot, scope, sync}; use std::sync::Arc; +use zksync_concurrency::{ctx, ctx::channel, oneshot, scope, sync}; /// Read frame allocation permit. #[derive(Debug)] diff --git a/node/actors/network/src/mux/tests.rs b/node/actors/network/src/mux/tests.rs index 83986a9c..19a82458 100644 --- a/node/actors/network/src/mux/tests.rs +++ b/node/actors/network/src/mux/tests.rs @@ -1,8 +1,6 @@ use crate::{frame, mux, noise, noise::bytes}; use anyhow::Context as _; -use concurrency::{ctx, scope}; use rand::Rng as _; -use schema::proto::network::mux_test as proto; use std::{ collections::BTreeMap, sync::{ @@ -10,7 +8,10 @@ use std::{ Arc, }, }; -use utils::no_copy::NoCopy; +use zksync_concurrency::{ctx, scope, testonly::abort_on_panic}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::proto::network::mux_test as proto; +use zksync_consensus_utils::no_copy::NoCopy; fn assert_partition(sets: &[u16]) { let mut sum = 0; @@ -193,8 +194,8 @@ fn expected(res: Result<(), mux::RunError>) -> Result<(), mux::RunError> { // checking 1 property at a time should be added. #[test] fn mux_with_noise() { - concurrency::testonly::abort_on_panic(); - concurrency::testonly::with_runtimes(|| async { + abort_on_panic(); + zksync_concurrency::testonly::with_runtimes(|| async { let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -283,7 +284,7 @@ fn mux_with_noise() { #[tokio::test] async fn test_transport_closed() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let cap: mux::CapabilityId = 0; let cfg = Arc::new(mux::Config { diff --git a/node/actors/network/src/mux/transient_stream.rs b/node/actors/network/src/mux/transient_stream.rs index 4fe33539..e4736f69 100644 --- a/node/actors/network/src/mux/transient_stream.rs +++ b/node/actors/network/src/mux/transient_stream.rs @@ -9,7 +9,7 @@ //! or convenience of use. use super::{FrameKind, ReadReusableStream, WriteReusableStream}; use crate::noise::bytes; -use concurrency::{ctx, sync}; +use zksync_concurrency::{ctx, sync}; /// Read half of the transient stream. #[derive(Debug)] diff --git a/node/actors/network/src/noise/stream.rs b/node/actors/network/src/noise/stream.rs index d3b97544..205edfaa 100644 --- a/node/actors/network/src/noise/stream.rs +++ b/node/actors/network/src/noise/stream.rs @@ -1,15 +1,15 @@ //! `tokio::io` stream using Noise encryption. use super::bytes; use crate::metrics::MeteredStream; -use concurrency::{ - ctx, io, - io::{AsyncRead as _, AsyncWrite as _}, -}; -use crypto::{sha256::Sha256, ByteFmt}; use std::{ pin::Pin, task::{ready, Context, Poll}, }; +use zksync_concurrency::{ + ctx, io, + io::{AsyncRead as _, AsyncWrite as _}, +}; +use zksync_consensus_crypto::{sha256::Sha256, ByteFmt}; /// Fixed noise configuration. Nodes need to use the same noise /// configuration to be able to connect to each other. diff --git a/node/actors/network/src/noise/testonly.rs b/node/actors/network/src/noise/testonly.rs index 9304c6d2..ea4856e9 100644 --- a/node/actors/network/src/noise/testonly.rs +++ b/node/actors/network/src/noise/testonly.rs @@ -1,5 +1,5 @@ use crate::{metrics, noise}; -use concurrency::{ctx, scope}; +use zksync_concurrency::{ctx, scope}; pub(crate) async fn pipe(ctx: &ctx::Ctx) -> (noise::Stream, noise::Stream) { scope::run!(ctx, |ctx, s| async { diff --git a/node/actors/network/src/noise/tests.rs b/node/actors/network/src/noise/tests.rs index 8ef5b71f..7ad33fcd 100644 --- a/node/actors/network/src/noise/tests.rs +++ b/node/actors/network/src/noise/tests.rs @@ -1,11 +1,11 @@ use crate::noise; -use concurrency::{ctx, io, scope}; use rand::Rng; use tracing::instrument::Instrument as _; +use zksync_concurrency::{ctx, io, scope, testonly::abort_on_panic}; #[tokio::test] async fn transmit_ok() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let (mut s1, mut s2) = noise::testonly::pipe(ctx).await; let msg = "hello"; @@ -44,7 +44,7 @@ async fn transmit_ok() { #[tokio::test] async fn transmit_sender_dies() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let (mut s1, mut s2) = noise::testonly::pipe(ctx).await; let msg = "hello"; @@ -74,7 +74,7 @@ async fn transmit_sender_dies() { #[tokio::test] async fn transmit_receiver_dies() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); let (s1, s2) = noise::testonly::pipe(ctx).await; diff --git a/node/actors/network/src/pool.rs b/node/actors/network/src/pool.rs index d694c543..92257993 100644 --- a/node/actors/network/src/pool.rs +++ b/node/actors/network/src/pool.rs @@ -1,8 +1,8 @@ //! An abstraction for a set of "connections" which constraints //! which peers are allowed to connect. use crate::watch::Watch; -use concurrency::sync; use std::collections::HashSet; +use zksync_concurrency::sync; /// Set of elements of type T. /// This set consists of an arbitrary subset of `allowed` + up to `extra_limit` elements outside of diff --git a/node/actors/network/src/preface.rs b/node/actors/network/src/preface.rs index 37542746..5cb53ac9 100644 --- a/node/actors/network/src/preface.rs +++ b/node/actors/network/src/preface.rs @@ -8,8 +8,9 @@ //! Hence, the preface protocol is used to enable encryption //! and multiplex between mutliple endpoints available on the same TCP port. use crate::{frame, metrics, noise}; -use concurrency::{ctx, time}; -use schema::{proto::network::preface as proto, required, ProtoFmt}; +use zksync_concurrency::{ctx, time}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::preface as proto, required, ProtoFmt}; /// Timeout on executing the preface protocol. const TIMEOUT: time::Duration = time::Duration::seconds(5); diff --git a/node/actors/network/src/rpc/consensus.rs b/node/actors/network/src/rpc/consensus.rs index 3df4e58e..86365eb0 100644 --- a/node/actors/network/src/rpc/consensus.rs +++ b/node/actors/network/src/rpc/consensus.rs @@ -1,8 +1,9 @@ //! Defines RPC for passing consensus messages. use crate::mux; -use concurrency::{limiter, time}; -use roles::validator; -use schema::{proto::network::consensus as proto, read_required, ProtoFmt}; +use zksync_concurrency::{limiter, time}; +use zksync_consensus_roles::validator; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::consensus as proto, read_required, ProtoFmt}; /// Consensus RPC. pub(crate) struct Rpc; diff --git a/node/actors/network/src/rpc/metrics.rs b/node/actors/network/src/rpc/metrics.rs index a8770168..a9111cec 100644 --- a/node/actors/network/src/rpc/metrics.rs +++ b/node/actors/network/src/rpc/metrics.rs @@ -6,6 +6,7 @@ use vise::{ Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LabeledFamily, Metrics, Unit, }; +use zksync_consensus_schema as schema; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue)] #[metrics(rename_all = "snake_case")] diff --git a/node/actors/network/src/rpc/mod.rs b/node/actors/network/src/rpc/mod.rs index a4609016..b3173821 100644 --- a/node/actors/network/src/rpc/mod.rs +++ b/node/actors/network/src/rpc/mod.rs @@ -18,8 +18,9 @@ use self::metrics::{CallLatencyType, CallType, RPC_METRICS}; use crate::{frame, mux}; use anyhow::Context as _; -use concurrency::{ctx, io, limiter, metrics::LatencyHistogramExt as _, scope}; use std::{collections::BTreeMap, sync::Arc}; +use zksync_concurrency::{ctx, io, limiter, metrics::LatencyHistogramExt as _, scope}; +use zksync_consensus_schema as schema; pub(crate) mod consensus; mod metrics; diff --git a/node/actors/network/src/rpc/ping.rs b/node/actors/network/src/rpc/ping.rs index 5f95def5..98a292bc 100644 --- a/node/actors/network/src/rpc/ping.rs +++ b/node/actors/network/src/rpc/ping.rs @@ -1,9 +1,10 @@ //! Defines an RPC for sending ping messages. use crate::{mux, rpc::Rpc as _}; use anyhow::Context as _; -use concurrency::{ctx, limiter, time}; use rand::Rng; -use schema::{proto::network::ping as proto, required, ProtoFmt}; +use zksync_concurrency::{ctx, limiter, time}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::ping as proto, required, ProtoFmt}; /// Ping RPC. pub(crate) struct Rpc; diff --git a/node/actors/network/src/rpc/sync_blocks.rs b/node/actors/network/src/rpc/sync_blocks.rs index 84fa071b..26454b53 100644 --- a/node/actors/network/src/rpc/sync_blocks.rs +++ b/node/actors/network/src/rpc/sync_blocks.rs @@ -2,9 +2,10 @@ use crate::{io, mux}; use anyhow::Context; -use concurrency::{limiter, time}; -use roles::validator::{BlockNumber, FinalBlock}; -use schema::{proto::network::gossip as proto, read_required, ProtoFmt}; +use zksync_concurrency::{limiter, time}; +use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::gossip as proto, read_required, ProtoFmt}; /// `get_sync_state` RPC. #[derive(Debug)] diff --git a/node/actors/network/src/rpc/sync_validator_addrs.rs b/node/actors/network/src/rpc/sync_validator_addrs.rs index b1441355..587c4dbd 100644 --- a/node/actors/network/src/rpc/sync_validator_addrs.rs +++ b/node/actors/network/src/rpc/sync_validator_addrs.rs @@ -1,11 +1,11 @@ //! Defines an Rpc for synchronizing ValidatorAddrs data. - use crate::mux; use anyhow::Context as _; -use concurrency::{limiter, time}; -use roles::validator; -use schema::{proto::network::gossip as proto, ProtoFmt}; use std::sync::Arc; +use zksync_concurrency::{limiter, time}; +use zksync_consensus_roles::validator; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{proto::network::gossip as proto, ProtoFmt}; /// SyncValidatorAddrs Rpc. pub(crate) struct Rpc; diff --git a/node/actors/network/src/rpc/testonly.rs b/node/actors/network/src/rpc/testonly.rs index 972d380a..d176790e 100644 --- a/node/actors/network/src/rpc/testonly.rs +++ b/node/actors/network/src/rpc/testonly.rs @@ -7,7 +7,7 @@ use rand::{ distributions::{Distribution, Standard}, Rng, }; -use roles::validator; +use zksync_consensus_roles::validator; impl Distribution for Standard { fn sample(&self, rng: &mut R) -> consensus::Req { diff --git a/node/actors/network/src/rpc/tests.rs b/node/actors/network/src/rpc/tests.rs index 69f3e8e2..d2e98851 100644 --- a/node/actors/network/src/rpc/tests.rs +++ b/node/actors/network/src/rpc/tests.rs @@ -1,11 +1,12 @@ use super::*; use crate::noise; -use concurrency::{ctx, time}; use rand::Rng as _; use std::{ collections::HashSet, sync::atomic::{AtomicU64, Ordering}, }; +use zksync_concurrency::{ctx, testonly::abort_on_panic, time}; +use zksync_consensus_schema::testonly::test_encode_random; /// CAPABILITY_ID should uniquely identify the RPC. #[test] @@ -21,8 +22,8 @@ fn test_capability_rpc_correspondence() { #[test] fn test_schema_encode_decode() { let rng = &mut ctx::test_root(&ctx::RealClock).rng(); - schema::testonly::test_encode_random::<_, consensus::Req>(rng); - schema::testonly::test_encode_random::<_, sync_validator_addrs::Resp>(rng); + test_encode_random::<_, consensus::Req>(rng); + test_encode_random::<_, sync_validator_addrs::Resp>(rng); } fn expected(res: Result<(), mux::RunError>) -> Result<(), mux::RunError> { @@ -34,7 +35,7 @@ fn expected(res: Result<(), mux::RunError>) -> Result<(), mux::RunError> { #[tokio::test] async fn test_ping() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let clock = ctx::ManualClock::new(); let ctx = &ctx::test_root(&clock); let (s1, s2) = noise::testonly::pipe(ctx).await; @@ -86,7 +87,7 @@ impl Handler for PingServer { #[tokio::test] async fn test_ping_loop() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let clock = ctx::ManualClock::new(); clock.set_advance_on_sleep(); let ctx = &ctx::test_root(&clock); @@ -150,7 +151,7 @@ impl Handler for ExampleServer { #[tokio::test] async fn test_inflight() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let (s1, s2) = noise::testonly::pipe(ctx).await; let client = Client::::new(ctx); diff --git a/node/actors/network/src/state.rs b/node/actors/network/src/state.rs index 4d6edbdc..ae9269c6 100644 --- a/node/actors/network/src/state.rs +++ b/node/actors/network/src/state.rs @@ -2,10 +2,10 @@ use super::{consensus, event::Event, gossip, metrics, preface}; use crate::io::{InputMessage, OutputMessage, SyncState}; use anyhow::Context as _; -use concurrency::{ctx, ctx::channel, net, scope, sync::watch}; -use roles::validator; use std::sync::Arc; -use utils::pipe::ActorPipe; +use zksync_concurrency::{ctx, ctx::channel, net, scope, sync::watch}; +use zksync_consensus_roles::validator; +use zksync_consensus_utils::pipe::ActorPipe; /// Network actor config. #[derive(Debug, Clone)] diff --git a/node/actors/network/src/testonly.rs b/node/actors/network/src/testonly.rs index 72007f28..d913e142 100644 --- a/node/actors/network/src/testonly.rs +++ b/node/actors/network/src/testonly.rs @@ -1,18 +1,18 @@ //! Testonly utilities. #![allow(dead_code)] use crate::{consensus, event::Event, gossip, io::SyncState, Config, State}; -use concurrency::{ - ctx, - ctx::channel, - io, net, - sync::{self, watch}, -}; use rand::Rng; -use roles::validator; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; +use zksync_concurrency::{ + ctx, + ctx::channel, + io, net, + sync::{self, watch}, +}; +use zksync_consensus_roles::validator; /// Synchronously forwards data from one stream to another. pub(crate) async fn forward( diff --git a/node/actors/network/src/tests.rs b/node/actors/network/src/tests.rs index ce42f70b..e6b5b220 100644 --- a/node/actors/network/src/tests.rs +++ b/node/actors/network/src/tests.rs @@ -1,13 +1,13 @@ use crate::{run_network, testonly}; -use concurrency::{ctx, scope}; use tracing::Instrument as _; -use utils::pipe; +use zksync_concurrency::{ctx, scope, testonly::abort_on_panic}; +use zksync_consensus_utils::pipe; /// Test that metrics are correctly defined /// (won't panic during registration). #[tokio::test] async fn test_metrics() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &mut ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); let nodes = testonly::Instance::new(rng, 3, 1); diff --git a/node/actors/network/src/watch.rs b/node/actors/network/src/watch.rs index ef5a15ce..459d46d4 100644 --- a/node/actors/network/src/watch.rs +++ b/node/actors/network/src/watch.rs @@ -1,5 +1,5 @@ //! Wrapper of the tokio::sync::Watch for easier usage. -use concurrency::sync; +use zksync_concurrency::sync; /// Wrapper of the tokio::sync::Watch. pub(crate) struct Watch { diff --git a/node/actors/sync_blocks/Cargo.toml b/node/actors/sync_blocks/Cargo.toml index 646132d2..be4f696c 100644 --- a/node/actors/sync_blocks/Cargo.toml +++ b/node/actors/sync_blocks/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sync_blocks" +name = "zksync_consensus_sync_blocks" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,17 +7,16 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_network.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_storage.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true thiserror.workspace = true tracing.workspace = true -concurrency = { path = "../../libs/concurrency" } -roles = { path = "../../libs/roles" } -storage = { path = "../../libs/storage" } -utils = { path = "../../libs/utils" } - -network = { path = "../network" } - [dev-dependencies] assert_matches.workspace = true async-trait.workspace = true diff --git a/node/actors/sync_blocks/src/config.rs b/node/actors/sync_blocks/src/config.rs index a279a808..3bc44839 100644 --- a/node/actors/sync_blocks/src/config.rs +++ b/node/actors/sync_blocks/src/config.rs @@ -1,7 +1,7 @@ //! Configuration for the `SyncBlocks` actor. -use concurrency::time; -use roles::validator::ValidatorSet; +use zksync_concurrency::time; +use zksync_consensus_roles::validator::ValidatorSet; /// Configuration for the `SyncBlocks` actor. #[derive(Debug)] diff --git a/node/actors/sync_blocks/src/io.rs b/node/actors/sync_blocks/src/io.rs index 9a83494e..cb4a9225 100644 --- a/node/actors/sync_blocks/src/io.rs +++ b/node/actors/sync_blocks/src/io.rs @@ -1,6 +1,6 @@ //! Input and output messages for the [`SyncBlocks`](crate::SyncBlocks) actor. -use network::io::{SyncBlocksInputMessage, SyncBlocksRequest}; +use zksync_consensus_network::io::{SyncBlocksInputMessage, SyncBlocksRequest}; /// All the messages that other actors can send to the `SyncBlocks` actor. #[derive(Debug)] diff --git a/node/actors/sync_blocks/src/lib.rs b/node/actors/sync_blocks/src/lib.rs index 6992470a..b25211a6 100644 --- a/node/actors/sync_blocks/src/lib.rs +++ b/node/actors/sync_blocks/src/lib.rs @@ -2,20 +2,19 @@ //! //! This crate contains an actor implementing block syncing among nodes, which is tied to the gossip //! network RPCs. - use crate::{ io::{InputMessage, OutputMessage}, message_handler::SyncBlocksMessageHandler, }; -use concurrency::{ +use std::sync::Arc; +use tracing::instrument; +use zksync_concurrency::{ ctx, scope, sync::{self, watch}, }; -use network::io::SyncState; -use std::sync::Arc; -use storage::{StorageError, StorageResult, WriteBlockStore}; -use tracing::instrument; -use utils::pipe::ActorPipe; +use zksync_consensus_network::io::SyncState; +use zksync_consensus_storage::{StorageError, StorageResult, WriteBlockStore}; +use zksync_consensus_utils::pipe::ActorPipe; mod config; pub mod io; diff --git a/node/actors/sync_blocks/src/message_handler.rs b/node/actors/sync_blocks/src/message_handler.rs index 16343134..0e94c9f1 100644 --- a/node/actors/sync_blocks/src/message_handler.rs +++ b/node/actors/sync_blocks/src/message_handler.rs @@ -1,12 +1,12 @@ //! Inner details of `SyncBlocks` actor. use crate::{io::InputMessage, peers::PeerStatesHandle}; -use concurrency::ctx::{self, channel}; -use network::io::{GetBlockError, GetBlockResponse, SyncBlocksRequest}; -use roles::validator::BlockNumber; use std::sync::Arc; -use storage::{StorageResult, WriteBlockStore}; use tracing::instrument; +use zksync_concurrency::ctx::{self, channel}; +use zksync_consensus_network::io::{GetBlockError, GetBlockResponse, SyncBlocksRequest}; +use zksync_consensus_roles::validator::BlockNumber; +use zksync_consensus_storage::{StorageResult, WriteBlockStore}; /// Inner details of `SyncBlocks` actor allowing to process messages. #[derive(Debug)] diff --git a/node/actors/sync_blocks/src/peers/events.rs b/node/actors/sync_blocks/src/peers/events.rs index 97980d2a..186099be 100644 --- a/node/actors/sync_blocks/src/peers/events.rs +++ b/node/actors/sync_blocks/src/peers/events.rs @@ -1,6 +1,6 @@ //! Events emitted by `PeerStates` actor. Useful for testing. -use roles::{node, validator::BlockNumber}; +use zksync_consensus_roles::{node, validator::BlockNumber}; /// Events emitted by `PeerStates` actor. Only used for tests so far. #[derive(Debug)] diff --git a/node/actors/sync_blocks/src/peers/mod.rs b/node/actors/sync_blocks/src/peers/mod.rs index 1e2d5da6..43d98246 100644 --- a/node/actors/sync_blocks/src/peers/mod.rs +++ b/node/actors/sync_blocks/src/peers/mod.rs @@ -3,19 +3,19 @@ use self::events::PeerStateEvent; use crate::{io, Config}; use anyhow::Context as _; -use concurrency::{ +use std::{collections::HashMap, sync::Arc}; +use tracing::instrument; +use zksync_concurrency::{ ctx::{self, channel}, oneshot, scope, sync::{self, watch, Mutex, Semaphore}, }; -use network::io::{SyncBlocksInputMessage, SyncState}; -use roles::{ +use zksync_consensus_network::io::{SyncBlocksInputMessage, SyncState}; +use zksync_consensus_roles::{ node, validator::{BlockHeader, BlockNumber, FinalBlock, PayloadHash}, }; -use std::{collections::HashMap, sync::Arc}; -use storage::{StorageResult, WriteBlockStore}; -use tracing::instrument; +use zksync_consensus_storage::{StorageResult, WriteBlockStore}; mod events; #[cfg(test)] diff --git a/node/actors/sync_blocks/src/peers/tests.rs b/node/actors/sync_blocks/src/peers/tests.rs index 6eea24fa..74ac69db 100644 --- a/node/actors/sync_blocks/src/peers/tests.rs +++ b/node/actors/sync_blocks/src/peers/tests.rs @@ -2,12 +2,12 @@ use super::*; use crate::tests::TestValidators; use assert_matches::assert_matches; use async_trait::async_trait; -use concurrency::time; use rand::{rngs::StdRng, seq::IteratorRandom, Rng}; -use roles::validator; use std::{collections::HashSet, fmt}; -use storage::{BlockStore, InMemoryStorage, StorageError}; use test_casing::{test_casing, Product}; +use zksync_concurrency::{testonly::abort_on_panic, time}; +use zksync_consensus_roles::validator; +use zksync_consensus_storage::{BlockStore, InMemoryStorage, StorageError}; const TEST_TIMEOUT: time::Duration = time::Duration::seconds(5); const BLOCK_SLEEP_INTERVAL: time::Duration = time::Duration::milliseconds(5); @@ -84,7 +84,7 @@ async fn wait_for_peer_update( #[instrument(level = "trace")] async fn test_peer_states(test: T) { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock).with_timeout(TEST_TIMEOUT); let clock = ctx::ManualClock::new(); diff --git a/node/actors/sync_blocks/src/tests/end_to_end.rs b/node/actors/sync_blocks/src/tests/end_to_end.rs index 1d9256bf..610834a3 100644 --- a/node/actors/sync_blocks/src/tests/end_to_end.rs +++ b/node/actors/sync_blocks/src/tests/end_to_end.rs @@ -1,16 +1,16 @@ //! End-to-end tests that launch a network of nodes and the `SyncBlocks` actor for each node. - use super::*; use anyhow::Context as _; use async_trait::async_trait; -use concurrency::ctx::channel; -use network::testonly::Instance as NetworkInstance; use rand::seq::SliceRandom; -use roles::node; use std::fmt; -use storage::InMemoryStorage; use test_casing::test_casing; use tracing::Instrument; +use zksync_concurrency::{ctx::channel, testonly::abort_on_panic}; +use zksync_consensus_network as network; +use zksync_consensus_network::testonly::Instance as NetworkInstance; +use zksync_consensus_roles::node; +use zksync_consensus_storage::InMemoryStorage; type NetworkDispatcherPipe = pipe::DispatcherPipe; @@ -230,7 +230,7 @@ trait GossipNetworkTest: fmt::Debug + Send { async fn test_sync_blocks(test: T) { const CLOCK_SPEEDUP: u32 = 25; - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(CLOCK_SPEEDUP as f64)) .with_timeout(TEST_TIMEOUT * CLOCK_SPEEDUP); diff --git a/node/actors/sync_blocks/src/tests/mod.rs b/node/actors/sync_blocks/src/tests/mod.rs index 9d361189..fe0fe2b2 100644 --- a/node/actors/sync_blocks/src/tests/mod.rs +++ b/node/actors/sync_blocks/src/tests/mod.rs @@ -1,20 +1,19 @@ //! Tests for the block syncing actor. - use super::*; -use concurrency::{oneshot, time}; -use network::io::{GetBlockError, GetBlockResponse, SyncBlocksRequest}; use rand::{ distributions::{Distribution, Standard}, Rng, }; -use roles::validator::{ +use std::iter; +use zksync_concurrency::{oneshot, testonly::abort_on_panic, time}; +use zksync_consensus_network::io::{GetBlockError, GetBlockResponse, SyncBlocksRequest}; +use zksync_consensus_roles::validator::{ self, testonly::{make_block, make_genesis_block}, BlockHeader, BlockNumber, CommitQC, FinalBlock, Payload, ValidatorSet, }; -use std::iter; -use storage::InMemoryStorage; -use utils::pipe; +use zksync_consensus_storage::InMemoryStorage; +use zksync_consensus_utils::pipe; mod end_to_end; @@ -104,7 +103,7 @@ impl TestValidators { #[tokio::test] async fn subscribing_to_state_updates() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); @@ -179,7 +178,7 @@ async fn subscribing_to_state_updates() { #[tokio::test] async fn getting_blocks() { - concurrency::testonly::abort_on_panic(); + abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); diff --git a/node/libs/concurrency/Cargo.toml b/node/libs/concurrency/Cargo.toml index 81e73352..7cfb3e9f 100644 --- a/node/libs/concurrency/Cargo.toml +++ b/node/libs/concurrency/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "concurrency" +name = "zksync_concurrency" version = "0.1.0" edition.workspace = true authors.workspace = true diff --git a/node/libs/crypto/Cargo.toml b/node/libs/crypto/Cargo.toml index 4b8f96f3..117dfae2 100644 --- a/node/libs/crypto/Cargo.toml +++ b/node/libs/crypto/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "crypto" +name = "zksync_consensus_crypto" version = "0.1.0" edition.workspace = true authors.workspace = true diff --git a/node/libs/crypto/benches/bench.rs b/node/libs/crypto/benches/bench.rs index 99d6c477..bc47f648 100644 --- a/node/libs/crypto/benches/bench.rs +++ b/node/libs/crypto/benches/bench.rs @@ -1,14 +1,12 @@ #![allow(clippy::missing_docs_in_private_items)] #![allow(missing_docs)] -extern crate crypto; - use criterion::{criterion_group, criterion_main, Criterion}; use rand::Rng; use std::iter::repeat_with; fn bench_bn254(c: &mut Criterion) { - use crypto::bn254::{AggregateSignature, PublicKey, SecretKey, Signature}; + use zksync_consensus_crypto::bn254::{AggregateSignature, PublicKey, SecretKey, Signature}; let mut rng = rand::thread_rng(); let mut group = c.benchmark_group("bn254"); group.bench_function("100 sig aggregation", |b| { @@ -27,7 +25,7 @@ fn bench_bn254(c: &mut Criterion) { #[allow(missing_docs)] fn bench_bls12_381(c: &mut Criterion) { - use crypto::bls12_381::{AggregateSignature, PublicKey, SecretKey, Signature}; + use zksync_consensus_crypto::bls12_381::{AggregateSignature, PublicKey, SecretKey, Signature}; let mut rng = rand::thread_rng(); let mut group = c.benchmark_group("bls12_381"); group.bench_function("100 sig aggregation", |b| { diff --git a/node/libs/roles/Cargo.toml b/node/libs/roles/Cargo.toml index d63b5eab..fdd1bb84 100644 --- a/node/libs/roles/Cargo.toml +++ b/node/libs/roles/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "roles" +name = "zksync_consensus_roles" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,14 +7,14 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_crypto.workspace = true +zksync_consensus_schema.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true bit-vec.workspace = true hex.workspace = true rand.workspace = true serde.workspace = true tracing.workspace = true - -concurrency = { path = "../concurrency" } -crypto = { path = "../crypto" } -schema = { path = "../schema" } -utils = { path = "../utils" } diff --git a/node/libs/roles/src/node/conv.rs b/node/libs/roles/src/node/conv.rs index aad1edde..52924ec6 100644 --- a/node/libs/roles/src/node/conv.rs +++ b/node/libs/roles/src/node/conv.rs @@ -1,8 +1,8 @@ use crate::node; -use ::schema::{read_required, required, ProtoFmt}; use anyhow::Context as _; -use crypto::ByteFmt; -use utils::enum_util::Variant; +use zksync_consensus_crypto::ByteFmt; +use zksync_consensus_schema::{read_required, required, ProtoFmt}; +use zksync_consensus_utils::enum_util::Variant; impl ProtoFmt for node::Msg { type Proto = node::schema::Msg; diff --git a/node/libs/roles/src/node/keys.rs b/node/libs/roles/src/node/keys.rs index ab58fa4d..0d8447a8 100644 --- a/node/libs/roles/src/node/keys.rs +++ b/node/libs/roles/src/node/keys.rs @@ -3,10 +3,10 @@ //! Each node must have a different key. use super::{Msg, MsgHash, Signed}; -use crypto::{ed25519, ByteFmt, Text, TextFmt}; pub use ed25519::InvalidSignatureError; use std::{fmt, sync::Arc}; -use utils::enum_util::Variant; +use zksync_consensus_crypto::{ed25519, ByteFmt, Text, TextFmt}; +use zksync_consensus_utils::enum_util::Variant; /// A node's secret key. #[derive(Clone)] diff --git a/node/libs/roles/src/node/messages.rs b/node/libs/roles/src/node/messages.rs index 18c815d5..9c87f025 100644 --- a/node/libs/roles/src/node/messages.rs +++ b/node/libs/roles/src/node/messages.rs @@ -1,6 +1,7 @@ use crate::node; -use crypto::{sha256, ByteFmt, Text, TextFmt}; -use utils::enum_util::{BadVariantError, Variant}; +use zksync_consensus_crypto::{sha256, ByteFmt, Text, TextFmt}; +use zksync_consensus_schema as schema; +use zksync_consensus_utils::enum_util::{BadVariantError, Variant}; /// The ID for an authentication session. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/node/libs/roles/src/node/mod.rs b/node/libs/roles/src/node/mod.rs index a11eb6c9..e22bfd04 100644 --- a/node/libs/roles/src/node/mod.rs +++ b/node/libs/roles/src/node/mod.rs @@ -7,7 +7,7 @@ mod testonly; pub use keys::*; pub use messages::*; -pub use schema::proto::roles::node as schema; +pub use zksync_consensus_schema::proto::roles::node as schema; #[cfg(test)] mod tests; diff --git a/node/libs/roles/src/node/testonly.rs b/node/libs/roles/src/node/testonly.rs index f2798188..1d712ebb 100644 --- a/node/libs/roles/src/node/testonly.rs +++ b/node/libs/roles/src/node/testonly.rs @@ -4,7 +4,7 @@ use rand::{ Rng, }; use std::sync::Arc; -use utils::enum_util::Variant; +use zksync_consensus_utils::enum_util::Variant; impl Distribution for Standard { fn sample(&self, rng: &mut R) -> MsgHash { diff --git a/node/libs/roles/src/node/tests.rs b/node/libs/roles/src/node/tests.rs index b8cbfb4f..2d208796 100644 --- a/node/libs/roles/src/node/tests.rs +++ b/node/libs/roles/src/node/tests.rs @@ -1,8 +1,8 @@ use super::*; -use ::schema::testonly::{test_encode, test_encode_random}; -use concurrency::ctx; -use crypto::{ByteFmt, Text, TextFmt}; use rand::Rng; +use zksync_concurrency::ctx; +use zksync_consensus_crypto::{ByteFmt, Text, TextFmt}; +use zksync_consensus_schema::testonly::{test_encode, test_encode_random}; #[test] fn test_byte_encoding() { diff --git a/node/libs/roles/src/validator/conv.rs b/node/libs/roles/src/validator/conv.rs index c96fc2f7..69d5d179 100644 --- a/node/libs/roles/src/validator/conv.rs +++ b/node/libs/roles/src/validator/conv.rs @@ -5,12 +5,14 @@ use super::{ Signers, ViewNumber, }; use crate::node::SessionId; -use ::schema::{read_required, required, ProtoFmt}; use anyhow::Context as _; -use crypto::ByteFmt; -use schema::proto::roles::validator as proto; use std::collections::BTreeMap; -use utils::enum_util::Variant; +use zksync_consensus_crypto::ByteFmt; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{ + proto::roles::validator as proto, read_required, required, ProtoFmt, +}; +use zksync_consensus_utils::enum_util::Variant; impl ProtoFmt for BlockHeaderHash { type Proto = proto::BlockHeaderHash; diff --git a/node/libs/roles/src/validator/keys/aggregate_signature.rs b/node/libs/roles/src/validator/keys/aggregate_signature.rs index 7f1d6ee8..49e9cd62 100644 --- a/node/libs/roles/src/validator/keys/aggregate_signature.rs +++ b/node/libs/roles/src/validator/keys/aggregate_signature.rs @@ -1,8 +1,8 @@ use super::{Error, PublicKey, Signature}; use crate::validator::messages::{Msg, MsgHash}; -use crypto::{bn254, ByteFmt, Text, TextFmt}; use std::fmt; -use utils::enum_util::Variant; +use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt}; +use zksync_consensus_utils::enum_util::Variant; /// An aggregate signature from a validator. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] diff --git a/node/libs/roles/src/validator/keys/mod.rs b/node/libs/roles/src/validator/keys/mod.rs index 77e23ff9..43069397 100644 --- a/node/libs/roles/src/validator/keys/mod.rs +++ b/node/libs/roles/src/validator/keys/mod.rs @@ -11,4 +11,4 @@ pub use secret_key::SecretKey; pub use signature::Signature; /// Error type returned by validator key operations. -pub type Error = crypto::bn254::Error; +pub type Error = zksync_consensus_crypto::bn254::Error; diff --git a/node/libs/roles/src/validator/keys/public_key.rs b/node/libs/roles/src/validator/keys/public_key.rs index 40f8edfc..3eb086b9 100644 --- a/node/libs/roles/src/validator/keys/public_key.rs +++ b/node/libs/roles/src/validator/keys/public_key.rs @@ -1,5 +1,5 @@ -use crypto::{bn254, ByteFmt, Text, TextFmt}; use std::fmt; +use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt}; /// A public key for a validator. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/node/libs/roles/src/validator/keys/secret_key.rs b/node/libs/roles/src/validator/keys/secret_key.rs index 4029ea23..f5126cbf 100644 --- a/node/libs/roles/src/validator/keys/secret_key.rs +++ b/node/libs/roles/src/validator/keys/secret_key.rs @@ -1,9 +1,9 @@ use super::{PublicKey, Signature}; use crate::validator::messages::{Msg, MsgHash, Signed}; -use crypto::{bn254, ByteFmt, Text, TextFmt}; use rand::Rng; use std::{fmt, sync::Arc}; -use utils::enum_util::Variant; +use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt}; +use zksync_consensus_utils::enum_util::Variant; /// A secret key for the validator role. /// SecretKey is put into an Arc, so that we can clone it, diff --git a/node/libs/roles/src/validator/keys/signature.rs b/node/libs/roles/src/validator/keys/signature.rs index d35ec6d6..7b05733f 100644 --- a/node/libs/roles/src/validator/keys/signature.rs +++ b/node/libs/roles/src/validator/keys/signature.rs @@ -1,7 +1,7 @@ use super::{Error, PublicKey}; use crate::validator::messages::{Msg, MsgHash}; -use crypto::{bn254, ByteFmt, Text, TextFmt}; use std::fmt; +use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt}; /// A signature from a validator. #[derive(Clone, PartialEq, Eq)] diff --git a/node/libs/roles/src/validator/messages/block.rs b/node/libs/roles/src/validator/messages/block.rs index e4c96180..6a6d44c1 100644 --- a/node/libs/roles/src/validator/messages/block.rs +++ b/node/libs/roles/src/validator/messages/block.rs @@ -1,8 +1,9 @@ //! Messages related to blocks. use super::CommitQC; -use crypto::{sha256, ByteFmt, Text, TextFmt}; use std::fmt; +use zksync_consensus_crypto::{sha256, ByteFmt, Text, TextFmt}; +use zksync_consensus_schema as schema; /// Payload of the block. Consensus algorithm does not interpret the payload /// (except for imposing a size limit for the payload). Proposing a payload @@ -162,11 +163,11 @@ impl FinalBlock { impl ByteFmt for FinalBlock { fn decode(bytes: &[u8]) -> anyhow::Result { - ::schema::decode(bytes) + schema::decode(bytes) } fn encode(&self) -> Vec { - ::schema::encode(self) + schema::encode(self) } } diff --git a/node/libs/roles/src/validator/messages/consensus.rs b/node/libs/roles/src/validator/messages/consensus.rs index 743e12f0..a6603ddb 100644 --- a/node/libs/roles/src/validator/messages/consensus.rs +++ b/node/libs/roles/src/validator/messages/consensus.rs @@ -5,7 +5,7 @@ use crate::validator; use anyhow::{bail, Context}; use bit_vec::BitVec; use std::collections::{BTreeMap, BTreeSet, HashMap}; -use utils::enum_util::{BadVariantError, Variant}; +use zksync_consensus_utils::enum_util::{BadVariantError, Variant}; /// Version of the consensus algorithm that the validator is using. /// It allows to prevent misinterpretation of messages signed by validators diff --git a/node/libs/roles/src/validator/messages/discovery.rs b/node/libs/roles/src/validator/messages/discovery.rs index c70f67ab..ec8ea26c 100644 --- a/node/libs/roles/src/validator/messages/discovery.rs +++ b/node/libs/roles/src/validator/messages/discovery.rs @@ -1,5 +1,5 @@ -use concurrency::time; use std::net; +use zksync_concurrency::time; /// A message broadcasted by a validator /// over the gossip network announcing diff --git a/node/libs/roles/src/validator/messages/msg.rs b/node/libs/roles/src/validator/messages/msg.rs index ac0e3bf8..c740e9ed 100644 --- a/node/libs/roles/src/validator/messages/msg.rs +++ b/node/libs/roles/src/validator/messages/msg.rs @@ -1,10 +1,10 @@ //! Generic message types. - use super::{ConsensusMsg, NetAddress}; use crate::{node::SessionId, validator, validator::Error}; -use crypto::{sha256, ByteFmt, Text, TextFmt}; use std::fmt; -use utils::enum_util::{BadVariantError, Variant}; +use zksync_consensus_crypto::{sha256, ByteFmt, Text, TextFmt}; +use zksync_consensus_schema as schema; +use zksync_consensus_utils::enum_util::{BadVariantError, Variant}; /// Generic message type for a validator. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/node/libs/roles/src/validator/testonly.rs b/node/libs/roles/src/validator/testonly.rs index dad8d8e8..6952cc46 100644 --- a/node/libs/roles/src/validator/testonly.rs +++ b/node/libs/roles/src/validator/testonly.rs @@ -6,13 +6,13 @@ use super::{ Signed, Signers, ValidatorSet, ViewNumber, CURRENT_VERSION, }; use bit_vec::BitVec; -use concurrency::time; use rand::{ distributions::{Distribution, Standard}, Rng, }; use std::sync::Arc; -use utils::enum_util::Variant; +use zksync_concurrency::time; +use zksync_consensus_utils::enum_util::Variant; /// Constructs a CommitQC with `CommitQC.message.proposal` matching header. /// WARNING: it is not a fully correct CommitQC. diff --git a/node/libs/roles/src/validator/tests.rs b/node/libs/roles/src/validator/tests.rs index 9309ea64..8030afbf 100644 --- a/node/libs/roles/src/validator/tests.rs +++ b/node/libs/roles/src/validator/tests.rs @@ -1,9 +1,9 @@ use super::*; -use ::schema::testonly::test_encode_random; -use concurrency::ctx; -use crypto::{ByteFmt, Text, TextFmt}; use rand::Rng; use std::vec; +use zksync_concurrency::ctx; +use zksync_consensus_crypto::{ByteFmt, Text, TextFmt}; +use zksync_consensus_schema::testonly::test_encode_random; #[test] fn test_byte_encoding() { diff --git a/node/libs/schema/Cargo.toml b/node/libs/schema/Cargo.toml index ea9c6941..bdb3ac1c 100644 --- a/node/libs/schema/Cargo.toml +++ b/node/libs/schema/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "schema" +name = "zksync_consensus_schema" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -10,6 +10,8 @@ license.workspace = true name = "conformance_test" [dependencies] +zksync_concurrency.workspace = true + anyhow.workspace = true bit-vec.workspace = true serde.workspace = true @@ -21,8 +23,6 @@ rand.workspace = true serde_json.workspace = true tokio.workspace = true -concurrency = { path = "../concurrency" } - [build-dependencies] anyhow.workspace = true syn.workspace = true diff --git a/node/libs/schema/src/bin/conformance_test.rs b/node/libs/schema/src/bin/conformance_test.rs index e6de4eaa..38b9d1bb 100644 --- a/node/libs/schema/src/bin/conformance_test.rs +++ b/node/libs/schema/src/bin/conformance_test.rs @@ -6,10 +6,11 @@ //! subset of original fields. Also we run only proto3 binary -> binary tests. //! conformance_test_failure_list.txt contains tests which are expected to fail. use anyhow::Context as _; -use concurrency::{ctx, io}; use prost::Message as _; use prost_reflect::ReflectMessage; -use schema::proto::conformance as proto; +use zksync_concurrency::{ctx, io}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::proto::conformance as proto; #[tokio::main] async fn main() -> anyhow::Result<()> { @@ -36,7 +37,7 @@ async fn main() -> anyhow::Result<()> { // Decode. let payload = req.payload.context("missing payload")?; - use schema::proto::protobuf_test_messages::proto3::TestAllTypesProto3 as T; + use zksync_consensus_schema::proto::protobuf_test_messages::proto3::TestAllTypesProto3 as T; let p = match payload { proto::conformance_request::Payload::JsonPayload(payload) => { match schema::decode_json_proto(&payload) { diff --git a/node/libs/schema/src/std_conv.rs b/node/libs/schema/src/std_conv.rs index 2f2fa89b..264969b5 100644 --- a/node/libs/schema/src/std_conv.rs +++ b/node/libs/schema/src/std_conv.rs @@ -1,8 +1,8 @@ //! Proto conversion for messages in std package. use crate::{proto::std as proto, required, ProtoFmt}; use anyhow::Context as _; -use concurrency::time; use std::net; +use zksync_concurrency::time; impl ProtoFmt for () { type Proto = proto::Void; diff --git a/node/libs/schema/src/tests.rs b/node/libs/schema/src/tests.rs index d4d8366e..ddd49783 100644 --- a/node/libs/schema/src/tests.rs +++ b/node/libs/schema/src/tests.rs @@ -1,7 +1,7 @@ use super::*; use anyhow::Context as _; -use concurrency::{ctx, time}; use std::net; +use zksync_concurrency::{ctx, time}; #[derive(Debug, PartialEq, Eq)] enum B { diff --git a/node/libs/storage/Cargo.toml b/node/libs/storage/Cargo.toml index 9629ee2b..67b685e6 100644 --- a/node/libs/storage/Cargo.toml +++ b/node/libs/storage/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "storage" +name = "zksync_consensus_storage" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,6 +7,10 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_schema.workspace = true + anyhow.workspace = true async-trait.workspace = true rand.workspace = true @@ -14,10 +18,6 @@ rocksdb = { workspace = true, optional = true } thiserror.workspace = true tracing.workspace = true -concurrency = { path = "../concurrency" } -roles = { path = "../roles" } -schema = { path = "../schema" } - [dev-dependencies] assert_matches.workspace = true tempfile.workspace = true diff --git a/node/libs/storage/src/in_memory.rs b/node/libs/storage/src/in_memory.rs index c4a45e7c..9c81e123 100644 --- a/node/libs/storage/src/in_memory.rs +++ b/node/libs/storage/src/in_memory.rs @@ -6,12 +6,12 @@ use crate::{ StorageResult, }; use async_trait::async_trait; -use concurrency::{ +use std::{collections::BTreeMap, ops}; +use zksync_concurrency::{ ctx, sync::{self, watch, Mutex}, }; -use roles::validator::{BlockNumber, FinalBlock}; -use std::{collections::BTreeMap, ops}; +use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; #[derive(Debug)] struct BlocksInMemoryStore { diff --git a/node/libs/storage/src/replica_state.rs b/node/libs/storage/src/replica_state.rs index 69335e4f..e10dc547 100644 --- a/node/libs/storage/src/replica_state.rs +++ b/node/libs/storage/src/replica_state.rs @@ -4,9 +4,9 @@ use crate::{ traits::{BlockStore, ReplicaStateStore}, types::{ReplicaState, StorageResult}, }; -use concurrency::ctx; -use roles::validator; use std::sync::Arc; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator; impl From for ReplicaState { fn from(certificate: validator::CommitQC) -> Self { diff --git a/node/libs/storage/src/rocksdb.rs b/node/libs/storage/src/rocksdb.rs index 7a8b0937..1a2ebe7b 100644 --- a/node/libs/storage/src/rocksdb.rs +++ b/node/libs/storage/src/rocksdb.rs @@ -2,7 +2,6 @@ //! chain of blocks, not a tree (assuming we have all blocks and not have any gap). It allows for basic functionality like inserting a block, //! getting a block, checking if a block is contained in the DB. We also store the head of the chain. Storing it explicitly allows us to fetch //! the current head quickly. - use crate::{ traits::{BlockStore, ReplicaStateStore, WriteBlockStore}, types::{MissingBlockNumbers, ReplicaState}, @@ -10,9 +9,7 @@ use crate::{ }; use anyhow::Context as _; use async_trait::async_trait; -use concurrency::{ctx, scope, sync::watch}; use rocksdb::{Direction, IteratorMode, ReadOptions}; -use roles::validator::{BlockNumber, FinalBlock}; use std::{ fmt, ops, path::Path, @@ -21,6 +18,9 @@ use std::{ RwLock, }, }; +use zksync_concurrency::{ctx, scope, sync::watch}; +use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; +use zksync_consensus_schema as schema; /// Enum used to represent a key in the database. It also acts as a separator between different stores. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/node/libs/storage/src/tests/mod.rs b/node/libs/storage/src/tests/mod.rs index 1190ff2c..8cd28276 100644 --- a/node/libs/storage/src/tests/mod.rs +++ b/node/libs/storage/src/tests/mod.rs @@ -1,10 +1,13 @@ use super::*; use crate::types::ReplicaState; use async_trait::async_trait; -use concurrency::ctx; use rand::{seq::SliceRandom, Rng}; -use roles::validator::{testonly::make_block, BlockHeader, BlockNumber, FinalBlock, Payload}; use std::iter; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator::{ + testonly::make_block, BlockHeader, BlockNumber, FinalBlock, Payload, +}; +use zksync_consensus_schema as schema; #[cfg(feature = "rocksdb")] mod rocksdb; diff --git a/node/libs/storage/src/traits.rs b/node/libs/storage/src/traits.rs index 0d0b544f..b53f6d4c 100644 --- a/node/libs/storage/src/traits.rs +++ b/node/libs/storage/src/traits.rs @@ -1,10 +1,9 @@ //! Traits for storage. - use crate::{types::ReplicaState, StorageResult}; use async_trait::async_trait; -use concurrency::{ctx, sync::watch}; -use roles::validator::{BlockNumber, FinalBlock}; use std::{fmt, ops, sync::Arc}; +use zksync_concurrency::{ctx, sync::watch}; +use zksync_consensus_roles::validator::{BlockNumber, FinalBlock}; /// Storage of L2 blocks. /// diff --git a/node/libs/storage/src/types.rs b/node/libs/storage/src/types.rs index 1b437ac5..0217a4de 100644 --- a/node/libs/storage/src/types.rs +++ b/node/libs/storage/src/types.rs @@ -1,10 +1,9 @@ //! Defines the schema of the database. - use anyhow::Context as _; -use concurrency::ctx; -use roles::validator::{self, BlockNumber}; -use schema::{proto::storage as proto, read_required, required, ProtoFmt}; use std::{iter, ops}; +use zksync_concurrency::ctx; +use zksync_consensus_roles::validator::{self, BlockNumber}; +use zksync_consensus_schema::{proto::storage as proto, read_required, required, ProtoFmt}; /// A payload of a proposed block which is not known to be finalized yet. /// Replicas have to persist such proposed payloads for liveness: diff --git a/node/libs/utils/Cargo.toml b/node/libs/utils/Cargo.toml index 1fd234b3..83c2694e 100644 --- a/node/libs/utils/Cargo.toml +++ b/node/libs/utils/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "utils" +name = "zksync_consensus_utils" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -7,6 +7,7 @@ homepage.workspace = true license.workspace = true [dependencies] +zksync_concurrency.workspace = true + thiserror.workspace = true -concurrency = { path = "../concurrency" } diff --git a/node/libs/utils/src/pipe.rs b/node/libs/utils/src/pipe.rs index 8eedab43..e8db302c 100644 --- a/node/libs/utils/src/pipe.rs +++ b/node/libs/utils/src/pipe.rs @@ -1,8 +1,8 @@ //! This is a wrapper around channels to make it simpler and less error-prone to connect actors and the dispatcher. //! A Pipe is a basically a bi-directional unbounded channel. -use concurrency::ctx::{self, channel, Ctx}; use std::future::Future; +use zksync_concurrency::ctx::{self, channel, Ctx}; /// This is the end of the Pipe that should be held by the actor. pub type ActorPipe = Pipe; diff --git a/node/tools/Cargo.toml b/node/tools/Cargo.toml index 4129497f..3102f33d 100644 --- a/node/tools/Cargo.toml +++ b/node/tools/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tools" +name = "zksync_consensus_tools" version = "0.1.0" edition.workspace = true authors.workspace = true @@ -9,6 +9,15 @@ publish = false default-run = "executor" [dependencies] +zksync_concurrency.workspace = true +zksync_consensus_bft.workspace = true +zksync_consensus_crypto.workspace = true +zksync_consensus_executor.workspace = true +zksync_consensus_roles.workspace = true +zksync_consensus_storage = { workspace = true, features = ["rocksdb"] } +zksync_consensus_schema.workspace = true +zksync_consensus_utils.workspace = true + anyhow.workspace = true clap.workspace = true rand.workspace = true @@ -17,16 +26,6 @@ tracing.workspace = true tracing-subscriber.workspace = true vise-exporter.workspace = true -concurrency = { path = "../libs/concurrency" } -crypto = { path = "../libs/crypto" } -roles = { path = "../libs/roles" } -storage = { path = "../libs/storage", features = ["rocksdb"] } -schema = { path = "../libs/schema" } -utils = { path = "../libs/utils" } - -consensus = { path = "../actors/consensus" } -executor = { path = "../actors/executor" } - [[bin]] name = "executor" path = "src/main.rs" diff --git a/node/tools/src/bin/keys.rs b/node/tools/src/bin/keys.rs index 63d5ec9e..2f2a0bfd 100644 --- a/node/tools/src/bin/keys.rs +++ b/node/tools/src/bin/keys.rs @@ -1,7 +1,8 @@ //! This tool generates a validator key pair and prints it to stdout. #![allow(clippy::print_stdout)] -use roles::validator; +use zksync_consensus_crypto as crypto; +use zksync_consensus_roles::validator; /// This tool generates a validator key pair and prints it to stdout. fn main() { diff --git a/node/tools/src/bin/localnet_config.rs b/node/tools/src/bin/localnet_config.rs index 20862ef5..95f74f5a 100644 --- a/node/tools/src/bin/localnet_config.rs +++ b/node/tools/src/bin/localnet_config.rs @@ -1,13 +1,14 @@ //! This tool constructs collection of node configs for running tests. use anyhow::Context as _; use clap::Parser; -use consensus::testonly; -use crypto::TextFmt; -use executor::{ConsensusConfig, ExecutorConfig, GossipConfig}; use rand::Rng; -use roles::{node, validator}; use std::{fs, net::SocketAddr, path::PathBuf}; -use tools::NodeConfig; +use zksync_consensus_bft::testonly; +use zksync_consensus_crypto::TextFmt; +use zksync_consensus_executor::{ConsensusConfig, ExecutorConfig, GossipConfig}; +use zksync_consensus_roles::{node, validator}; +use zksync_consensus_schema as schema; +use zksync_consensus_tools::NodeConfig; /// Replaces IP of the address with UNSPECIFIED (aka INADDR_ANY) of the corresponding IP type. /// Opening a listener socket with an UNSPECIFIED IP, means that the new connections diff --git a/node/tools/src/config.rs b/node/tools/src/config.rs index 0776659d..be7b4421 100644 --- a/node/tools/src/config.rs +++ b/node/tools/src/config.rs @@ -1,11 +1,13 @@ //! Node configuration. - use anyhow::Context as _; -use crypto::{read_optional_text, Text, TextFmt}; -use executor::{ConsensusConfig, ExecutorConfig}; -use roles::{node, validator}; -use schema::{proto::executor::config as proto, read_optional, read_required, ProtoFmt}; use std::{fs, net, path::Path}; +use zksync_consensus_crypto::{read_optional_text, Text, TextFmt}; +use zksync_consensus_executor::{ConsensusConfig, ExecutorConfig}; +use zksync_consensus_roles::{node, validator}; +use zksync_consensus_schema as schema; +use zksync_consensus_schema::{ + proto::executor::config as proto, read_optional, read_required, ProtoFmt, +}; /// This struct holds the file path to each of the config files. #[derive(Debug)] diff --git a/node/tools/src/main.rs b/node/tools/src/main.rs index 936b6dae..b781a248 100644 --- a/node/tools/src/main.rs +++ b/node/tools/src/main.rs @@ -1,25 +1,24 @@ //! Main binary for the consensus node. It reads the configuration, initializes all parts of the node and //! manages communication between the actors. It is the main executable in this workspace. - use anyhow::Context as _; use clap::Parser; -use concurrency::{ - ctx::{self, channel}, - scope, time, -}; -use executor::Executor; use std::{ fs, io::IsTerminal as _, path::{Path, PathBuf}, sync::Arc, }; -use storage::{BlockStore, RocksdbStorage}; -use tools::{ConfigPaths, Configs}; use tracing::metadata::LevelFilter; use tracing_subscriber::{prelude::*, Registry}; -use utils::no_copy::NoCopy; use vise_exporter::MetricsExporter; +use zksync_concurrency::{ + ctx::{self, channel}, + scope, time, +}; +use zksync_consensus_executor::Executor; +use zksync_consensus_storage::{BlockStore, RocksdbStorage}; +use zksync_consensus_tools::{ConfigPaths, Configs}; +use zksync_consensus_utils::no_copy::NoCopy; /// Command-line application launching a node executor. #[derive(Debug, Parser)]