Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast validators signature and collect QC (BFT-414) #76

Merged
merged 88 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
23ef076
Create new message type for validators to broadcast signature
IAvecilla Mar 14, 2024
93732c4
Add new message to send to the gossip network
IAvecilla Mar 14, 2024
cbc7790
Add protobuf related functions for new message
IAvecilla Mar 14, 2024
a942623
Update batch signature message
IAvecilla Mar 19, 2024
73122a5
Add new rpc clients for validators to receive signatures
IAvecilla Mar 20, 2024
1538d0a
Add new input message for network actor
IAvecilla Mar 20, 2024
11680fd
Update L1Batch message variant
IAvecilla Apr 9, 2024
94f5b67
Add verification for L1 Batcj signatures
IAvecilla Apr 9, 2024
a532bbc
Merge branch 'main' into signature_broadcast
IAvecilla Apr 9, 2024
cec46c1
Update network struct for l1 batches rpc
IAvecilla Apr 9, 2024
5c2639b
introduced msg pool
pompon0 Apr 10, 2024
5926692
retransmission
pompon0 Apr 11, 2024
36be3da
typo
pompon0 Apr 11, 2024
1b28fd7
retransmission test
pompon0 Apr 11, 2024
c8d06ef
added tests
pompon0 Apr 11, 2024
96be90b
removed limiting from sync_blocks
pompon0 Apr 12, 2024
16693df
cargo fmt
pompon0 Apr 12, 2024
c9935c0
cargo fmt
pompon0 Apr 12, 2024
c670006
Merge branch 'main' into signature_broadcast
IAvecilla Apr 15, 2024
96a50de
Fix clippy lints
IAvecilla Apr 15, 2024
1dcda70
Added support for persisting blocks in parallel (#98)
pompon0 Apr 17, 2024
fb64951
Merge branch 'main' into signature_broadcast
IAvecilla Apr 18, 2024
d7069f7
New attester role for full nodes (#93)
IAvecilla Apr 19, 2024
8d76509
Rewritten sync_blocks actor to maximize utilization. (#101)
pompon0 Apr 25, 2024
26488ec
Weighted attesters (#102)
IAvecilla Apr 25, 2024
f729182
Merge branch 'main' into signature_broadcast
IAvecilla Apr 25, 2024
32fc525
Merge branch 'version0' into signature_broadcast
IAvecilla Apr 25, 2024
4d2675c
Merge branch 'main' into signature_broadcast
IAvecilla Apr 26, 2024
4e32fc0
l1 batch signature watcher for nodes in the gossip net
IAvecilla Apr 26, 2024
7c1ab8a
New push signature request for full nodes in the gossip network
IAvecilla Apr 30, 2024
dd912d1
Update gossip proto file
IAvecilla Apr 30, 2024
182adca
Add push signature watcher to the runner of the gossip network
IAvecilla Apr 30, 2024
d6a5f80
Fix lints
IAvecilla Apr 30, 2024
1359e54
Add attester key to the config
IAvecilla Apr 30, 2024
1e4e720
Identify node in gossip network adding the attester key
IAvecilla Apr 30, 2024
5f5cee1
Update watcher and signature broadcasting tasks
IAvecilla May 3, 2024
e9ad0fa
Add tests and update test setup to get batches
IAvecilla May 3, 2024
b53ec80
Merge branch 'main' into signature_broadcast
IAvecilla May 3, 2024
8365c9f
Fix genesis hash test
IAvecilla May 3, 2024
05f80e2
Fix encoding tests and hash back to previous version
IAvecilla May 6, 2024
df7b777
Fix deny
IAvecilla May 6, 2024
e77db65
Add test disclaimer
IAvecilla May 6, 2024
e86aa92
Update qc construction implementation
IAvecilla May 6, 2024
9511247
Delete committee prefix for validators and attesters in genesis
IAvecilla May 7, 2024
4f548d7
Fix some crate imports
IAvecilla May 7, 2024
5cf4fae
Update limit rate for rpc requests with batch signatures
IAvecilla May 7, 2024
03780cb
Update name for signed messages in proto file
IAvecilla May 7, 2024
5392a1c
Update attester field in genesis for proto struct
IAvecilla May 7, 2024
e0f16de
Leave TODO comment for hash of the L1 Batch
IAvecilla May 7, 2024
073c22d
Update proto genesis struct
IAvecilla May 7, 2024
93b59be
Delete unused code related to attesters an l1 batches
IAvecilla May 7, 2024
a9b5a5a
Use qualified names for attester imports
IAvecilla May 7, 2024
5c0e7b7
Renamed most of batch related structs for consistency
IAvecilla May 7, 2024
0271e43
Fix some function names
IAvecilla May 7, 2024
ecb3c99
Implement hash for every curve signature and derive it for each role
IAvecilla May 8, 2024
2201c54
Fix incorrect docs for attesters
IAvecilla May 8, 2024
99c9302
Update encoding tests for secret keys
IAvecilla May 8, 2024
e09b6f6
Make batch qc adding function return proper errors
IAvecilla May 8, 2024
76a0a9b
Remove timestamp for batch message
IAvecilla May 8, 2024
d4acad5
Update rpc method name for push batch votes
IAvecilla May 8, 2024
b50fb48
Calculate correctly the expected weight for tests
IAvecilla May 8, 2024
0aa2131
Fix format and clippy lints
IAvecilla May 8, 2024
8168af7
Add trait for the state keeper
IAvecilla May 10, 2024
f380e74
Use calculated QC by the node instead of taking it from signers
IAvecilla May 10, 2024
c9f6152
Add extra comments on QC updater
IAvecilla May 10, 2024
eabc7d7
Panic if overflow happens for batch number
IAvecilla May 13, 2024
e163378
Use validator function for max faulty weight
IAvecilla May 13, 2024
246d834
Use batch votes instead of batch signatures
IAvecilla May 13, 2024
2d331ef
Update some names referring to signatures changing it to votes
IAvecilla May 13, 2024
7eee7dc
Move trait to persist batches to the storage workspace
IAvecilla May 13, 2024
fab01d5
Implement deref for committees
IAvecilla May 13, 2024
c6fe4db
Use map instead of and_then
IAvecilla May 13, 2024
3cec7be
Fix clippy
IAvecilla May 13, 2024
b6721a8
Merge branch 'main' into signature_broadcast
IAvecilla May 14, 2024
55feb75
Fix some unused imports
IAvecilla May 14, 2024
70d8c91
Make attesters field in genesis optional
IAvecilla May 14, 2024
13b63d9
Optional build and read protobuff for attester committee
IAvecilla May 15, 2024
d521f10
Fix clippy lint
IAvecilla May 15, 2024
520e412
Delete attester key from the config
IAvecilla May 15, 2024
ef5c654
Generate valid genesis to verify in test
IAvecilla May 16, 2024
034f196
Fix clippy lints with latest rust version
IAvecilla May 16, 2024
77e45d6
Fix genesis raw encoding for empty attesters
IAvecilla May 16, 2024
834f0fb
Fix latest comments
IAvecilla May 16, 2024
5f35266
Get attester at the beginning of the tests
IAvecilla May 16, 2024
d2c8233
Fix some last comments
IAvecilla May 17, 2024
672046f
Fix CI protobuff job
IAvecilla May 17, 2024
d84421c
Fix last comment in gossip runner
IAvecilla May 20, 2024
06e1350
Merge branch 'main' into signature_broadcast
IAvecilla May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/protobuf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: protobuf_compatibility

on:
pull_request:
branches: [ "*" ]
branches: ["*"]
push:
# protobuf compatibility is a transitive property,
# but it requires all the transitions to be checked.
Expand All @@ -11,7 +11,7 @@ on:
# (unless we improve our github setup).
# Therefore on post-merge we will execute the
# compatibility check as well (TODO: alerting).
branches: [ "main" ]
branches: ["main"]

permissions:
id-token: write
Expand All @@ -33,17 +33,16 @@ jobs:
compatibility:
runs-on: [ubuntu-22.04-github-hosted-16core]
steps:
- uses: mozilla-actions/[email protected]
- uses: mozilla-actions/[email protected]

# before
- uses: actions/checkout@v4
with:
ref: ${{ env.BASE }}
path: before
fetch-depth: 0 # fetches all branches and tags, which is needed to compute the LCA.
- name: checkout LCA
run:
git checkout $(git merge-base $BASE $HEAD)
run: git checkout $(git merge-base $BASE $HEAD)
working-directory: ./before
- name: compile before
run: cargo build --all-targets
Expand All @@ -53,7 +52,7 @@ jobs:
perl -ne 'print "$1\n" if /PROTOBUF_DESCRIPTOR="(.*)"/'
`find ./before/node/target/debug/build/*/output`
| xargs cat > ./before.binpb

# after
- uses: actions/checkout@v4
with:
Expand All @@ -67,7 +66,7 @@ jobs:
perl -ne 'print "$1\n" if /PROTOBUF_DESCRIPTOR="(.*)"/'
`find ./after/node/target/debug/build/*/output`
| xargs cat > ./after.binpb

# compare
- uses: bufbuild/buf-setup-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
"libs/protobuf_build",
"libs/roles",
"libs/storage",
"libs/utils",
"libs/utils",
"tests",
"tools",
]
Expand Down Expand Up @@ -55,7 +55,7 @@ ff_ce = "0.14.3"
heck = "0.5.0"
hex = "0.4.3"
im = "15.1.0"
jsonrpsee = { version = "0.21.0", features = ["server", "http-client"] }
jsonrpsee = { version = "0.21.0", features = ["server", "http-client"] }
k8s-openapi = { version = "0.21.0", features = ["latest"] }
kube = { version = "0.88.1", features = ["runtime", "derive"] }
num-bigint = "0.4.4"
Expand Down
6 changes: 3 additions & 3 deletions node/actors/bft/src/leader/replica_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl StateMachine {
let author = &signed_message.key;

// Check that the message signer is in the validator committee.
if !self.config.genesis().committee.contains(author) {
if !self.config.genesis().validators.contains(author) {
return Err(Error::NonValidatorSigner {
signer: author.clone(),
});
Expand Down Expand Up @@ -103,7 +103,7 @@ impl StateMachine {
.expect("Could not add message to CommitQC");

// Calculate the CommitQC signers weight.
let weight = self.config.genesis().committee.weight(&commit_qc.signers);
let weight = self.config.genesis().validators.weight(&commit_qc.signers);

// Update commit message current view number for author
self.replica_commit_views
Expand All @@ -118,7 +118,7 @@ impl StateMachine {
.retain(|view_number, _| active_views.contains(view_number));

// Now we check if we have enough weight to continue.
if weight < self.config.genesis().committee.threshold() {
if weight < self.config.genesis().validators.threshold() {
return Ok(());
};

Expand Down
6 changes: 3 additions & 3 deletions node/actors/bft/src/leader/replica_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl StateMachine {
let author = &signed_message.key;

// Check that the message signer is in the validator set.
if !self.config.genesis().committee.contains(author) {
if !self.config.genesis().validators.contains(author) {
return Err(Error::NonValidatorSigner {
signer: author.clone(),
});
Expand Down Expand Up @@ -114,7 +114,7 @@ impl StateMachine {
.expect("Could not add message to PrepareQC");

// Calculate the PrepareQC signers weight.
let weight = prepare_qc.weight(&self.config.genesis().committee);
let weight = prepare_qc.weight(&self.config.genesis().validators);

// Update prepare message current view number for author
self.replica_prepare_views
Expand All @@ -129,7 +129,7 @@ impl StateMachine {
.retain(|view_number, _| active_views.contains(view_number));

// Now we check if we have enough weight to continue.
if weight < self.config.genesis().committee.threshold() {
if weight < self.config.genesis().validators.threshold() {
return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion node/actors/bft/src/leader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async fn replica_prepare_different_messages() {

let mut replica_commit_result = None;
// The rest of the validators until threshold sign other_replica_prepare
for i in validators / 2..util.genesis().committee.threshold() as usize {
for i in validators / 2..util.genesis().validators.threshold() as usize {
replica_commit_result = util
.process_replica_prepare(ctx, util.keys[i].sign_msg(other_replica_prepare.clone()))
.await
Expand Down
14 changes: 7 additions & 7 deletions node/actors/bft/src/testonly/ut_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl UTHarness {
let (send, recv) = ctx::channel::unbounded();

let cfg = Arc::new(Config {
secret_key: setup.keys[0].clone(),
secret_key: setup.validator_keys[0].clone(),
block_store: block_store.clone(),
replica_store: Box::new(in_memory::ReplicaStore::default()),
payload_manager,
Expand All @@ -75,7 +75,7 @@ impl UTHarness {
leader,
replica,
pipe: recv,
keys: setup.keys.clone(),
keys: setup.validator_keys.clone(),
leader_send,
};
let _: Signed<ReplicaPrepare> = this.try_recv().unwrap();
Expand All @@ -86,7 +86,7 @@ impl UTHarness {
pub(crate) async fn new_many(ctx: &ctx::Ctx) -> (UTHarness, BlockStoreRunner) {
let num_validators = 6;
let (util, runner) = UTHarness::new(ctx, num_validators).await;
assert!(util.genesis().committee.max_faulty_weight() > 0);
assert!(util.genesis().validators.max_faulty_weight() > 0);
(util, runner)
}

Expand Down Expand Up @@ -223,8 +223,8 @@ impl UTHarness {
for (i, msg) in msgs.into_iter().enumerate() {
let res = self.process_replica_prepare(ctx, msg).await;
match (
(i + 1) as u64 * self.genesis().committee.iter().next().unwrap().weight
< self.genesis().committee.threshold(),
(i + 1) as u64 * self.genesis().validators.iter().next().unwrap().weight
< self.genesis().validators.threshold(),
first_match,
) {
(true, _) => assert!(res.unwrap().is_none()),
Expand Down Expand Up @@ -258,8 +258,8 @@ impl UTHarness {
.leader
.process_replica_commit(ctx, key.sign_msg(msg.clone()));
match (
(i + 1) as u64 * self.genesis().committee.iter().next().unwrap().weight
< self.genesis().committee.threshold(),
(i + 1) as u64 * self.genesis().validators.iter().next().unwrap().weight
< self.genesis().validators.threshold(),
first_match,
) {
(true, _) => res.unwrap(),
Expand Down
13 changes: 2 additions & 11 deletions node/actors/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::io::Dispatcher;
use anyhow::Context as _;
use std::{
collections::{HashMap, HashSet},
fmt,
sync::Arc,
};
use zksync_concurrency::{ctx, limiter, net, scope, time};
Expand All @@ -19,6 +18,7 @@ mod io;
mod tests;

/// Validator-related part of [`Executor`].
#[derive(Debug)]
pub struct Validator {
/// Consensus network configuration.
pub key: validator::SecretKey,
Expand All @@ -28,14 +28,6 @@ pub struct Validator {
pub payload_manager: Box<dyn bft::PayloadManager>,
}

impl fmt::Debug for Validator {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("ValidatorExecutor")
.field("key", &self.key)
.finish()
}
}

/// Config of the node executor.
#[derive(Clone, Debug)]
pub struct Config {
Expand All @@ -47,7 +39,6 @@ pub struct Config {
pub public_addr: net::Host,
/// Maximal size of the block payload.
pub max_payload_size: usize,

/// Key of this node. It uniquely identifies the node.
/// It should match the secret key provided in the `node_key` file.
pub node_key: node::SecretKey,
Expand Down Expand Up @@ -129,7 +120,7 @@ impl Executor {
if !self
.block_store
.genesis()
.committee
.validators
.contains(&validator.key.public())
{
tracing::warn!(
Expand Down
6 changes: 6 additions & 0 deletions node/actors/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct RpcConfig {
pub get_block_timeout: Option<time::Duration>,
/// Max rate of sending/receiving consensus messages.
pub consensus_rate: limiter::Rate,
/// Max rate of sending/receiving l1 batch votes messages.
pub push_batch_votes_rate: limiter::Rate,
}

impl Default for RpcConfig {
Expand All @@ -42,6 +44,10 @@ impl Default for RpcConfig {
burst: 10,
refresh: time::Duration::ZERO,
},
push_batch_votes_rate: limiter::Rate {
burst: 2,
refresh: time::Duration::milliseconds(500),
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/actors/network/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Network {
/// Constructs a new consensus network state.
pub(crate) fn new(gossip: Arc<gossip::Network>) -> Option<Arc<Self>> {
let key = gossip.cfg.validator_key.clone()?;
let validators: HashSet<_> = gossip.genesis().committee.keys().cloned().collect();
let validators: HashSet<_> = gossip.genesis().validators.keys().cloned().collect();
Some(Arc::new(Self {
key,
inbound: PoolWatch::new(validators.clone(), 0),
Expand Down
20 changes: 11 additions & 9 deletions node/actors/network/src/consensus/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ async fn test_genesis_mismatch() {
.gossip
.validator_addrs
.update(
&setup.genesis.committee,
&[Arc::new(setup.keys[1].sign_msg(validator::NetAddress {
addr: *cfgs[1].server_addr,
version: 0,
timestamp: ctx.now_utc(),
}))],
&setup.genesis.validators,
&[Arc::new(setup.validator_keys[1].sign_msg(
validator::NetAddress {
addr: *cfgs[1].server_addr,
version: 0,
timestamp: ctx.now_utc(),
},
))],
)
.await
.unwrap();
Expand All @@ -185,7 +187,7 @@ async fn test_genesis_mismatch() {
.context("preface::accept()")?;
assert_eq!(endpoint, preface::Endpoint::ConsensusNet);
tracing::info!("Expect the handshake to fail");
let res = handshake::inbound(ctx, &setup.keys[1], rng.gen(), &mut stream).await;
let res = handshake::inbound(ctx, &setup.validator_keys[1], rng.gen(), &mut stream).await;
assert_matches!(res, Err(handshake::Error::GenesisMismatch));

tracing::info!("Try to connect to a node with a mismatching genesis.");
Expand All @@ -195,10 +197,10 @@ async fn test_genesis_mismatch() {
.context("preface::connect")?;
let res = handshake::outbound(
ctx,
&setup.keys[1],
&setup.validator_keys[1],
rng.gen(),
&mut stream,
&setup.keys[0].public(),
&setup.validator_keys[0].public(),
)
.await;
tracing::info!(
Expand Down
Loading
Loading