From ff6b10c4a994cf70297a034202bcb55152748cba Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Wed, 24 Jul 2024 17:25:04 +0100 Subject: [PATCH] feat: Update to consensus 0.1.0-rc.4 (BFT-486) (#2475) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Updates the `era-consensus` dependency to 0.1.0-rc.4, which brings the following changes: * `BatchStoreState::last` no longer contains the entire `SyncBatch`, just the number of the latest batch, which should reduce the unintended gossip data volume * Makes new batch gossip related metrics available to Prometheus (BFT-486) ## Why ❔ Adding attesters to the genesis is a breaking change, so we would like to cut a new release to external node operators. These changes make the gossip less resource intensive as well as make it more observable. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Co-authored-by: Bruno França --- Cargo.lock | 40 +++++++++---------- Cargo.toml | 22 +++++----- core/node/consensus/src/storage/connection.rs | 14 ------- core/node/consensus/src/storage/store.rs | 40 ++++++++++--------- core/node/consensus/src/tests.rs | 14 +++++-- prover/Cargo.lock | 28 ++++++------- zk_toolbox/Cargo.lock | 16 ++++---- 7 files changed, 85 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9840be8502e..3b43a01fc5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8110,9 +8110,9 @@ dependencies = [ [[package]] name = "zksync_concurrency" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1af85d9a31c534a29877c88474cf5f1c46ad25f7c48efff61ea40f4aa83c5459" +checksum = "50302b77192891256d180ff2551dc0c3bc4144958b49e9a16c50a0dc218958ba" dependencies = [ "anyhow", "once_cell", @@ -8144,9 +8144,9 @@ dependencies = [ [[package]] name = "zksync_consensus_bft" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddbee11ed4fafe461092fb73d3879325f08243fe50351baab6b5f593fee88f06" +checksum = "2325c7486a8280db1c26c10020350bead6eecb3de03f8bbfd878060f000cdce7" dependencies = [ "anyhow", "async-trait", @@ -8166,9 +8166,9 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b3867f9b4778616d87f157d1049e47290a3bca5ec9db208164f8902524ae92c" +checksum = "f5cb8ed0d59593f6147085b77142628e459ba673aa4d48fce064d5b96e31eb36" dependencies = [ "anyhow", "blst", @@ -8190,9 +8190,9 @@ dependencies = [ [[package]] name = "zksync_consensus_executor" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7d50aa34616a9c1f4cdc7c47aae2df61474e137e41125c9d5fbfc1e5a1faaa" +checksum = "247b70ec255781b3b740acb744236e771a192922ffbaa52c462b84c4ea67609f" dependencies = [ "anyhow", "rand 0.8.5", @@ -8210,9 +8210,9 @@ dependencies = [ [[package]] name = "zksync_consensus_network" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced7deafe460c74321edf79486980f9f75da121a1e52e5805392946dabafdf82" +checksum = "f10626b79885a9b096cd19ee83d85ef9b0554f061a9db6946f2b7c9d1b2f49ea" dependencies = [ "anyhow", "async-trait", @@ -8245,9 +8245,9 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55dacdf1bad5d9efe7dd9db200421afa0c3bf5cfc7fdce4a64720a5dd0685807" +checksum = "1ffe3e47d99eb943eb94f2f5c9d929b1192bf3e8d1434de0fa6f0090f9c1197e" dependencies = [ "anyhow", "bit-vec", @@ -8267,9 +8267,9 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f796020459775391094b9dcd133f01b5127059fe167cf412b2d1aed23fe0e52f" +checksum = "b9ae9a0ec64ce9c0af346e50cc87dc257c30259101ce9675b408cb883e096087" dependencies = [ "anyhow", "async-trait", @@ -8287,9 +8287,9 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "587de103f745d0b88b49a9fb98cb002c4b7ce6ad042e17845091dce67b8aa984" +checksum = "24dc6135abeefa80f617eb2903fe43d137d362bf673f0651b4894b17069d1fb1" dependencies = [ "anyhow", "rand 0.8.5", @@ -9225,9 +9225,9 @@ dependencies = [ [[package]] name = "zksync_protobuf" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86baa84d8bbbbeea269c0f99aca88364e4fd2a08e6ae7051ff87317132b4ef9" +checksum = "b1e7c7820f290db565a1b4ff73aa1175cd7d31498fca8d859eb5aceebd33468c" dependencies = [ "anyhow", "bit-vec", @@ -9246,9 +9246,9 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f221ce83f4622c3d8732d09f4461d116d7b10f1cc9d1d1cd014c1fa836c168e6" +checksum = "f6cafeec1150ae91f1a37c8f0dce6b71b92b93e0c4153d32b4c37e2fd71bce2f" dependencies = [ "anyhow", "heck 0.5.0", diff --git a/Cargo.toml b/Cargo.toml index b0f98f33e3d..7b6ac30be8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ members = [ "core/tests/vm-benchmark/harness", # Parts of prover workspace that are needed for Core workspace - "prover/crates/lib/prover_dal" + "prover/crates/lib/prover_dal", ] resolver = "2" @@ -209,16 +209,16 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141.0" } zk_evm_1_5_0 = { package = "zk_evm", version = "0.150.0" } # Consensus dependencies. -zksync_concurrency = "=0.1.0-rc.2" -zksync_consensus_bft = "=0.1.0-rc.2" -zksync_consensus_crypto = "=0.1.0-rc.2" -zksync_consensus_executor = "=0.1.0-rc.2" -zksync_consensus_network = "=0.1.0-rc.2" -zksync_consensus_roles = "=0.1.0-rc.2" -zksync_consensus_storage = "=0.1.0-rc.2" -zksync_consensus_utils = "=0.1.0-rc.2" -zksync_protobuf = "=0.1.0-rc.2" -zksync_protobuf_build = "=0.1.0-rc.2" +zksync_concurrency = "=0.1.0-rc.4" +zksync_consensus_bft = "=0.1.0-rc.4" +zksync_consensus_crypto = "=0.1.0-rc.4" +zksync_consensus_executor = "=0.1.0-rc.4" +zksync_consensus_network = "=0.1.0-rc.4" +zksync_consensus_roles = "=0.1.0-rc.4" +zksync_consensus_storage = "=0.1.0-rc.4" +zksync_consensus_utils = "=0.1.0-rc.4" +zksync_protobuf = "=0.1.0-rc.4" +zksync_protobuf_build = "=0.1.0-rc.4" # "Local" dependencies zksync_multivm = { version = "0.1.0", path = "core/lib/multivm" } diff --git a/core/node/consensus/src/storage/connection.rs b/core/node/consensus/src/storage/connection.rs index 5d76934d700..7bff2c4bcf0 100644 --- a/core/node/consensus/src/storage/connection.rs +++ b/core/node/consensus/src/storage/connection.rs @@ -411,20 +411,6 @@ impl<'a> Connection<'a> { .await .context("get_last_batch_number()")?; - let last = if let Some(last) = last { - // For now it would be unexpected if we couldn't retrieve the payloads - // for the `last` batch number, as an L1 batch is only created if we - // have all the L2 miniblocks for it. - Some( - self.get_batch(ctx, last) - .await - .context("get_batch()")? - .context("last batch not available")?, - ) - } else { - None - }; - Ok(BatchStoreState { first: first .map(|n| attester::BatchNumber(n.0 as u64)) diff --git a/core/node/consensus/src/storage/store.rs b/core/node/consensus/src/storage/store.rs index ad8f4948831..b1dc3e0b60c 100644 --- a/core/node/consensus/src/storage/store.rs +++ b/core/node/consensus/src/storage/store.rs @@ -446,10 +446,7 @@ impl storage::PersistentBatchStore for Store { self.batches_persisted.clone() } - /// Get the earliest L1 batch number which has to be (re)signed by a node. - /// - /// Ideally we would make this decision by looking up the last batch submitted to L1, - /// and so it might require a quorum of attesters to sign a certificate for it. + /// Get the earliest L1 batch number which has to be signed by attesters. async fn earliest_batch_number_to_sign( &self, ctx: &ctx::Ctx, @@ -457,31 +454,36 @@ impl storage::PersistentBatchStore for Store { // This is the rough roadmap of how this logic will evolve: // 1. Make best effort at gossiping and collecting votes; the `BatchVotes` in consensus only considers the last vote per attesters. // Still, we can re-sign more than the last batch, anticipating step 2. - // 2. Change `BatchVotes` to handle multiple pending batch numbers, anticipating that batch intervals might decrease dramatically. - // 3. Ask the Main Node what is the earliest batch number that it still expects votes for (ie. what is the last submission + 1). - // 4. Look at L1 to figure out what is the last submssion, and sign after that. + // 2. Ask the Main Node what is the earliest batch number that it still expects votes for (ie. what is the last submission + 1). + // 3. Change `BatchVotes` to handle multiple pending batch numbers, anticipating that batch intervals might decrease dramatically. + // 4. Once QC is required to submit to L1, Look at L1 to figure out what is the last submission, and sign after that. - // Originally this method returned all unsigned batch numbers by doing a DAL query, but we decided it shoudl be okay and cheap + // Originally this method returned all unsigned batch numbers by doing a DAL query, but we decided it should be okay and cheap // to resend signatures for already signed batches, and we don't have to worry about skipping them. Because of that, we also // didn't think it makes sense to query the database for the earliest unsigned batch *after* the submission, because we might // as well just re-sign everything. Until we have a way to argue about the "last submission" we just re-sign the last 10 to // try to produce as many QCs as the voting register allows, within reason. - let Some(last_batch_number) = self.last_batch(ctx).await? else { - return Ok(None); - }; - Ok(Some(attester::BatchNumber( - last_batch_number.0.saturating_sub(10), - ))) - } + // The latest decision is not to store batches with gaps between in the database *of the main node*. + // Once we have an API to serve to external nodes the earliest number the main node wants them to sign, + // we can get rid of this method: on the main node we can sign from what `last_batch_qc` returns, and + // while external nodes we can go from whatever the API returned. - /// Get the highest L1 batch number from storage. - async fn last_batch(&self, ctx: &ctx::Ctx) -> ctx::Result> { - self.conn(ctx) + const NUM_BATCHES_TO_SIGN: u64 = 10; + + let Some(last_batch_number) = self + .conn(ctx) .await? .get_last_batch_number(ctx) .await - .wrap("get_last_batch_number") + .wrap("get_last_batch_number")? + else { + return Ok(None); + }; + + Ok(Some(attester::BatchNumber( + last_batch_number.0.saturating_sub(NUM_BATCHES_TO_SIGN), + ))) } /// Get the L1 batch QC from storage with the highest number. diff --git a/core/node/consensus/src/tests.rs b/core/node/consensus/src/tests.rs index 5506ec6ee8f..7d269376b65 100644 --- a/core/node/consensus/src/tests.rs +++ b/core/node/consensus/src/tests.rs @@ -120,17 +120,25 @@ async fn test_connection_get_batch(from_snapshot: bool, version: ProtocolVersion let batches = conn.batches_range(ctx).await?; let last = batches.last.expect("last is set"); let (min, max) = conn - .get_l2_block_range_of_l1_batch(ctx, last.number) + .get_l2_block_range_of_l1_batch(ctx, last) .await? .unwrap(); + let last_batch = conn + .get_batch(ctx, last) + .await? + .expect("last batch can be retrieved"); + assert_eq!( - last.payloads.len(), + last_batch.payloads.len(), (max.0 - min.0) as usize, "all block payloads present" ); - let first_payload = last.payloads.first().expect("last batch has payloads"); + let first_payload = last_batch + .payloads + .first() + .expect("last batch has payloads"); let want_payload = conn.payload(ctx, min).await?.expect("payload is in the DB"); let want_payload = want_payload.encode(); diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 376b464babe..6be3ab0db10 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -7728,9 +7728,9 @@ dependencies = [ [[package]] name = "zksync_concurrency" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1af85d9a31c534a29877c88474cf5f1c46ad25f7c48efff61ea40f4aa83c5459" +checksum = "50302b77192891256d180ff2551dc0c3bc4144958b49e9a16c50a0dc218958ba" dependencies = [ "anyhow", "once_cell", @@ -7762,9 +7762,9 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b3867f9b4778616d87f157d1049e47290a3bca5ec9db208164f8902524ae92c" +checksum = "f5cb8ed0d59593f6147085b77142628e459ba673aa4d48fce064d5b96e31eb36" dependencies = [ "anyhow", "blst", @@ -7786,9 +7786,9 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55dacdf1bad5d9efe7dd9db200421afa0c3bf5cfc7fdce4a64720a5dd0685807" +checksum = "1ffe3e47d99eb943eb94f2f5c9d929b1192bf3e8d1434de0fa6f0090f9c1197e" dependencies = [ "anyhow", "bit-vec", @@ -7808,9 +7808,9 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f796020459775391094b9dcd133f01b5127059fe167cf412b2d1aed23fe0e52f" +checksum = "b9ae9a0ec64ce9c0af346e50cc87dc257c30259101ce9675b408cb883e096087" dependencies = [ "anyhow", "async-trait", @@ -7828,9 +7828,9 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "587de103f745d0b88b49a9fb98cb002c4b7ce6ad042e17845091dce67b8aa984" +checksum = "24dc6135abeefa80f617eb2903fe43d137d362bf673f0651b4894b17069d1fb1" dependencies = [ "anyhow", "rand 0.8.5", @@ -8137,9 +8137,9 @@ dependencies = [ [[package]] name = "zksync_protobuf" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86baa84d8bbbbeea269c0f99aca88364e4fd2a08e6ae7051ff87317132b4ef9" +checksum = "b1e7c7820f290db565a1b4ff73aa1175cd7d31498fca8d859eb5aceebd33468c" dependencies = [ "anyhow", "bit-vec", @@ -8158,9 +8158,9 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f221ce83f4622c3d8732d09f4461d116d7b10f1cc9d1d1cd014c1fa836c168e6" +checksum = "f6cafeec1150ae91f1a37c8f0dce6b71b92b93e0c4153d32b4c37e2fd71bce2f" dependencies = [ "anyhow", "heck 0.5.0", diff --git a/zk_toolbox/Cargo.lock b/zk_toolbox/Cargo.lock index 769b2af8e44..9d738fdf723 100644 --- a/zk_toolbox/Cargo.lock +++ b/zk_toolbox/Cargo.lock @@ -6360,9 +6360,9 @@ dependencies = [ [[package]] name = "zksync_concurrency" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1af85d9a31c534a29877c88474cf5f1c46ad25f7c48efff61ea40f4aa83c5459" +checksum = "50302b77192891256d180ff2551dc0c3bc4144958b49e9a16c50a0dc218958ba" dependencies = [ "anyhow", "once_cell", @@ -6394,9 +6394,9 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "587de103f745d0b88b49a9fb98cb002c4b7ce6ad042e17845091dce67b8aa984" +checksum = "24dc6135abeefa80f617eb2903fe43d137d362bf673f0651b4894b17069d1fb1" dependencies = [ "anyhow", "rand", @@ -6445,9 +6445,9 @@ dependencies = [ [[package]] name = "zksync_protobuf" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86baa84d8bbbbeea269c0f99aca88364e4fd2a08e6ae7051ff87317132b4ef9" +checksum = "b1e7c7820f290db565a1b4ff73aa1175cd7d31498fca8d859eb5aceebd33468c" dependencies = [ "anyhow", "bit-vec", @@ -6466,9 +6466,9 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" -version = "0.1.0-rc.2" +version = "0.1.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f221ce83f4622c3d8732d09f4461d116d7b10f1cc9d1d1cd014c1fa836c168e6" +checksum = "f6cafeec1150ae91f1a37c8f0dce6b71b92b93e0c4153d32b4c37e2fd71bce2f" dependencies = [ "anyhow", "heck 0.5.0",