Skip to content

Commit

Permalink
Merge branch 'main' into bn254
Browse files Browse the repository at this point in the history
# Conflicts:
#	node/actors/consensus/src/leader/error.rs
#	node/actors/consensus/src/replica/error.rs
  • Loading branch information
moshababo committed Oct 29, 2023
2 parents 47b624f + 1c6e578 commit 7071f2e
Show file tree
Hide file tree
Showing 72 changed files with 2,000 additions and 1,397 deletions.
9 changes: 9 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CODEOWNERS @brunoffranca

/node/actors/consensus/ @brunoffranca
/node/actors/executor/ @brunoffranca @pompon0
/node/actors/network/ @pompon0
/node/actors/sync_blocks/ @slowli

/node/libs/concurrency/ @pompon0
/node/libs/crypto/ @brunoffranca
6 changes: 3 additions & 3 deletions .github/workflows/protobuf_conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
conformance:
runs-on: [ubuntu-22.04-github-hosted-16core]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: "this"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: "protocolbuffers/protobuf"
ref: "main"
ref: "v24.4"
path: "protobuf"
- uses: mozilla-actions/[email protected]
- name: build test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ at your option.
- [ZK Credo](https://github.com/zksync/credo)
- [Twitter](https://twitter.com/zksync)
- [Twitter for Devs](https://twitter.com/zkSyncDevs)
- [Discord](https://discord.gg/nMaPGrDDwk)
- [Discord](https://join.zksync.dev/)
7 changes: 7 additions & 0 deletions node/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions node/Cranky.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ warn = [
# cargo group
"clippy::wildcard_dependencies",
]

allow = [
# Produces too many false positives.
"clippy::redundant_locals",
"clippy::needless_pass_by_ref_mut",
]
55 changes: 0 additions & 55 deletions node/actors/consensus/src/leader/error.rs

This file was deleted.

1 change: 0 additions & 1 deletion node/actors/consensus/src/leader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! and aggregates replica messages. It mainly acts as a central point of communication for the replicas. Note that
//! our consensus node will perform both the replica and leader roles simultaneously.

mod error;
mod replica_commit;
mod replica_prepare;
mod state_machine;
Expand Down
64 changes: 52 additions & 12 deletions node/actors/consensus/src/leader/replica_commit.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
use super::StateMachine;
use crate::{inner::ConsensusInner, leader::error::Error, metrics};
use crate::{inner::ConsensusInner, metrics};
use concurrency::{ctx, metrics::LatencyHistogramExt as _};
use network::io::{ConsensusInputMessage, Target};
use roles::validator;
use tracing::instrument;

/// Errors that can occur when processing a "replica commit" message.
#[derive(Debug, thiserror::Error)]
pub(crate) enum Error {
/// Unexpected proposal.
#[error("unexpected proposal")]
UnexpectedProposal,
/// Past view or phase.
#[error("past view/phase (current view: {current_view:?}, current phase: {current_phase:?})")]
Old {
/// Current view.
current_view: validator::ViewNumber,
/// Current phase.
current_phase: validator::Phase,
},
/// The processing node is not a lead for this message's view.
#[error("we are not a leader for this message's view")]
NotLeaderInView,
/// Duplicate message from a replica.
#[error("duplicate message from a replica (existing message: {existing_message:?}")]
DuplicateMessage {
/// Existing message from the same replica.
existing_message: validator::ReplicaCommit,
},
/// Number of received messages is below threshold.
#[error(
"number of received messages is below threshold. waiting for more (received: {num_messages:?}, \
threshold: {threshold:?}"
)]
NumReceivedBelowThreshold {
/// Number of received messages.
num_messages: usize,
/// Threshold for message count.
threshold: usize,
},
/// Invalid message signature.
#[error("invalid signature: {0:#}")]
InvalidSignature(#[source] crypto::bls12_381::Error),
}

impl StateMachine {
#[instrument(level = "trace", ret)]
pub(crate) fn process_replica_commit(
Expand All @@ -21,15 +60,15 @@ impl StateMachine {

// If the message is from the "past", we discard it.
if (message.view, validator::Phase::Commit) < (self.view, self.phase) {
return Err(Error::ReplicaCommitOld {
return Err(Error::Old {
current_view: self.view,
current_phase: self.phase,
});
}

// If the message is for a view when we are not a leader, we discard it.
if consensus.view_leader(message.view) != consensus.secret_key.public() {
return Err(Error::ReplicaCommitWhenNotLeaderInView);
return Err(Error::NotLeaderInView);
}

// If we already have a message from the same validator and for the same view, we discard it.
Expand All @@ -38,24 +77,22 @@ impl StateMachine {
.get(&message.view)
.and_then(|x| x.get(author))
{
return Err(Error::ReplicaCommitExists {
existing_message: format!("{:?}", existing_message),
return Err(Error::DuplicateMessage {
existing_message: existing_message.msg,
});
}

// ----------- Checking the signed part of the message --------------

// Check the signature on the message.
signed_message
.verify()
.map_err(Error::ReplicaCommitInvalidSignature)?;
signed_message.verify().map_err(Error::InvalidSignature)?;

// ----------- Checking the contents of the message --------------

// We only accept replica commit messages for proposals that we have cached. That's so
// we don't need to store replica commit messages for different proposals.
if self.block_proposal_cache != Some(message) {
return Err(Error::ReplicaCommitMissingProposal);
if self.block_proposal_cache != Some(message.proposal) {
return Err(Error::UnexpectedProposal);
}

// ----------- All checks finished. Now we process the message. --------------
Expand All @@ -70,7 +107,7 @@ impl StateMachine {
let num_messages = self.commit_message_cache.get(&message.view).unwrap().len();

if num_messages < consensus.threshold() {
return Err(Error::ReplicaCommitNumReceivedBelowThreshold {
return Err(Error::NumReceivedBelowThreshold {
num_messages,
threshold: consensus.threshold(),
});
Expand Down Expand Up @@ -110,7 +147,10 @@ impl StateMachine {
message: consensus
.secret_key
.sign_msg(validator::ConsensusMsg::LeaderCommit(
validator::LeaderCommit { justification },
validator::LeaderCommit {
protocol_version: validator::CURRENT_VERSION,
justification,
},
)),
recipient: Target::Broadcast,
};
Expand Down
Loading

0 comments on commit 7071f2e

Please sign in to comment.