Skip to content

Commit

Permalink
Merge branch 'main' into igor/quint-timeout-qc-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
konnov committed Aug 8, 2024
2 parents 5191830 + e9f8dfe commit 79f7eb6
Show file tree
Hide file tree
Showing 37 changed files with 1,100 additions and 625 deletions.
639 changes: 294 additions & 345 deletions node/Cargo.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ homepage = "https://matter-labs.io/"
repository = "https://github.com/matter-labs/era-consensus"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
version = "0.1.0-rc.4"
version = "0.1.0-rc.9"

[workspace.dependencies]
# Crates from this repo.
zksync_consensus_bft = { version = "=0.1.0-rc.4", path = "actors/bft" }
zksync_consensus_crypto = { version = "=0.1.0-rc.4", path = "libs/crypto" }
zksync_consensus_executor = { version = "=0.1.0-rc.4", path = "actors/executor" }
zksync_consensus_network = { version = "=0.1.0-rc.4", path = "actors/network" }
zksync_consensus_roles = { version = "=0.1.0-rc.4", path = "libs/roles" }
zksync_consensus_storage = { version = "=0.1.0-rc.4", path = "libs/storage" }
zksync_consensus_tools = { version = "=0.1.0-rc.4", path = "tools" }
zksync_consensus_utils = { version = "=0.1.0-rc.4", path = "libs/utils" }
zksync_consensus_bft = { version = "=0.1.0-rc.9", path = "actors/bft" }
zksync_consensus_crypto = { version = "=0.1.0-rc.9", path = "libs/crypto" }
zksync_consensus_executor = { version = "=0.1.0-rc.9", path = "actors/executor" }
zksync_consensus_network = { version = "=0.1.0-rc.9", path = "actors/network" }
zksync_consensus_roles = { version = "=0.1.0-rc.9", path = "libs/roles" }
zksync_consensus_storage = { version = "=0.1.0-rc.9", path = "libs/storage" }
zksync_consensus_tools = { version = "=0.1.0-rc.9", path = "tools" }
zksync_consensus_utils = { version = "=0.1.0-rc.9", path = "libs/utils" }

# Crates from this repo that might become independent in the future.
zksync_concurrency = { version = "=0.1.0-rc.4", path = "libs/concurrency" }
zksync_protobuf = { version = "=0.1.0-rc.4", path = "libs/protobuf" }
zksync_protobuf_build = { version = "=0.1.0-rc.4", path = "libs/protobuf_build" }
zksync_concurrency = { version = "=0.1.0-rc.9", path = "libs/concurrency" }
zksync_protobuf = { version = "=0.1.0-rc.9", path = "libs/protobuf" }
zksync_protobuf_build = { version = "=0.1.0-rc.9", path = "libs/protobuf_build" }

# Crates from Matter Labs.
pairing = { package = "pairing_ce", version = "=0.28.6" }
vise = "0.1.0"
vise-exporter = "0.1.0"
vise = "0.2.0"
vise-exporter = "0.2.0"

# Crates from third-parties.
anyhow = "1"
Expand Down
41 changes: 26 additions & 15 deletions node/actors/bft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::io::{InputMessage, OutputMessage};
use anyhow::Context;
pub use config::Config;
use std::sync::Arc;
use tracing::Instrument;
use zksync_concurrency::{ctx, error::Wrap as _, oneshot, scope};
use zksync_consensus_network::io::ConsensusReq;
use zksync_consensus_roles::validator;
Expand Down Expand Up @@ -90,24 +91,34 @@ impl Config {
// This is the infinite loop where the consensus actually runs. The validator waits for either
// a message from the network or for a timeout, and processes each accordingly.
loop {
let InputMessage::Network(req) = pipe.recv.recv(ctx).await?;
use validator::ConsensusMsg as M;
match &req.msg.msg {
M::ReplicaPrepare(_) => {
// This is a hacky way to do a clone. This is necessary since we don't want to derive
// Clone for ConsensusReq. When we change to ChonkyBFT this will be removed anyway.
let (ack, _) = oneshot::channel();
let new_req = ConsensusReq {
msg: req.msg.clone(),
ack,
};
async {
let InputMessage::Network(req) = pipe
.recv
.recv(ctx)
.instrument(tracing::info_span!("wait_for_message"))
.await?;
use validator::ConsensusMsg as M;
match &req.msg.msg {
M::ReplicaPrepare(_) => {
// This is a hacky way to do a clone. This is necessary since we don't want to derive
// Clone for ConsensusReq. When we change to ChonkyBFT this will be removed anyway.
let (ack, _) = oneshot::channel();
let new_req = ConsensusReq {
msg: req.msg.clone(),
ack,
};

replica_send.send(new_req);
leader_send.send(req);
replica_send.send(new_req);
leader_send.send(req);
}
M::ReplicaCommit(_) => leader_send.send(req),
M::LeaderPrepare(_) | M::LeaderCommit(_) => replica_send.send(req),
}
M::ReplicaCommit(_) => leader_send.send(req),
M::LeaderPrepare(_) | M::LeaderCommit(_) => replica_send.send(req),

ctx::Ok(())
}
.instrument(tracing::info_span!("bft_iter"))
.await?;
}
})
.await;
Expand Down
4 changes: 3 additions & 1 deletion node/actors/bft/src/testonly/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use zksync_concurrency::{
},
oneshot, scope,
};
use zksync_consensus_network as network;
use zksync_consensus_network::{self as network};
use zksync_consensus_roles::validator;
use zksync_consensus_storage::{testonly::TestMemoryStorage, BlockStore};
use zksync_consensus_utils::pipe;
Expand Down Expand Up @@ -135,9 +135,11 @@ impl Test {
for (i, net) in nets.into_iter().enumerate() {
let store = TestMemoryStorage::new(ctx, genesis).await;
s.spawn_bg(async { Ok(store.runner.run(ctx).await?) });

if self.nodes[i].0 == Behavior::Honest {
honest.push(store.blocks.clone());
}

nodes.push(Node {
net,
behavior: self.nodes[i].0,
Expand Down
8 changes: 4 additions & 4 deletions node/actors/bft/src/testonly/twins/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl<'a, T> Partitioner<'a, T> {
///
/// Take the table in [partitions] as an example with 4 items and 3 partitions.
/// * `A` is the first item, so it can only go into `P1`; `P2` can't be used while `P1` is empty,
/// otherwise we'd be generating redundant combinations.
/// otherwise we'd be generating redundant combinations.
/// * `B` can go minimally into `P1` because there are 2 more items after it, which is enough
/// to fill all remaining partitions; or it can go into `P2`, because `P1` is filled.
/// to fill all remaining partitions; or it can go into `P2`, because `P1` is filled.
/// * `C` depends on what we did with `B`: if `B` is in `P1` then `C` has to minimally go into
/// `P2` to make sure no partition will be left empty at the end; if `B` is in `P2` then `C`
/// can go either in `P1`, `P2` or `P3`.
/// `P2` to make sure no partition will be left empty at the end; if `B` is in `P2` then `C`
/// can go either in `P1`, `P2` or `P3`.
///
/// The algorithm has to traverse all possible placements with backtracking.
fn go(&mut self, idx: usize, first_empty: usize) {
Expand Down
1 change: 1 addition & 0 deletions node/actors/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zksync_consensus_utils.workspace = true
zksync_protobuf.workspace = true

anyhow.workspace = true
async-trait.workspace = true
rand.workspace = true
tracing.workspace = true
vise.workspace = true
Expand Down
Loading

0 comments on commit 79f7eb6

Please sign in to comment.