From 65b304608863011d6d0d0833589bead570fea919 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Wed, 13 Mar 2024 10:51:17 +0100 Subject: [PATCH 01/11] wfaef --- Cargo.lock | 11 --- core/lib/dal/src/consensus_dal.rs | 12 +-- core/lib/zksync_core/src/consensus/fetcher.rs | 10 ++- .../zksync_core/src/consensus/storage/mod.rs | 87 +++++++++++++------ .../src/consensus/storage/testonly.rs | 22 ----- 5 files changed, 68 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26b509410e1..ccc8fe52263 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8003,7 +8003,6 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "once_cell", @@ -8031,7 +8030,6 @@ dependencies = [ [[package]] name = "zksync_consensus_bft" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "async-trait", @@ -8052,7 +8050,6 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "blst", @@ -8070,7 +8067,6 @@ dependencies = [ [[package]] name = "zksync_consensus_executor" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "rand 0.8.5", @@ -8090,7 +8086,6 @@ dependencies = [ [[package]] name = "zksync_consensus_network" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "async-trait", @@ -8115,7 +8110,6 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "bit-vec", @@ -8135,7 +8129,6 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "async-trait", @@ -8153,7 +8146,6 @@ dependencies = [ [[package]] name = "zksync_consensus_sync_blocks" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "thiserror", @@ -8168,7 +8160,6 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "thiserror", "zksync_concurrency", @@ -8563,7 +8554,6 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "bit-vec", @@ -8581,7 +8571,6 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "heck 0.4.1", diff --git a/core/lib/dal/src/consensus_dal.rs b/core/lib/dal/src/consensus_dal.rs index 1988ac0207c..aa769a16758 100644 --- a/core/lib/dal/src/consensus_dal.rs +++ b/core/lib/dal/src/consensus_dal.rs @@ -53,10 +53,6 @@ impl ConsensusDal<'_, '_> { got.fork.number, genesis.fork.number, ); - anyhow::ensure!( - got.fork.first_parent.is_none(), - "fork with first_parent != None not supported", - ); } let genesis = zksync_protobuf::serde::serialize(genesis, serde_json::value::Serializer).unwrap(); @@ -115,7 +111,6 @@ impl ConsensusDal<'_, '_> { fork: validator::Fork { number: old.fork.number.next(), first_block, - first_parent: None, }, }; txn.consensus_dal().try_update_genesis(&new).await?; @@ -244,14 +239,10 @@ impl ConsensusDal<'_, '_> { let header = &cert.message.proposal; let mut txn = self.storage.start_transaction().await?; if let Some(last) = txn.consensus_dal().last_certificate().await? { - let last = &last.message.proposal; anyhow::ensure!( - last.number.next() == header.number, + last.header().number.next() == header.number, "expected certificate for a block after the current head block" ); - anyhow::ensure!(Some(last.hash()) == header.parent, "parent block mismatch"); - } else { - anyhow::ensure!(header.parent.is_none(), "inserting first block with parent"); } let want_payload = txn .consensus_dal() @@ -297,7 +288,6 @@ mod tests { let fork = validator::Fork { number: validator::ForkNumber(n), first_block: rng.gen(), - first_parent: None, }; let setup = validator::testonly::Setup::new_with_fork(rng, 3, fork); conn.consensus_dal() diff --git a/core/lib/zksync_core/src/consensus/fetcher.rs b/core/lib/zksync_core/src/consensus/fetcher.rs index 325118d27ea..c1e6ffff17b 100644 --- a/core/lib/zksync_core/src/consensus/fetcher.rs +++ b/core/lib/zksync_core/src/consensus/fetcher.rs @@ -50,8 +50,7 @@ impl Fetcher { // Fetch blocks before the genesis. self.fetch_blocks(ctx, &mut cursor, Some(genesis.fork.first_block)) - .await?; - + .await?; // Monitor the genesis of the main node. // If it changes, it means that a hard fork occurred and we need to reset the consensus state. s.spawn_bg::<()>(async { @@ -175,6 +174,7 @@ impl Fetcher { end: Option, ) -> ctx::Result<()> { const MAX_CONCURRENT_REQUESTS: usize = 30; + let first = cursor.next(); let mut next = cursor.next(); scope::run!(ctx, |ctx, s| async { let (send, mut recv) = ctx::channel::bounded(MAX_CONCURRENT_REQUESTS); @@ -194,6 +194,10 @@ impl Fetcher { } Ok(()) }) - .await + .await?; + // If fetched anything, wait for the last block to be stored persistently. + if first < cursor.next() { + self.store.wait_for_block(cursor.next().prev().unwrap()).await?; + } } } diff --git a/core/lib/zksync_core/src/consensus/storage/mod.rs b/core/lib/zksync_core/src/consensus/storage/mod.rs index 3892bf4dc38..952abe0c756 100644 --- a/core/lib/zksync_core/src/consensus/storage/mod.rs +++ b/core/lib/zksync_core/src/consensus/storage/mod.rs @@ -197,6 +197,28 @@ impl Store { .await??, )) } + + /// Waits for the `number` miniblock. + pub async fn wait_for_block( + &self, + ctx: &ctx::Ctx, + number: validator::BlockNumber, + ) -> ctx::Result { + const POLL_INTERVAL: time::Duration = time::Duration::milliseconds(50); + loop { + if let Some(payload) = self + .access(ctx) + .await + .wrap("access()")? + .payload(ctx, number) + .await + .wrap("payload()")? + { + return Ok(payload); + } + ctx.sleep(POLL_INTERVAL).await?; + } + } } impl BlockStore { @@ -214,6 +236,7 @@ impl BlockStore { .last_miniblock_number(ctx) .await .wrap("last_miniblock_number()")? + // TODO: snapshot start here. .unwrap_or(validator::BlockNumber(0)); let mut txn = conn .start_transaction(ctx) @@ -259,14 +282,32 @@ impl PersistentBlockStore for BlockStore { .context("genesis is missing")?) } - async fn last(&self, ctx: &ctx::Ctx) -> ctx::Result> { - self.inner - .access(ctx) - .await - .wrap("access()")? - .last_certificate(ctx) - .await - .wrap("last_certificate()") + async fn state(&self, ctx: &ctx::Ctx) -> ctx::Result { + let conn = self.inner.access(ctx).await.wrap("access()")?; + + // Fetch the range of miniblocks in storage. + let first_payload = conn.first_miniblock_number(ctx).await.wrap("first_miniblock_number()")?; + let next_payload = conn.last_miniblock_number(ctx).await.wrap("last_miniblock_number()")?.map_or(first_payload,|last|last.next()); + + // Fetch the range of certificates in storage. + let first = conn.genesis(ctx).await.wrap("genesis()")?.context("genesis missing")?.fork.first_block.max(first_payload); + let last = conn.last_certificate(ctx).await.wrap("last_certificate()")?; + let next = last.map_or(first,|cert|cert.header().number.next()); + + // Check that the first certificate in storage has the expected miniblock number. + if let Some(got) = conn.first_certificate(ctx).await.wrap("first_certificate()")? { + if got != first { + return Err(anyhow::format_err!("inconsistent storage: certificates should start at {first}, while they start at {got}").into()); + } + } + // Check that the node has all the blocks before the next expected certificate, because + // the node needs to know the state of the chain up to block `X` to process block `X+1`. + if let Some(got) = &last { + if next_payload <= next { + return Err(anyhow::format_err!("inconsistent storage: cannot start consensus for miniblock {next}, because earlier blocks are missing").into()); + } + } + Ok(BlockStoreState { first, last }) } async fn block( @@ -386,23 +427,16 @@ impl PayloadManager for Store { ctx: &ctx::Ctx, block_number: validator::BlockNumber, ) -> ctx::Result { - const POLL_INTERVAL: time::Duration = time::Duration::milliseconds(50); - loop { - let mut conn = self.access(ctx).await.wrap("access()")?; - if let Some(payload) = conn.payload(ctx, block_number).await.wrap("payload()")? { - let encoded_payload = payload.encode(); - if encoded_payload.0.len() > 1 << 20 { - tracing::warn!( - "large payload ({}B) with {} transactions", - encoded_payload.0.len(), - payload.transactions.len() - ); - } - return Ok(encoded_payload); - } - drop(conn); - ctx.sleep(POLL_INTERVAL).await?; + let payload = self.wait_for_block(ctx).await?; + let encoded_payload = payload.encode(); + if encoded_payload.0.len() > 1 << 20 { + tracing::warn!( + "large payload ({}B) with {} transactions", + encoded_payload.0.len(), + payload.transactions.len() + ); } + Ok(encoded_payload) } /// Verify that `payload` is a correct proposal for the block `block_number`. @@ -414,11 +448,10 @@ impl PayloadManager for Store { block_number: validator::BlockNumber, payload: &validator::Payload, ) -> ctx::Result<()> { - let want = self.propose(ctx, block_number).await?; - let want = Payload::decode(&want).context("Payload::decode(want)")?; let got = Payload::decode(payload).context("Payload::decode(got)")?; + let want = self.wait_for_block(ctx).await?; if got != want { - return Err(anyhow::anyhow!("unexpected payload: got {got:?} want {want:?}").into()); + return Err(anyhow::format_err!("unexpected payload: got {got:?} want {want:?}").into()); } Ok(()) } diff --git a/core/lib/zksync_core/src/consensus/storage/testonly.rs b/core/lib/zksync_core/src/consensus/storage/testonly.rs index ba97bed8dd4..bee452cccb3 100644 --- a/core/lib/zksync_core/src/consensus/storage/testonly.rs +++ b/core/lib/zksync_core/src/consensus/storage/testonly.rs @@ -9,28 +9,6 @@ use zksync_dal::consensus_dal::Payload; use super::Store; impl Store { - /// Waits for the `number` miniblock. - pub async fn wait_for_block( - &self, - ctx: &ctx::Ctx, - number: validator::BlockNumber, - ) -> ctx::Result { - const POLL_INTERVAL: time::Duration = time::Duration::milliseconds(100); - loop { - if let Some(payload) = self - .access(ctx) - .await - .wrap("access()")? - .payload(ctx, number) - .await - .wrap("payload()")? - { - return Ok(payload); - } - ctx.sleep(POLL_INTERVAL).await?; - } - } - /// Waits for the `number` miniblock to have a certificate. pub async fn wait_for_certificate( &self, From 1c95519e75d63198fff67d77f47cce8115b0eca7 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Thu, 14 Mar 2024 11:22:24 +0100 Subject: [PATCH 02/11] tests pass --- ...17a7ffc993cf436ad3aeeae82ed3e330b07bd.json | 20 ++ ...1b2cc0c39fd0376a88708a5b793e2327c012f.json | 202 ------------------ ...a300bf2720c48886d7ae00a253a4975d7efee.json | 202 ------------------ core/lib/dal/src/consensus_dal.rs | 68 +++++- core/lib/zksync_core/src/consensus/fetcher.rs | 7 +- .../zksync_core/src/consensus/storage/mod.rs | 125 ++++++----- .../src/consensus/storage/testonly.rs | 23 +- core/lib/zksync_core/src/consensus/tests.rs | 41 ++-- prover/Cargo.lock | 23 +- 9 files changed, 196 insertions(+), 515 deletions(-) create mode 100644 core/lib/dal/.sqlx/query-3b013b93ea4a6766162c9f0c60517a7ffc993cf436ad3aeeae82ed3e330b07bd.json delete mode 100644 core/lib/dal/.sqlx/query-55339d6d9ee1205be25c28f0ea01b2cc0c39fd0376a88708a5b793e2327c012f.json delete mode 100644 core/lib/dal/.sqlx/query-b0c89a492fcedc74a52370ad44ca300bf2720c48886d7ae00a253a4975d7efee.json diff --git a/core/lib/dal/.sqlx/query-3b013b93ea4a6766162c9f0c60517a7ffc993cf436ad3aeeae82ed3e330b07bd.json b/core/lib/dal/.sqlx/query-3b013b93ea4a6766162c9f0c60517a7ffc993cf436ad3aeeae82ed3e330b07bd.json new file mode 100644 index 00000000000..6e7bffec485 --- /dev/null +++ b/core/lib/dal/.sqlx/query-3b013b93ea4a6766162c9f0c60517a7ffc993cf436ad3aeeae82ed3e330b07bd.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n certificate\n FROM\n miniblocks_consensus\n ORDER BY\n number ASC\n LIMIT\n 1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "certificate", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false + ] + }, + "hash": "3b013b93ea4a6766162c9f0c60517a7ffc993cf436ad3aeeae82ed3e330b07bd" +} diff --git a/core/lib/dal/.sqlx/query-55339d6d9ee1205be25c28f0ea01b2cc0c39fd0376a88708a5b793e2327c012f.json b/core/lib/dal/.sqlx/query-55339d6d9ee1205be25c28f0ea01b2cc0c39fd0376a88708a5b793e2327c012f.json deleted file mode 100644 index cd9e6b54246..00000000000 --- a/core/lib/dal/.sqlx/query-55339d6d9ee1205be25c28f0ea01b2cc0c39fd0376a88708a5b793e2327c012f.json +++ /dev/null @@ -1,202 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n number,\n timestamp,\n l1_tx_count,\n l2_tx_count,\n bloom,\n priority_ops_onchain_data,\n hash,\n commitment,\n eth_prove_tx_id,\n eth_commit_tx_id,\n eth_execute_tx_id,\n merkle_root_hash,\n l2_to_l1_logs,\n l2_to_l1_messages,\n used_contract_hashes,\n compressed_initial_writes,\n compressed_repeated_writes,\n l2_l1_merkle_root,\n rollup_last_leaf_index,\n zkporter_is_available,\n bootloader_code_hash,\n default_aa_code_hash,\n aux_data_hash,\n pass_through_data_hash,\n meta_parameters_hash,\n protocol_version,\n compressed_state_diffs,\n system_logs,\n events_queue_commitment,\n bootloader_initial_content_commitment,\n pubdata_input\n FROM\n l1_batches\n LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number\n \n WHERE\n eth_commit_tx_id IS NOT NULL\n AND eth_prove_tx_id IS NULL\n \n ORDER BY\n number\n LIMIT\n $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "number", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "timestamp", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "l1_tx_count", - "type_info": "Int4" - }, - { - "ordinal": 3, - "name": "l2_tx_count", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "bloom", - "type_info": "Bytea" - }, - { - "ordinal": 5, - "name": "priority_ops_onchain_data", - "type_info": "ByteaArray" - }, - { - "ordinal": 6, - "name": "hash", - "type_info": "Bytea" - }, - { - "ordinal": 7, - "name": "commitment", - "type_info": "Bytea" - }, - { - "ordinal": 8, - "name": "eth_prove_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 9, - "name": "eth_commit_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 10, - "name": "eth_execute_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 11, - "name": "merkle_root_hash", - "type_info": "Bytea" - }, - { - "ordinal": 12, - "name": "l2_to_l1_logs", - "type_info": "ByteaArray" - }, - { - "ordinal": 13, - "name": "l2_to_l1_messages", - "type_info": "ByteaArray" - }, - { - "ordinal": 14, - "name": "used_contract_hashes", - "type_info": "Jsonb" - }, - { - "ordinal": 15, - "name": "compressed_initial_writes", - "type_info": "Bytea" - }, - { - "ordinal": 16, - "name": "compressed_repeated_writes", - "type_info": "Bytea" - }, - { - "ordinal": 17, - "name": "l2_l1_merkle_root", - "type_info": "Bytea" - }, - { - "ordinal": 18, - "name": "rollup_last_leaf_index", - "type_info": "Int8" - }, - { - "ordinal": 19, - "name": "zkporter_is_available", - "type_info": "Bool" - }, - { - "ordinal": 20, - "name": "bootloader_code_hash", - "type_info": "Bytea" - }, - { - "ordinal": 21, - "name": "default_aa_code_hash", - "type_info": "Bytea" - }, - { - "ordinal": 22, - "name": "aux_data_hash", - "type_info": "Bytea" - }, - { - "ordinal": 23, - "name": "pass_through_data_hash", - "type_info": "Bytea" - }, - { - "ordinal": 24, - "name": "meta_parameters_hash", - "type_info": "Bytea" - }, - { - "ordinal": 25, - "name": "protocol_version", - "type_info": "Int4" - }, - { - "ordinal": 26, - "name": "compressed_state_diffs", - "type_info": "Bytea" - }, - { - "ordinal": 27, - "name": "system_logs", - "type_info": "ByteaArray" - }, - { - "ordinal": 28, - "name": "events_queue_commitment", - "type_info": "Bytea" - }, - { - "ordinal": 29, - "name": "bootloader_initial_content_commitment", - "type_info": "Bytea" - }, - { - "ordinal": 30, - "name": "pubdata_input", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - true, - true, - true, - true, - true, - true, - false, - false, - false, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - false, - true, - true, - true - ] - }, - "hash": "55339d6d9ee1205be25c28f0ea01b2cc0c39fd0376a88708a5b793e2327c012f" -} diff --git a/core/lib/dal/.sqlx/query-b0c89a492fcedc74a52370ad44ca300bf2720c48886d7ae00a253a4975d7efee.json b/core/lib/dal/.sqlx/query-b0c89a492fcedc74a52370ad44ca300bf2720c48886d7ae00a253a4975d7efee.json deleted file mode 100644 index 3557c17a0dc..00000000000 --- a/core/lib/dal/.sqlx/query-b0c89a492fcedc74a52370ad44ca300bf2720c48886d7ae00a253a4975d7efee.json +++ /dev/null @@ -1,202 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n number,\n timestamp,\n l1_tx_count,\n l2_tx_count,\n bloom,\n priority_ops_onchain_data,\n hash,\n commitment,\n eth_prove_tx_id,\n eth_commit_tx_id,\n eth_execute_tx_id,\n merkle_root_hash,\n l2_to_l1_logs,\n l2_to_l1_messages,\n used_contract_hashes,\n compressed_initial_writes,\n compressed_repeated_writes,\n l2_l1_merkle_root,\n rollup_last_leaf_index,\n zkporter_is_available,\n bootloader_code_hash,\n default_aa_code_hash,\n aux_data_hash,\n pass_through_data_hash,\n meta_parameters_hash,\n protocol_version,\n compressed_state_diffs,\n system_logs,\n events_queue_commitment,\n bootloader_initial_content_commitment,\n pubdata_input\n FROM\n l1_batches\n LEFT JOIN commitments ON commitments.l1_batch_number = l1_batches.number\n JOIN eth_txs_history ON eth_commit_tx_id = eth_tx_id\n WHERE\n eth_commit_tx_id IS NOT NULL\n AND eth_prove_tx_id IS NULL\n AND confirmed_at IS NOT NULL\n ORDER BY\n number\n LIMIT\n $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "number", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "timestamp", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "l1_tx_count", - "type_info": "Int4" - }, - { - "ordinal": 3, - "name": "l2_tx_count", - "type_info": "Int4" - }, - { - "ordinal": 4, - "name": "bloom", - "type_info": "Bytea" - }, - { - "ordinal": 5, - "name": "priority_ops_onchain_data", - "type_info": "ByteaArray" - }, - { - "ordinal": 6, - "name": "hash", - "type_info": "Bytea" - }, - { - "ordinal": 7, - "name": "commitment", - "type_info": "Bytea" - }, - { - "ordinal": 8, - "name": "eth_prove_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 9, - "name": "eth_commit_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 10, - "name": "eth_execute_tx_id", - "type_info": "Int4" - }, - { - "ordinal": 11, - "name": "merkle_root_hash", - "type_info": "Bytea" - }, - { - "ordinal": 12, - "name": "l2_to_l1_logs", - "type_info": "ByteaArray" - }, - { - "ordinal": 13, - "name": "l2_to_l1_messages", - "type_info": "ByteaArray" - }, - { - "ordinal": 14, - "name": "used_contract_hashes", - "type_info": "Jsonb" - }, - { - "ordinal": 15, - "name": "compressed_initial_writes", - "type_info": "Bytea" - }, - { - "ordinal": 16, - "name": "compressed_repeated_writes", - "type_info": "Bytea" - }, - { - "ordinal": 17, - "name": "l2_l1_merkle_root", - "type_info": "Bytea" - }, - { - "ordinal": 18, - "name": "rollup_last_leaf_index", - "type_info": "Int8" - }, - { - "ordinal": 19, - "name": "zkporter_is_available", - "type_info": "Bool" - }, - { - "ordinal": 20, - "name": "bootloader_code_hash", - "type_info": "Bytea" - }, - { - "ordinal": 21, - "name": "default_aa_code_hash", - "type_info": "Bytea" - }, - { - "ordinal": 22, - "name": "aux_data_hash", - "type_info": "Bytea" - }, - { - "ordinal": 23, - "name": "pass_through_data_hash", - "type_info": "Bytea" - }, - { - "ordinal": 24, - "name": "meta_parameters_hash", - "type_info": "Bytea" - }, - { - "ordinal": 25, - "name": "protocol_version", - "type_info": "Int4" - }, - { - "ordinal": 26, - "name": "compressed_state_diffs", - "type_info": "Bytea" - }, - { - "ordinal": 27, - "name": "system_logs", - "type_info": "ByteaArray" - }, - { - "ordinal": 28, - "name": "events_queue_commitment", - "type_info": "Bytea" - }, - { - "ordinal": 29, - "name": "bootloader_initial_content_commitment", - "type_info": "Bytea" - }, - { - "ordinal": 30, - "name": "pubdata_input", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - true, - true, - true, - true, - true, - true, - false, - false, - false, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - false, - true, - true, - true - ] - }, - "hash": "b0c89a492fcedc74a52370ad44ca300bf2720c48886d7ae00a253a4975d7efee" -} diff --git a/core/lib/dal/src/consensus_dal.rs b/core/lib/dal/src/consensus_dal.rs index aa769a16758..c141139c9e3 100644 --- a/core/lib/dal/src/consensus_dal.rs +++ b/core/lib/dal/src/consensus_dal.rs @@ -91,21 +91,47 @@ impl ConsensusDal<'_, '_> { Ok(()) } + /// Fetches the range of miniblocks present in storage. + /// If storage was recovered from snapshot, the range doesn't need to start at 0. + pub async fn block_range(&mut self) -> anyhow::Result> { + let mut txn = self + .storage + .start_transaction() + .await + .context("start_transaction")?; + let snapshot = txn + .snapshot_recovery_dal() + .get_applied_snapshot_status() + .await + .context("get_applied_snapshot_status()")?; + let start = validator::BlockNumber(snapshot.map_or(0, |s| s.miniblock_number.0).into()); + let end = txn + .blocks_dal() + .get_sealed_miniblock_number() + .await + .context("get_sealed_miniblock_number")? + .map_or(start, |last| validator::BlockNumber(last.0.into()).next()); + Ok(std::ops::Range { start, end }) + } + /// [Main node only] creates a new consensus fork starting at /// the last sealed miniblock. Resets the state of the consensus /// by calling `try_update_genesis()`. pub async fn fork(&mut self) -> anyhow::Result<()> { - let mut txn = self.storage.start_transaction().await?; - let Some(old) = txn.consensus_dal().genesis().await? else { + let mut txn = self + .storage + .start_transaction() + .await + .context("start_transaction")?; + let Some(old) = txn.consensus_dal().genesis().await.context("genesis()")? else { return Ok(()); }; - let last = txn - .blocks_dal() - .get_sealed_miniblock_number() - .await? - .context("forking without any blocks in storage is not supported yet")?; - let first_block = validator::BlockNumber(last.0.into()); - + let first_block = txn + .consensus_dal() + .block_range() + .await + .context("get_block_range()")? + .end; let new = validator::Genesis { validators: old.validators, fork: validator::Fork { @@ -154,6 +180,30 @@ impl ConsensusDal<'_, '_> { Ok(()) } + /// Fetches the first consensus certificate. + /// It might NOT be the certificate for the first miniblock: + /// see `validator::Genesis.first_block`. + pub async fn first_certificate(&mut self) -> anyhow::Result> { + let Some(row) = sqlx::query!( + r#" + SELECT + certificate + FROM + miniblocks_consensus + ORDER BY + number ASC + LIMIT + 1 + "# + ) + .fetch_optional(self.storage.conn()) + .await? + else { + return Ok(None); + }; + Ok(Some(zksync_protobuf::serde::deserialize(row.certificate)?)) + } + /// Fetches the last consensus certificate. /// Currently certificates are NOT generated synchronously with miniblocks, /// so it might NOT be the certificate for the last miniblock. diff --git a/core/lib/zksync_core/src/consensus/fetcher.rs b/core/lib/zksync_core/src/consensus/fetcher.rs index c1e6ffff17b..dee02faef65 100644 --- a/core/lib/zksync_core/src/consensus/fetcher.rs +++ b/core/lib/zksync_core/src/consensus/fetcher.rs @@ -50,7 +50,7 @@ impl Fetcher { // Fetch blocks before the genesis. self.fetch_blocks(ctx, &mut cursor, Some(genesis.fork.first_block)) - .await?; + .await?; // Monitor the genesis of the main node. // If it changes, it means that a hard fork occurred and we need to reset the consensus state. s.spawn_bg::<()>(async { @@ -197,7 +197,10 @@ impl Fetcher { .await?; // If fetched anything, wait for the last block to be stored persistently. if first < cursor.next() { - self.store.wait_for_block(cursor.next().prev().unwrap()).await?; + self.store + .wait_for_payload(ctx, cursor.next().prev().unwrap()) + .await?; } + Ok(()) } } diff --git a/core/lib/zksync_core/src/consensus/storage/mod.rs b/core/lib/zksync_core/src/consensus/storage/mod.rs index 952abe0c756..e47eed8b738 100644 --- a/core/lib/zksync_core/src/consensus/storage/mod.rs +++ b/core/lib/zksync_core/src/consensus/storage/mod.rs @@ -4,7 +4,7 @@ use anyhow::Context as _; use zksync_concurrency::{ctx, error::Wrap as _, sync, time}; use zksync_consensus_bft::PayloadManager; use zksync_consensus_roles::validator; -use zksync_consensus_storage::{PersistentBlockStore, ReplicaState, ReplicaStore}; +use zksync_consensus_storage::{BlockStoreState, PersistentBlockStore, ReplicaState, ReplicaStore}; use zksync_dal::{consensus_dal::Payload, ConnectionPool}; use zksync_types::MiniblockNumber; @@ -40,16 +40,12 @@ impl<'a> Connection<'a> { Ok(ctx.wait(self.0.commit()).await?.context("sqlx")?) } - /// Wrapper for `blocks_dal().get_sealed_miniblock_number()`. - pub async fn last_miniblock_number( + /// Wrapper for `consensus_dal().block_range()`. + pub async fn block_range( &mut self, ctx: &ctx::Ctx, - ) -> ctx::Result> { - Ok(ctx - .wait(self.0.blocks_dal().get_sealed_miniblock_number()) - .await? - .context("sqlx")? - .map(|n| validator::BlockNumber(n.0.into()))) + ) -> ctx::Result> { + Ok(ctx.wait(self.0.consensus_dal().block_range()).await??) } /// Wrapper for `consensus_dal().block_payload()`. @@ -63,6 +59,16 @@ impl<'a> Connection<'a> { .await??) } + /// Wrapper for `consensus_dal().first_certificate()`. + pub async fn first_certificate( + &mut self, + ctx: &ctx::Ctx, + ) -> ctx::Result> { + Ok(ctx + .wait(self.0.consensus_dal().first_certificate()) + .await??) + } + /// Wrapper for `consensus_dal().last_certificate()`. pub async fn last_certificate( &mut self, @@ -199,7 +205,7 @@ impl Store { } /// Waits for the `number` miniblock. - pub async fn wait_for_block( + pub async fn wait_for_payload( &self, ctx: &ctx::Ctx, number: validator::BlockNumber, @@ -230,14 +236,7 @@ impl BlockStore { validator_key: &validator::PublicKey, ) -> ctx::Result<()> { let mut conn = self.inner.access(ctx).await.wrap("access()")?; - // Fetch last miniblock number before starting the transaction - // to avoid taking lock on the miniblocks table. - let first_block = conn - .last_miniblock_number(ctx) - .await - .wrap("last_miniblock_number()")? - // TODO: snapshot start here. - .unwrap_or(validator::BlockNumber(0)); + let block_range = conn.block_range(ctx).await.wrap("block_range()")?; let mut txn = conn .start_transaction(ctx) .await @@ -250,8 +249,7 @@ impl BlockStore { validators: validator::ValidatorSet::new([validator_key.clone()]).unwrap(), fork: validator::Fork { number: validator::ForkNumber(0), - first_block, - first_parent: None, + first_block: block_range.end, }, }; txn.try_update_genesis(ctx, &genesis) @@ -283,31 +281,46 @@ impl PersistentBlockStore for BlockStore { } async fn state(&self, ctx: &ctx::Ctx) -> ctx::Result { - let conn = self.inner.access(ctx).await.wrap("access()")?; - + let mut conn = self.inner.access(ctx).await.wrap("access()")?; + // Fetch the range of miniblocks in storage. - let first_payload = conn.first_miniblock_number(ctx).await.wrap("first_miniblock_number()")?; - let next_payload = conn.last_miniblock_number(ctx).await.wrap("last_miniblock_number()")?.map_or(first_payload,|last|last.next()); - + let block_range = conn.block_range(ctx).await.context("block_range")?; + // Fetch the range of certificates in storage. - let first = conn.genesis(ctx).await.wrap("genesis()")?.context("genesis missing")?.fork.first_block.max(first_payload); - let last = conn.last_certificate(ctx).await.wrap("last_certificate()")?; - let next = last.map_or(first,|cert|cert.header().number.next()); - + let genesis = conn + .genesis(ctx) + .await + .wrap("genesis()")? + .context("genesis missing")?; + let first_cert = genesis.fork.first_block.max(block_range.start); + let last_cert = conn + .last_certificate(ctx) + .await + .wrap("last_certificate()")?; + let next_cert = last_cert + .as_ref() + .map_or(first_cert, |cert| cert.header().number.next()); + // Check that the first certificate in storage has the expected miniblock number. - if let Some(got) = conn.first_certificate(ctx).await.wrap("first_certificate()")? { - if got != first { - return Err(anyhow::format_err!("inconsistent storage: certificates should start at {first}, while they start at {got}").into()); + if let Some(got) = conn + .first_certificate(ctx) + .await + .wrap("first_certificate()")? + { + if got.header().number != first_cert { + return Err(anyhow::format_err!("inconsistent storage: certificates should start at {first_cert}, while they start at {}",got.header().number).into()); } } // Check that the node has all the blocks before the next expected certificate, because // the node needs to know the state of the chain up to block `X` to process block `X+1`. - if let Some(got) = &last { - if next_payload <= next { - return Err(anyhow::format_err!("inconsistent storage: cannot start consensus for miniblock {next}, because earlier blocks are missing").into()); - } + if block_range.end < next_cert { + return Err(anyhow::format_err!("inconsistent storage: cannot start consensus for miniblock {next_cert}, because earlier blocks are missing").into()); } - Ok(BlockStoreState { first, last }) + let state = BlockStoreState { + first: first_cert, + last: last_cert, + }; + Ok(state) } async fn block( @@ -376,24 +389,18 @@ impl PersistentBlockStore for BlockStore { }; cursor.advance(block).await.context("cursor.advance()")?; } - const POLL_INTERVAL: time::Duration = time::Duration::milliseconds(50); - loop { - let mut conn = self.inner.access(ctx).await.wrap("access()")?; - let last = conn - .last_miniblock_number(ctx) - .await - .wrap("last_miniblock_number()")?; - if let Some(last) = last { - if last >= block.number() { - conn.insert_certificate(ctx, &block.justification) - .await - .wrap("insert_certificate()")?; - return Ok(()); - } - } - drop(conn); - ctx.sleep(POLL_INTERVAL).await?; - } + self.inner + .wait_for_payload(ctx, block.number()) + .await + .wrap("wait_for_payload()")?; + self.inner + .access(ctx) + .await + .wrap("access()")? + .insert_certificate(ctx, &block.justification) + .await + .wrap("insert_certificate()")?; + Ok(()) } } @@ -427,7 +434,7 @@ impl PayloadManager for Store { ctx: &ctx::Ctx, block_number: validator::BlockNumber, ) -> ctx::Result { - let payload = self.wait_for_block(ctx).await?; + let payload = self.wait_for_payload(ctx, block_number).await?; let encoded_payload = payload.encode(); if encoded_payload.0.len() > 1 << 20 { tracing::warn!( @@ -449,9 +456,11 @@ impl PayloadManager for Store { payload: &validator::Payload, ) -> ctx::Result<()> { let got = Payload::decode(payload).context("Payload::decode(got)")?; - let want = self.wait_for_block(ctx).await?; + let want = self.wait_for_payload(ctx, block_number).await?; if got != want { - return Err(anyhow::format_err!("unexpected payload: got {got:?} want {want:?}").into()); + return Err( + anyhow::format_err!("unexpected payload: got {got:?} want {want:?}").into(), + ); } Ok(()) } diff --git a/core/lib/zksync_core/src/consensus/storage/testonly.rs b/core/lib/zksync_core/src/consensus/storage/testonly.rs index bee452cccb3..6bd7fb388a3 100644 --- a/core/lib/zksync_core/src/consensus/storage/testonly.rs +++ b/core/lib/zksync_core/src/consensus/storage/testonly.rs @@ -4,7 +4,6 @@ use zksync_concurrency::{ctx, error::Wrap as _, time}; use zksync_consensus_roles::validator; use zksync_consensus_storage as storage; use zksync_consensus_storage::PersistentBlockStore as _; -use zksync_dal::consensus_dal::Payload; use super::Store; @@ -16,20 +15,18 @@ impl Store { number: validator::BlockNumber, ) -> ctx::Result<()> { const POLL_INTERVAL: time::Duration = time::Duration::milliseconds(100); - loop { - if self - .access(ctx) - .await - .wrap("access()")? - .certificate(ctx, number) - .await - .wrap("certificate()")? - .is_some() - { - return Ok(()); - } + while self + .access(ctx) + .await + .wrap("access()")? + .certificate(ctx, number) + .await + .wrap("certificate()")? + .is_none() + { ctx.sleep(POLL_INTERVAL).await?; } + Ok(()) } /// Waits for `want_last` block to have certificate, then fetches all miniblocks with certificates diff --git a/core/lib/zksync_core/src/consensus/tests.rs b/core/lib/zksync_core/src/consensus/tests.rs index 5468c57055d..0dfebef662d 100644 --- a/core/lib/zksync_core/src/consensus/tests.rs +++ b/core/lib/zksync_core/src/consensus/tests.rs @@ -31,11 +31,10 @@ async fn test_validator_block_store() { let (mut sk, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; s.spawn_bg(runner.run(ctx)); sk.push_random_blocks(rng, 10).await; - store.wait_for_block(ctx, sk.last_block()).await?; + store.wait_for_payload(ctx, sk.last_block()).await?; let fork = validator::Fork { number: validator::ForkNumber(rng.gen()), first_block: validator::BlockNumber(4), - first_parent: None, }; let mut setup = Setup::new_with_fork(rng, 3, fork.clone()); let mut conn = store.access(ctx).await.wrap("access()")?; @@ -89,41 +88,38 @@ async fn test_validator() { let cfgs = new_configs(rng, &setup, 0); scope::run!(ctx, |ctx, s| async { - // Start state keeper. + tracing::info!("Start state keeper."); let store = testonly::new_store(false).await; let (mut sk, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; s.spawn_bg(runner.run(ctx)); - // Populate storage with a bunch of blocks. + tracing::info!("Populate storage with a bunch of blocks."); sk.push_random_blocks(rng, 5).await; store - .wait_for_block(ctx, sk.last_block()) + .wait_for_payload(ctx, sk.last_block()) .await .context("sk.wait_for_miniblocks(<1st phase>)")?; - // Restart consensus actor a couple times, making it process a bunch of blocks each time. + tracing::info!("Restart consensus actor a couple times, making it process a bunch of blocks each time."); for iteration in 0..3 { + tracing::info!("iteration {iteration}"); scope::run!(ctx, |ctx, s| async { - // Start consensus actor (in the first iteration it will select a genesis block and - // store a cert for it). + tracing::info!("Start consensus actor"); + // In the first iteration it will initialize genesis. let cfg = MainNodeConfig { executor: executor_config(&cfgs[0]), validator_key: setup.keys[0].clone(), }; s.spawn_bg(cfg.run(ctx, store.clone())); - store - .wait_for_certificate(ctx, sk.last_block()) - .await - .context("wait_for_certificate(<1st phase>)")?; - // Generate couple more blocks and wait for consensus to catch up. + tracing::info!("Generate couple more blocks and wait for consensus to catch up."); sk.push_random_blocks(rng, 3).await; store .wait_for_certificate(ctx, sk.last_block()) .await .context("wait_for_certificate(<2nd phase>)")?; - // Synchronously produce blocks one by one, and wait for consensus. + tracing::info!("Synchronously produce blocks one by one, and wait for consensus."); for _ in 0..2 { sk.push_random_blocks(rng, 1).await; store @@ -132,6 +128,7 @@ async fn test_validator() { .context("wait_for_certificate(<3rd phase>)")?; } + tracing::info!("Verify all certificates"); store .wait_for_certificates_and_verify(ctx, sk.last_block()) .await @@ -185,7 +182,7 @@ async fn test_full_nodes() { // Generate a couple of blocks, before initializing consensus genesis. validator.push_random_blocks(rng, 5).await; validator_store - .wait_for_block(ctx, validator.last_block()) + .wait_for_payload(ctx, validator.last_block()) .await .unwrap(); @@ -287,7 +284,7 @@ async fn test_p2p_fetcher_backfill_certs() { s.spawn_bg(node.run_centralized_fetcher(ctx, client.clone())); validator.push_random_blocks(rng, 3).await; node_store - .wait_for_block(ctx, validator.last_block()) + .wait_for_payload(ctx, validator.last_block()) .await?; Ok(()) }) @@ -344,10 +341,10 @@ async fn test_centralized_fetcher(from_snapshot: bool) { tracing::info!("Produce some blocks and wait for node to fetch them"); validator.push_random_blocks(rng, 10).await; let want = validator_store - .wait_for_block(ctx, validator.last_block()) + .wait_for_payload(ctx, validator.last_block()) .await?; let got = node_store - .wait_for_block(ctx, validator.last_block()) + .wait_for_payload(ctx, validator.last_block()) .await?; assert_eq!(want, got); Ok(()) @@ -376,14 +373,14 @@ impl RandomConfig for Config { max_payload_size: g.gen(), gossip_dynamic_inbound_limit: g.gen(), gossip_static_inbound: g - .gen::>>() + .gen::>>() .into_iter() - .map(|x| x.0.public()) + .map(|x| x.0) .collect(), gossip_static_outbound: g - .gen::>>() + .gen::>>() .into_iter() - .map(|x| (x.0.public(), g.gen())) + .map(|x| (x.0, g.gen())) .collect(), } } diff --git a/prover/Cargo.lock b/prover/Cargo.lock index a6c7be66514..d64c5d92376 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -6936,7 +6936,6 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "once_cell", @@ -6964,7 +6963,6 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "blst", @@ -6982,7 +6980,6 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "bit-vec", @@ -7002,7 +6999,6 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "async-trait", @@ -7020,7 +7016,6 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "thiserror", "zksync_concurrency", @@ -7175,7 +7170,6 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "bit-vec", @@ -7193,7 +7187,6 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=842d4fd79f1d7dae946b6873ded7ad391d554814#842d4fd79f1d7dae946b6873ded7ad391d554814" dependencies = [ "anyhow", "heck 0.4.1", @@ -7470,3 +7463,19 @@ dependencies = [ "zksync_types", "zksync_utils", ] + +[[patch.unused]] +name = "zksync_consensus_bft" +version = "0.1.0" + +[[patch.unused]] +name = "zksync_consensus_executor" +version = "0.1.0" + +[[patch.unused]] +name = "zksync_consensus_network" +version = "0.1.0" + +[[patch.unused]] +name = "zksync_consensus_sync_blocks" +version = "0.1.0" From 6bf65ff5e48559d7781647833b13f2c981b091c0 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Thu, 14 Mar 2024 12:01:48 +0100 Subject: [PATCH 03/11] tests fixed --- core/lib/dal/src/consensus_dal.rs | 5 ++++- .../zksync_core/src/consensus/storage/mod.rs | 6 ++++++ core/lib/zksync_core/src/consensus/tests.rs | 21 ++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/lib/dal/src/consensus_dal.rs b/core/lib/dal/src/consensus_dal.rs index c141139c9e3..daf7997eee1 100644 --- a/core/lib/dal/src/consensus_dal.rs +++ b/core/lib/dal/src/consensus_dal.rs @@ -104,7 +104,10 @@ impl ConsensusDal<'_, '_> { .get_applied_snapshot_status() .await .context("get_applied_snapshot_status()")?; - let start = validator::BlockNumber(snapshot.map_or(0, |s| s.miniblock_number.0).into()); + // `snapshot.miniblock_number` indicates the last block processed. + // This block is NOT present in storage. Therefore the first block + // that will appear in storage is `snapshot.miniblock_number+1`. + let start = validator::BlockNumber(snapshot.map_or(0, |s| s.miniblock_number.0 + 1).into()); let end = txn .blocks_dal() .get_sealed_miniblock_number() diff --git a/core/lib/zksync_core/src/consensus/storage/mod.rs b/core/lib/zksync_core/src/consensus/storage/mod.rs index e47eed8b738..76c51426ad2 100644 --- a/core/lib/zksync_core/src/consensus/storage/mod.rs +++ b/core/lib/zksync_core/src/consensus/storage/mod.rs @@ -358,6 +358,7 @@ impl PersistentBlockStore for BlockStore { ctx: &ctx::Ctx, block: &validator::FinalBlock, ) -> ctx::Result<()> { + tracing::info!("storing block {}", block.number()); // This mutex prevents concurrent `store_next_block` calls. let mut guard = ctx.wait(self.store_next_block_mutex.lock()).await?; if let Some(cursor) = &mut *guard { @@ -400,6 +401,7 @@ impl PersistentBlockStore for BlockStore { .insert_certificate(ctx, &block.justification) .await .wrap("insert_certificate()")?; + tracing::info!("storing block {} DONE", block.number()); Ok(()) } } @@ -434,6 +436,7 @@ impl PayloadManager for Store { ctx: &ctx::Ctx, block_number: validator::BlockNumber, ) -> ctx::Result { + tracing::info!("proposing block {block_number}"); let payload = self.wait_for_payload(ctx, block_number).await?; let encoded_payload = payload.encode(); if encoded_payload.0.len() > 1 << 20 { @@ -443,6 +446,7 @@ impl PayloadManager for Store { payload.transactions.len() ); } + tracing::info!("proposing block {block_number} DONE"); Ok(encoded_payload) } @@ -455,6 +459,7 @@ impl PayloadManager for Store { block_number: validator::BlockNumber, payload: &validator::Payload, ) -> ctx::Result<()> { + tracing::info!("verifying block {block_number}"); let got = Payload::decode(payload).context("Payload::decode(got)")?; let want = self.wait_for_payload(ctx, block_number).await?; if got != want { @@ -462,6 +467,7 @@ impl PayloadManager for Store { anyhow::format_err!("unexpected payload: got {got:?} want {want:?}").into(), ); } + tracing::info!("verifying block {block_number} DONE"); Ok(()) } } diff --git a/core/lib/zksync_core/src/consensus/tests.rs b/core/lib/zksync_core/src/consensus/tests.rs index 0dfebef662d..59fb911bb06 100644 --- a/core/lib/zksync_core/src/consensus/tests.rs +++ b/core/lib/zksync_core/src/consensus/tests.rs @@ -79,8 +79,9 @@ fn executor_config(cfg: &network::Config) -> executor::Config { // In the current implementation, consensus certificates are created asynchronously // for the miniblocks constructed by the StateKeeper. This means that consensus actor // is effectively just back filling the consensus certificates for the miniblocks in storage. +#[test_casing(2, [false, true])] #[tokio::test(flavor = "multi_thread")] -async fn test_validator() { +async fn test_validator(from_snapshot: bool) { zksync_concurrency::testonly::abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(10.)); let rng = &mut ctx.rng(); @@ -89,7 +90,7 @@ async fn test_validator() { scope::run!(ctx, |ctx, s| async { tracing::info!("Start state keeper."); - let store = testonly::new_store(false).await; + let store = testonly::new_store(from_snapshot).await; let (mut sk, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; s.spawn_bg(runner.run(ctx)); @@ -147,8 +148,9 @@ async fn test_validator() { // Test running a validator node and a couple of full nodes. // Validator is producing signed blocks and fetchers are expected to fetch // them directly or indirectly. +#[test_casing(2, [false, true])] #[tokio::test(flavor = "multi_thread")] -async fn test_full_nodes() { +async fn test_full_nodes(from_snapshot: bool) { const NODES: usize = 2; zksync_concurrency::testonly::abort_on_panic(); @@ -169,7 +171,7 @@ async fn test_full_nodes() { // Run validator and fetchers in parallel. scope::run!(ctx, |ctx, s| async { - let validator_store = testonly::new_store(false).await; + let validator_store = testonly::new_store(from_snapshot).await; let (mut validator, runner) = testonly::StateKeeper::new(ctx, validator_store.clone()).await?; s.spawn_bg(async { @@ -197,7 +199,7 @@ async fn test_full_nodes() { let mut node_stores = vec![]; for (i, cfg) in node_cfgs.iter().enumerate() { let i = ctx::NoCopy(i); - let store = testonly::new_store(false).await; + let store = testonly::new_store(from_snapshot).await; let (node, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; node_stores.push(store.clone()); s.spawn_bg(async { @@ -237,8 +239,9 @@ async fn test_full_nodes() { } // Test fetcher back filling missing certs. +#[test_casing(2, [false, true])] #[tokio::test(flavor = "multi_thread")] -async fn test_p2p_fetcher_backfill_certs() { +async fn test_p2p_fetcher_backfill_certs(from_snapshot: bool) { zksync_concurrency::testonly::abort_on_panic(); let ctx = &ctx::test_root(&ctx::AffineClock::new(10.)); let rng = &mut ctx.rng(); @@ -248,7 +251,7 @@ async fn test_p2p_fetcher_backfill_certs() { scope::run!(ctx, |ctx, s| async { tracing::info!("Spawn validator."); - let validator_store = testonly::new_store(false).await; + let validator_store = testonly::new_store(from_snapshot).await; let (mut validator, runner) = testonly::StateKeeper::new(ctx, validator_store.clone()).await?; s.spawn_bg(runner.run(ctx)); @@ -259,9 +262,11 @@ async fn test_p2p_fetcher_backfill_certs() { } .run(ctx, validator_store.clone()), ); + // API server needs at least 1 L1 batch to start. + validator.seal_batch().await; let client = validator.connect(ctx).await?; - let node_store = testonly::new_store(false).await; + let node_store = testonly::new_store(from_snapshot).await; tracing::info!("Run p2p fetcher."); scope::run!(ctx, |ctx, s| async { From 06e86595ed8218691dadadedc1a8bbf2848db760 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 11:06:39 +0100 Subject: [PATCH 04/11] enabled snapshot + consensus CI test --- .github/workflows/ci-core-reusable.yml | 1 - core/bin/external_node/src/main.rs | 12 +- core/lib/dal/src/snapshots_creator_dal.rs | 2 + .../src/consensus/storage/testonly.rs | 35 ++++ .../lib/zksync_core/src/consensus/testonly.rs | 22 +-- core/lib/zksync_core/src/consensus/tests.rs | 27 ++- core/lib/zksync_core/src/utils/testonly.rs | 163 ++++++++++++++---- 7 files changed, 188 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index e1a7074cd15..ed1fc782e9f 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -200,7 +200,6 @@ jobs: run: ci_run zk test i server - name: Snapshot recovery test - if: ${{ ! matrix.consensus }} # We use `yarn` directly because the test launches `zk` commands in both server and EN envs. # An empty topmost environment helps avoid a mess when redefining env vars shared between both envs # (e.g., DATABASE_URL). diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 492e6fb7783..8c82dc6142a 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -435,7 +435,7 @@ struct Cli { /// or was synced from genesis. /// /// This is an experimental and incomplete feature; do not use unless you know what you're doing. - #[arg(long, conflicts_with = "enable_consensus")] + #[arg(long)] enable_snapshots_recovery: bool, } @@ -470,17 +470,9 @@ async fn main() -> anyhow::Result<()> { let mut config = ExternalNodeConfig::collect() .await .context("Failed to load external node config")?; - if opt.enable_consensus { - // This is more of a sanity check; the mutual exclusion of `enable_consensus` and `enable_snapshots_recovery` - // should be ensured by `clap`. - anyhow::ensure!( - !opt.enable_snapshots_recovery, - "Consensus logic does not support snapshot recovery yet" - ); - } else { + if !opt.enable_consensus { config.consensus = None; } - if let Some(threshold) = config.optional.slow_query_threshold() { ConnectionPool::global_config().set_slow_query_threshold(threshold)?; } diff --git a/core/lib/dal/src/snapshots_creator_dal.rs b/core/lib/dal/src/snapshots_creator_dal.rs index 7940ecb7cdf..b7b2dda6eb1 100644 --- a/core/lib/dal/src/snapshots_creator_dal.rs +++ b/core/lib/dal/src/snapshots_creator_dal.rs @@ -67,6 +67,8 @@ impl SnapshotsCreatorDal<'_, '_> { Ok(row.count.unwrap_or(0) as u64) } + /// Constructs a `storate_logs` chunk of the state AFTER processing `[0..l1_batch_number]` + /// batches. `miniblock_number` MUST be the last miniblock of the `l1_batch_number` batch. pub async fn get_storage_logs_chunk( &mut self, miniblock_number: MiniblockNumber, diff --git a/core/lib/zksync_core/src/consensus/storage/testonly.rs b/core/lib/zksync_core/src/consensus/storage/testonly.rs index 6bd7fb388a3..f7f427888f0 100644 --- a/core/lib/zksync_core/src/consensus/storage/testonly.rs +++ b/core/lib/zksync_core/src/consensus/storage/testonly.rs @@ -4,8 +4,14 @@ use zksync_concurrency::{ctx, error::Wrap as _, time}; use zksync_consensus_roles::validator; use zksync_consensus_storage as storage; use zksync_consensus_storage::PersistentBlockStore as _; +use zksync_dal::ConnectionPool; +use zksync_types::L2ChainId; use super::Store; +use crate::{ + genesis::{ensure_genesis_state, GenesisParams}, + utils::testonly::{recover, snapshot, Snapshot}, +}; impl Store { /// Waits for the `number` miniblock to have a certificate. @@ -47,4 +53,33 @@ impl Store { } Ok(blocks) } + + /// Takes a storage snapshot at the last sealed L1 batch. + pub(crate) async fn snapshot(&self, ctx: &ctx::Ctx) -> ctx::Result { + let mut conn = self.access(ctx).await.wrap("access()")?; + Ok(ctx.wait(snapshot(&mut conn.0)).await?) + } + + /// Constructs a new db initialized with genesis state. + pub(crate) async fn from_genesis() -> Self { + let pool = ConnectionPool::test_pool().await; + { + let mut storage = pool.access_storage().await.unwrap(); + ensure_genesis_state(&mut storage, L2ChainId::default(), &GenesisParams::mock()) + .await + .unwrap(); + } + Self(pool) + } + + /// Recovers storage from a snapshot. + #[allow(dead_code)] + pub(crate) async fn from_snapshot(snapshot: Snapshot) -> Self { + let pool = ConnectionPool::test_pool().await; + { + let mut storage = pool.access_storage().await.unwrap(); + recover(&mut storage, snapshot).await; + } + Self(pool) + } } diff --git a/core/lib/zksync_core/src/consensus/testonly.rs b/core/lib/zksync_core/src/consensus/testonly.rs index fb099595b03..6de4ac15681 100644 --- a/core/lib/zksync_core/src/consensus/testonly.rs +++ b/core/lib/zksync_core/src/consensus/testonly.rs @@ -7,7 +7,6 @@ use zksync_concurrency::{ctx, error::Wrap as _, limiter, scope, sync, time}; use zksync_config::configs; use zksync_consensus_roles::validator; use zksync_contracts::BaseSystemContractsHashes; -use zksync_dal::ConnectionPool; use zksync_types::{ api, snapshots::SnapshotRecoveryStatus, Address, L1BatchNumber, L2ChainId, MiniblockNumber, ProtocolVersionId, H256, @@ -20,7 +19,7 @@ use zksync_web3_decl::{ use crate::{ api_server::web3::{state::InternalApiConfig, tests::spawn_http_server}, consensus::{fetcher::P2PConfig, Fetcher, Store}, - genesis::{ensure_genesis_state, GenesisParams}, + genesis::GenesisParams, state_keeper::{ io::common::IoCursor, seal_criteria::NoopSealer, tests::MockBatchExecutor, MiniblockSealer, ZkSyncStateKeeper, @@ -30,7 +29,7 @@ use crate::{ sync_action::{ActionQueue, ActionQueueSender, SyncAction}, ExternalIO, MainNodeClient, SyncState, }, - utils::testonly::{create_l1_batch_metadata, create_l2_transaction, prepare_recovery_snapshot}, + utils::testonly::{create_l1_batch_metadata, create_l2_transaction}, }; #[derive(Debug, Default)] @@ -171,23 +170,6 @@ pub(super) struct StateKeeperRunner { addr: sync::watch::Sender>, } -/// Constructs a new db initialized with genesis state or a snapshot. -pub(super) async fn new_store(from_snapshot: bool) -> Store { - let pool = ConnectionPool::test_pool().await; - { - let mut storage = pool.access_storage().await.unwrap(); - if from_snapshot { - prepare_recovery_snapshot(&mut storage, L1BatchNumber(23), MiniblockNumber(42), &[]) - .await; - } else { - ensure_genesis_state(&mut storage, L2ChainId::default(), &GenesisParams::mock()) - .await - .unwrap(); - } - } - Store(pool) -} - // Limiter with infinite refresh rate. fn unbounded_limiter(ctx: &ctx::Ctx) -> limiter::Limiter { limiter::Limiter::new( diff --git a/core/lib/zksync_core/src/consensus/tests.rs b/core/lib/zksync_core/src/consensus/tests.rs index 59fb911bb06..e78ab990db6 100644 --- a/core/lib/zksync_core/src/consensus/tests.rs +++ b/core/lib/zksync_core/src/consensus/tests.rs @@ -14,15 +14,26 @@ use zksync_consensus_roles::{node, validator::testonly::Setup}; use zksync_consensus_storage as storage; use zksync_consensus_storage::PersistentBlockStore as _; use zksync_protobuf_config::testonly::{encode_decode, FmtConv}; +use zksync_types::{L1BatchNumber, MiniblockNumber}; use super::*; +use crate::utils::testonly::Snapshot; + +async fn new_store(from_snapshot: bool) -> Store { + match from_snapshot { + true => { + Store::from_snapshot(Snapshot::make(L1BatchNumber(23), MiniblockNumber(87), &[])).await + } + false => Store::from_genesis().await, + } +} #[tokio::test(flavor = "multi_thread")] async fn test_validator_block_store() { zksync_concurrency::testonly::abort_on_panic(); let ctx = &ctx::test_root(&ctx::RealClock); let rng = &mut ctx.rng(); - let store = testonly::new_store(false).await; + let store = new_store(false).await; // Fill storage with unsigned miniblocks. // Fetch a suffix of blocks that we will generate (fake) certs for. @@ -90,7 +101,7 @@ async fn test_validator(from_snapshot: bool) { scope::run!(ctx, |ctx, s| async { tracing::info!("Start state keeper."); - let store = testonly::new_store(from_snapshot).await; + let store = new_store(from_snapshot).await; let (mut sk, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; s.spawn_bg(runner.run(ctx)); @@ -171,7 +182,7 @@ async fn test_full_nodes(from_snapshot: bool) { // Run validator and fetchers in parallel. scope::run!(ctx, |ctx, s| async { - let validator_store = testonly::new_store(from_snapshot).await; + let validator_store = new_store(from_snapshot).await; let (mut validator, runner) = testonly::StateKeeper::new(ctx, validator_store.clone()).await?; s.spawn_bg(async { @@ -199,7 +210,7 @@ async fn test_full_nodes(from_snapshot: bool) { let mut node_stores = vec![]; for (i, cfg) in node_cfgs.iter().enumerate() { let i = ctx::NoCopy(i); - let store = testonly::new_store(from_snapshot).await; + let store = new_store(from_snapshot).await; let (node, runner) = testonly::StateKeeper::new(ctx, store.clone()).await?; node_stores.push(store.clone()); s.spawn_bg(async { @@ -251,7 +262,7 @@ async fn test_p2p_fetcher_backfill_certs(from_snapshot: bool) { scope::run!(ctx, |ctx, s| async { tracing::info!("Spawn validator."); - let validator_store = testonly::new_store(from_snapshot).await; + let validator_store = new_store(from_snapshot).await; let (mut validator, runner) = testonly::StateKeeper::new(ctx, validator_store.clone()).await?; s.spawn_bg(runner.run(ctx)); @@ -266,7 +277,7 @@ async fn test_p2p_fetcher_backfill_certs(from_snapshot: bool) { validator.seal_batch().await; let client = validator.connect(ctx).await?; - let node_store = testonly::new_store(from_snapshot).await; + let node_store = new_store(from_snapshot).await; tracing::info!("Run p2p fetcher."); scope::run!(ctx, |ctx, s| async { @@ -328,7 +339,7 @@ async fn test_centralized_fetcher(from_snapshot: bool) { scope::run!(ctx, |ctx, s| async { tracing::info!("Spawn a validator."); - let validator_store = testonly::new_store(from_snapshot).await; + let validator_store = new_store(from_snapshot).await; let (mut validator, runner) = testonly::StateKeeper::new(ctx, validator_store.clone()).await?; s.spawn_bg(runner.run(ctx).instrument(tracing::info_span!("validator"))); @@ -338,7 +349,7 @@ async fn test_centralized_fetcher(from_snapshot: bool) { validator.seal_batch().await; tracing::info!("Spawn a node."); - let node_store = testonly::new_store(from_snapshot).await; + let node_store = new_store(from_snapshot).await; let (node, runner) = testonly::StateKeeper::new(ctx, node_store.clone()).await?; s.spawn_bg(runner.run(ctx).instrument(tracing::info_span!("fetcher"))); s.spawn_bg(node.run_centralized_fetcher(ctx, validator.connect(ctx).await?)); diff --git a/core/lib/zksync_core/src/utils/testonly.rs b/core/lib/zksync_core/src/utils/testonly.rs index 978b342a4b8..24e24b037b2 100644 --- a/core/lib/zksync_core/src/utils/testonly.rs +++ b/core/lib/zksync_core/src/utils/testonly.rs @@ -1,5 +1,4 @@ //! Test utils. - use std::collections::HashMap; use multivm::utils::get_max_gas_per_pubdata_byte; @@ -148,84 +147,178 @@ pub(crate) fn execute_l2_transaction(transaction: L2Tx) -> TransactionExecutionR } } +/// Concise representation of a storage snapshot for testing recovery. +#[derive(Debug)] +pub(crate) struct Snapshot { + pub l1_batch: L1BatchHeader, + pub miniblock: MiniblockHeader, + pub storage_logs: Vec, + pub factory_deps: HashMap>, +} + +impl Snapshot { + pub fn make( + l1_batch: L1BatchNumber, + miniblock: MiniblockNumber, + storage_logs: &[StorageLog], + ) -> Self { + let genesis_params = GenesisParams::mock(); + let contracts = &genesis_params.base_system_contracts; + let l1_batch = L1BatchHeader::new( + l1_batch, + l1_batch.0.into(), + contracts.hashes(), + genesis_params.protocol_version, + ); + let miniblock = MiniblockHeader { + number: miniblock, + timestamp: miniblock.0.into(), + hash: H256::from_low_u64_be(miniblock.0.into()), + l1_tx_count: 0, + l2_tx_count: 0, + base_fee_per_gas: 100, + batch_fee_input: BatchFeeInput::l1_pegged(100, 100), + fee_account_address: Address::zero(), + gas_per_pubdata_limit: get_max_gas_per_pubdata_byte( + genesis_params.protocol_version.into(), + ), + base_system_contracts_hashes: contracts.hashes(), + protocol_version: Some(genesis_params.protocol_version), + virtual_blocks: 1, + }; + Snapshot { + l1_batch, + miniblock, + factory_deps: [&contracts.bootloader, &contracts.default_aa] + .into_iter() + .map(|c| (c.hash, zksync_utils::be_words_to_bytes(&c.code))) + .collect(), + storage_logs: storage_logs.iter().cloned().collect(), + } + } +} + /// Prepares a recovery snapshot without performing genesis. pub(crate) async fn prepare_recovery_snapshot( storage: &mut StorageProcessor<'_>, - l1_batch_number: L1BatchNumber, - miniblock_number: MiniblockNumber, - snapshot_logs: &[StorageLog], + l1_batch: L1BatchNumber, + miniblock: MiniblockNumber, + storage_logs: &[StorageLog], ) -> SnapshotRecoveryStatus { - let mut storage = storage.start_transaction().await.unwrap(); + recover(storage, Snapshot::make(l1_batch, miniblock, storage_logs)).await +} - let written_keys: Vec<_> = snapshot_logs.iter().map(|log| log.key).collect(); - let tree_instructions: Vec<_> = snapshot_logs +/// Takes a storage snapshot at the last sealed L1 batch. +pub(crate) async fn snapshot(storage: &mut StorageProcessor<'_>) -> Snapshot { + let l1_batch = storage + .blocks_dal() + .get_sealed_l1_batch_number() + .await + .unwrap() + .expect("no L1 batches in storage"); + let l1_batch = storage + .blocks_dal() + .get_l1_batch_header(l1_batch) + .await + .unwrap() + .unwrap(); + let (_, miniblock) = storage + .blocks_dal() + .get_miniblock_range_of_l1_batch(l1_batch.number) + .await + .unwrap() + .unwrap(); + let all_hashes = H256::zero()..=H256::repeat_byte(0xff); + Snapshot { + miniblock: storage + .blocks_dal() + .get_miniblock_header(miniblock) + .await + .unwrap() + .unwrap(), + storage_logs: storage + .snapshots_creator_dal() + .get_storage_logs_chunk(miniblock, l1_batch.number, all_hashes) + .await + .unwrap() + .into_iter() + .map(|l| StorageLog::new_write_log(l.key, l.value)) + .collect(), + factory_deps: storage + .snapshots_creator_dal() + .get_all_factory_deps(miniblock) + .await + .unwrap() + .into_iter() + .collect(), + l1_batch, + } +} + +/// Recovers storage from a snapshot. +/// Miniblock and L1 batch are intentionally **not** inserted into the storage. +pub(crate) async fn recover( + storage: &mut StorageProcessor<'_>, + snapshot: Snapshot, +) -> SnapshotRecoveryStatus { + let mut storage = storage.start_transaction().await.unwrap(); + let written_keys: Vec<_> = snapshot.storage_logs.iter().map(|log| log.key).collect(); + let tree_instructions: Vec<_> = snapshot + .storage_logs .iter() .enumerate() .map(|(i, log)| TreeInstruction::write(log.key, i as u64 + 1, log.value)) .collect(); let l1_batch_root_hash = ZkSyncTree::process_genesis_batch(&tree_instructions).root_hash; - let miniblock = create_miniblock(miniblock_number.0); - let l1_batch = create_l1_batch(l1_batch_number.0); - // Miniblock and L1 batch are intentionally **not** inserted into the storage. - // Store factory deps for the base system contracts. - let contracts = GenesisParams::mock().base_system_contracts; - let protocol_version = storage .protocol_versions_dal() - .get_protocol_version(ProtocolVersionId::latest()) + .get_protocol_version(snapshot.l1_batch.protocol_version.unwrap()) .await; if let Some(protocol_version) = protocol_version { assert_eq!( protocol_version.base_system_contracts_hashes, - contracts.hashes(), + snapshot.l1_batch.base_system_contracts_hashes, "Protocol version set up with incorrect base system contracts" ); } else { storage .protocol_versions_dal() .save_protocol_version_with_tx(ProtocolVersion { - base_system_contracts_hashes: contracts.hashes(), + base_system_contracts_hashes: snapshot.l1_batch.base_system_contracts_hashes, ..ProtocolVersion::default() }) .await; } - let factory_deps = HashMap::from([ - ( - contracts.bootloader.hash, - zksync_utils::be_words_to_bytes(&contracts.bootloader.code), - ), - ( - contracts.default_aa.hash, - zksync_utils::be_words_to_bytes(&contracts.default_aa.code), - ), - ]); storage .factory_deps_dal() - .insert_factory_deps(miniblock.number, &factory_deps) + .insert_factory_deps(snapshot.miniblock.number, &snapshot.factory_deps) .await .unwrap(); storage .storage_logs_dedup_dal() - .insert_initial_writes(l1_batch.number, &written_keys) + .insert_initial_writes(snapshot.l1_batch.number, &written_keys) .await .unwrap(); storage .storage_logs_dal() - .insert_storage_logs(miniblock.number, &[(H256::zero(), snapshot_logs.to_vec())]) + .insert_storage_logs( + snapshot.miniblock.number, + &[(H256::zero(), snapshot.storage_logs)], + ) .await .unwrap(); let snapshot_recovery = SnapshotRecoveryStatus { - l1_batch_number: l1_batch.number, - l1_batch_timestamp: l1_batch.timestamp, + l1_batch_number: snapshot.l1_batch.number, + l1_batch_timestamp: snapshot.l1_batch.timestamp, l1_batch_root_hash, - miniblock_number: miniblock.number, - miniblock_timestamp: miniblock.timestamp, - miniblock_hash: H256::zero(), // not used - protocol_version: ProtocolVersionId::latest(), + miniblock_number: snapshot.miniblock.number, + miniblock_timestamp: snapshot.miniblock.timestamp, + miniblock_hash: snapshot.miniblock.hash, + protocol_version: snapshot.l1_batch.protocol_version.unwrap(), storage_logs_chunks_processed: vec![true; 100], }; storage From a086f6020b9fd995e621935f0b6d18964d690034 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 11:36:34 +0100 Subject: [PATCH 05/11] test with multiple snapshots --- .../src/consensus/storage/testonly.rs | 1 - core/lib/zksync_core/src/consensus/tests.rs | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/consensus/storage/testonly.rs b/core/lib/zksync_core/src/consensus/storage/testonly.rs index f7f427888f0..9c08b2524a5 100644 --- a/core/lib/zksync_core/src/consensus/storage/testonly.rs +++ b/core/lib/zksync_core/src/consensus/storage/testonly.rs @@ -73,7 +73,6 @@ impl Store { } /// Recovers storage from a snapshot. - #[allow(dead_code)] pub(crate) async fn from_snapshot(snapshot: Snapshot) -> Self { let pool = ConnectionPool::test_pool().await; { diff --git a/core/lib/zksync_core/src/consensus/tests.rs b/core/lib/zksync_core/src/consensus/tests.rs index e78ab990db6..3cc4535c67f 100644 --- a/core/lib/zksync_core/src/consensus/tests.rs +++ b/core/lib/zksync_core/src/consensus/tests.rs @@ -156,6 +156,79 @@ async fn test_validator(from_snapshot: bool) { .unwrap(); } +// Test running a validator node and 2 full nodes recovered from different snapshots. +#[tokio::test(flavor = "multi_thread")] +async fn test_nodes_from_various_snapshots() { + zksync_concurrency::testonly::abort_on_panic(); + let ctx = &ctx::test_root(&ctx::AffineClock::new(10.)); + let rng = &mut ctx.rng(); + let setup = Setup::new(rng, 1); + let validator_cfg = new_configs(rng, &setup, 0).pop().unwrap(); + + scope::run!(ctx, |ctx, s| async { + tracing::info!("spawn validator"); + let validator_store = Store::from_genesis().await; + let (mut validator, runner) = + testonly::StateKeeper::new(ctx, validator_store.clone()).await?; + s.spawn_bg(runner.run(ctx).instrument(tracing::info_span!("validator"))); + let cfg = MainNodeConfig { + executor: executor_config(&validator_cfg), + validator_key: setup.keys[0].clone(), + }; + s.spawn_bg(cfg.run(ctx, validator_store.clone())); + + tracing::info!("produce some batches"); + validator.push_random_blocks(rng, 5).await; + validator.seal_batch().await; + validator_store + .wait_for_certificate(ctx, validator.last_block()) + .await?; + + tracing::info!("take snapshot and start a node from it"); + let snapshot = validator_store.snapshot(ctx).await?; + let node_store = Store::from_snapshot(snapshot).await; + let (node, runner) = testonly::StateKeeper::new(ctx, node_store.clone()).await?; + s.spawn_bg(runner.run(ctx).instrument(tracing::info_span!("node1"))); + let node_cfg = executor_config(&new_fullnode(rng, &validator_cfg)); + s.spawn_bg(node.run_p2p_fetcher(ctx, validator.connect(ctx).await?, node_cfg)); + + tracing::info!("produce more batches"); + validator.push_random_blocks(rng, 5).await; + validator.seal_batch().await; + node_store + .wait_for_certificate(ctx, validator.last_block()) + .await?; + + tracing::info!("take another snapshot and start a node from it"); + let snapshot = validator_store.snapshot(ctx).await?; + let node_store2 = Store::from_snapshot(snapshot).await; + let (node, runner) = testonly::StateKeeper::new(ctx, node_store2.clone()).await?; + s.spawn_bg(runner.run(ctx).instrument(tracing::info_span!("node2"))); + let node_cfg = executor_config(&new_fullnode(rng, &validator_cfg)); + s.spawn_bg(node.run_p2p_fetcher(ctx, validator.connect(ctx).await?, node_cfg)); + + tracing::info!("produce more blocks and compare storages"); + validator.push_random_blocks(rng, 5).await; + let want = validator_store + .wait_for_certificates_and_verify(ctx, validator.last_block()) + .await?; + // node stores should be suffixes for validator store. + for got in [ + node_store + .wait_for_certificates_and_verify(ctx, validator.last_block()) + .await?, + node_store2 + .wait_for_certificates_and_verify(ctx, validator.last_block()) + .await?, + ] { + assert_eq!(want[want.len() - got.len()..], got[..]); + } + Ok(()) + }) + .await + .unwrap(); +} + // Test running a validator node and a couple of full nodes. // Validator is producing signed blocks and fetchers are expected to fetch // them directly or indirectly. From 9f146ee39ee10a269360d0e732a1edf22e92cdba Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 11:46:37 +0100 Subject: [PATCH 06/11] removed local overrides --- Cargo.lock | 11 +++++++++++ core/bin/external_node/Cargo.toml | 4 ++-- core/bin/zksync_server/Cargo.toml | 8 ++++---- core/lib/dal/Cargo.toml | 8 ++++---- core/lib/object_store/Cargo.toml | 2 +- core/lib/protobuf_config/Cargo.toml | 4 ++-- core/lib/types/Cargo.toml | 4 ++-- core/lib/zksync_core/Cargo.toml | 20 ++++++++++---------- 8 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccc8fe52263..52dc7870fce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8003,6 +8003,7 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "once_cell", @@ -8030,6 +8031,7 @@ dependencies = [ [[package]] name = "zksync_consensus_bft" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "async-trait", @@ -8050,6 +8052,7 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "blst", @@ -8067,6 +8070,7 @@ dependencies = [ [[package]] name = "zksync_consensus_executor" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "rand 0.8.5", @@ -8086,6 +8090,7 @@ dependencies = [ [[package]] name = "zksync_consensus_network" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "async-trait", @@ -8110,6 +8115,7 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "bit-vec", @@ -8129,6 +8135,7 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "async-trait", @@ -8146,6 +8153,7 @@ dependencies = [ [[package]] name = "zksync_consensus_sync_blocks" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "thiserror", @@ -8160,6 +8168,7 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "thiserror", "zksync_concurrency", @@ -8554,6 +8563,7 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "bit-vec", @@ -8571,6 +8581,7 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "heck 0.4.1", diff --git a/core/bin/external_node/Cargo.toml b/core/bin/external_node/Cargo.toml index 27b1f0b616c..4f965a3789b 100644 --- a/core/bin/external_node/Cargo.toml +++ b/core/bin/external_node/Cargo.toml @@ -28,8 +28,8 @@ zksync_web3_decl = { path = "../../lib/web3_decl" } zksync_types = { path = "../../lib/types" } vlog = { path = "../../lib/vlog" } -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" } anyhow = "1.0" diff --git a/core/bin/zksync_server/Cargo.toml b/core/bin/zksync_server/Cargo.toml index f2e01aeef58..04450af5b6c 100644 --- a/core/bin/zksync_server/Cargo.toml +++ b/core/bin/zksync_server/Cargo.toml @@ -19,10 +19,10 @@ zksync_types = { path = "../../lib/types" } zksync_core = { path = "../../lib/zksync_core" } # Consensus dependenices -zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } vlog = { path = "../../lib/vlog" } anyhow = "1.0" diff --git a/core/lib/dal/Cargo.toml b/core/lib/dal/Cargo.toml index 8b9c74fb61e..f0a2c76a697 100644 --- a/core/lib/dal/Cargo.toml +++ b/core/lib/dal/Cargo.toml @@ -18,9 +18,9 @@ zksync_system_constants = { path = "../constants" } zksync_contracts = { path = "../contracts" } zksync_types = { path = "../types" } zksync_health_check = { path = "../health_check" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } itertools = "0.10.1" thiserror = "1.0" @@ -55,4 +55,4 @@ chrono = { version = "0.4", features = ["serde"] } assert_matches = "1.5.0" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } diff --git a/core/lib/object_store/Cargo.toml b/core/lib/object_store/Cargo.toml index b26e37a42c6..f0dbda7d250 100644 --- a/core/lib/object_store/Cargo.toml +++ b/core/lib/object_store/Cargo.toml @@ -13,7 +13,7 @@ categories = ["cryptography"] vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" } zksync_config = { path = "../config" } zksync_types = { path = "../types" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } anyhow = "1.0" async-trait = "0.1" bincode = "1" diff --git a/core/lib/protobuf_config/Cargo.toml b/core/lib/protobuf_config/Cargo.toml index 465b45d40ba..99fbdc21c67 100644 --- a/core/lib/protobuf_config/Cargo.toml +++ b/core/lib/protobuf_config/Cargo.toml @@ -16,7 +16,7 @@ serde_json = "1.0" serde_yaml = "0.9" zksync_basic_types = { path = "../basic_types" } zksync_config = { path = "../config" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } zksync_types = { path = "../types" } anyhow = "1.0" @@ -25,5 +25,5 @@ prost = "0.12.1" rand = "0.8" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } diff --git a/core/lib/types/Cargo.toml b/core/lib/types/Cargo.toml index 0655f0c5b65..1397a17bf8d 100644 --- a/core/lib/types/Cargo.toml +++ b/core/lib/types/Cargo.toml @@ -17,7 +17,7 @@ zksync_basic_types = { path = "../basic_types" } zksync_contracts = { path = "../contracts" } zksync_mini_merkle_tree = { path = "../mini_merkle_tree" } zksync_config = { path = "../config" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } anyhow = "1.0.75" chrono = { version = "0.4", features = ["serde"] } @@ -42,4 +42,4 @@ tokio = { version = "1", features = ["rt", "macros"] } serde_with = { version = "1", features = ["hex"] } [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index 8bd47ca9a71..cee1cfa6df3 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -46,15 +46,15 @@ vlog = { path = "../vlog" } multivm = { path = "../multivm" } # Consensus dependenices -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } prost = "0.12.1" serde = { version = "1.0", features = ["derive"] } @@ -103,4 +103,4 @@ tempfile = "3.0.2" test-casing = "0.1.2" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "842d4fd79f1d7dae946b6873ded7ad391d554814" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } From 3eb9c23d6ec6190b4108c39c7fa4317b1e570959 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 12:00:26 +0100 Subject: [PATCH 07/11] prover/Cargo.lock --- prover/Cargo.lock | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/prover/Cargo.lock b/prover/Cargo.lock index bb514a7cf2a..b27e34d5c1a 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -6936,6 +6936,7 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "once_cell", @@ -6963,6 +6964,7 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "blst", @@ -6980,6 +6982,7 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "bit-vec", @@ -6999,6 +7002,7 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "async-trait", @@ -7016,6 +7020,7 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "thiserror", "zksync_concurrency", @@ -7170,6 +7175,7 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "bit-vec", @@ -7187,6 +7193,7 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" dependencies = [ "anyhow", "heck 0.4.1", @@ -7463,19 +7470,3 @@ dependencies = [ "zksync_types", "zksync_utils", ] - -[[patch.unused]] -name = "zksync_consensus_bft" -version = "0.1.0" - -[[patch.unused]] -name = "zksync_consensus_executor" -version = "0.1.0" - -[[patch.unused]] -name = "zksync_consensus_network" -version = "0.1.0" - -[[patch.unused]] -name = "zksync_consensus_sync_blocks" -version = "0.1.0" From f06e9d5c828ce44140424430f89e9af90e59eabd Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 12:27:18 +0100 Subject: [PATCH 08/11] updated snapshot-recovery test to support consensus --- .github/workflows/ci-core-reusable.yml | 2 +- core/tests/revert-test/tests/revert-and-restart-en.test.ts | 6 +++--- .../snapshot-recovery-test/tests/snapshot-recovery.test.ts | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index ed1fc782e9f..6cc159ad704 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -203,7 +203,7 @@ jobs: # We use `yarn` directly because the test launches `zk` commands in both server and EN envs. # An empty topmost environment helps avoid a mess when redefining env vars shared between both envs # (e.g., DATABASE_URL). - run: ci_run yarn snapshot-recovery-test snapshot-recovery-test + run: ENABLE_CONSENSUS=${{ matrix.consensus }} PASSED_ENV_VARS=ENABLE_CONSENSUS ci_run yarn snapshot-recovery-test snapshot-recovery-test - name: Fee projection tests run: ci_run zk test i fees diff --git a/core/tests/revert-test/tests/revert-and-restart-en.test.ts b/core/tests/revert-test/tests/revert-and-restart-en.test.ts index 3ac0fc76d65..b43df82271e 100644 --- a/core/tests/revert-test/tests/revert-and-restart-en.test.ts +++ b/core/tests/revert-test/tests/revert-and-restart-en.test.ts @@ -92,14 +92,14 @@ class MainNode { // Spawns a main node. // if enableConsensus is set, consensus component will be started in the main node. - // if enable_execute is NOT set, main node will NOT send L1 transactions to execute L1 batches. + // if enableExecute is NOT set, main node will NOT send L1 transactions to execute L1 batches. public static async spawn( logs: fs.WriteStream, enableConsensus: boolean, - enable_execute: boolean + enableExecute: boolean ): Promise { let env = fetchEnv(mainEnv); - env.ETH_SENDER_SENDER_AGGREGATED_BLOCK_EXECUTE_DEADLINE = enable_execute ? '1' : '10000'; + env.ETH_SENDER_SENDER_AGGREGATED_BLOCK_EXECUTE_DEADLINE = enableExecute ? '1' : '10000'; // Set full mode for the Merkle tree as it is required to get blocks committed. env.DATABASE_MERKLE_TREE_MODE = 'full'; console.log(`DATABASE_URL = ${env.DATABASE_URL}`); diff --git a/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts b/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts index ff18c25d3b3..c1044909db6 100644 --- a/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts +++ b/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts @@ -215,7 +215,12 @@ describe('snapshot recovery', () => { step('initialize external node', async () => { externalNodeLogs = await fs.open('snapshot-recovery.log', 'w'); - externalNodeProcess = spawn('zk external-node -- --enable-snapshots-recovery', { + const enableConsensus = process.env.ENABLE_CONSENSUS === 'true'; + let args = ['external-node','--','--enable-snapshots-recovery']; + if (enableConsensus) { + args.push('--enable-consensus'); + } + externalNodeProcess = spawn('zk' , args, { cwd: homeDir, stdio: [null, externalNodeLogs.fd, externalNodeLogs.fd], shell: true, From 9d72caf4c5ed5aecb8491b237de668c3409e8aab Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 12:30:50 +0100 Subject: [PATCH 09/11] zk lint --- core/lib/zksync_core/src/utils/testonly.rs | 2 +- .../snapshot-recovery-test/tests/snapshot-recovery.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/utils/testonly.rs b/core/lib/zksync_core/src/utils/testonly.rs index 24e24b037b2..ed6fc713034 100644 --- a/core/lib/zksync_core/src/utils/testonly.rs +++ b/core/lib/zksync_core/src/utils/testonly.rs @@ -193,7 +193,7 @@ impl Snapshot { .into_iter() .map(|c| (c.hash, zksync_utils::be_words_to_bytes(&c.code))) .collect(), - storage_logs: storage_logs.iter().cloned().collect(), + storage_logs: storage_logs.to_vec(), } } } diff --git a/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts b/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts index c1044909db6..a24e5ee6ae7 100644 --- a/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts +++ b/core/tests/snapshot-recovery-test/tests/snapshot-recovery.test.ts @@ -216,11 +216,11 @@ describe('snapshot recovery', () => { externalNodeLogs = await fs.open('snapshot-recovery.log', 'w'); const enableConsensus = process.env.ENABLE_CONSENSUS === 'true'; - let args = ['external-node','--','--enable-snapshots-recovery']; + let args = ['external-node', '--', '--enable-snapshots-recovery']; if (enableConsensus) { args.push('--enable-consensus'); } - externalNodeProcess = spawn('zk' , args, { + externalNodeProcess = spawn('zk', args, { cwd: homeDir, stdio: [null, externalNodeLogs.fd, externalNodeLogs.fd], shell: true, From f37f182532663f8282ff033d66e5016191a42140 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Fri, 15 Mar 2024 17:11:06 +0100 Subject: [PATCH 10/11] applied comments --- core/lib/dal/src/consensus_dal.rs | 2 +- .../zksync_core/src/consensus/storage/mod.rs | 22 +++++++++++-------- core/lib/zksync_core/src/utils/testonly.rs | 1 + 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/lib/dal/src/consensus_dal.rs b/core/lib/dal/src/consensus_dal.rs index daf7997eee1..4f9c71ff331 100644 --- a/core/lib/dal/src/consensus_dal.rs +++ b/core/lib/dal/src/consensus_dal.rs @@ -114,7 +114,7 @@ impl ConsensusDal<'_, '_> { .await .context("get_sealed_miniblock_number")? .map_or(start, |last| validator::BlockNumber(last.0.into()).next()); - Ok(std::ops::Range { start, end }) + Ok(start..end) } /// [Main node only] creates a new consensus fork starting at diff --git a/core/lib/zksync_core/src/consensus/storage/mod.rs b/core/lib/zksync_core/src/consensus/storage/mod.rs index 76c51426ad2..7b8bac16bc8 100644 --- a/core/lib/zksync_core/src/consensus/storage/mod.rs +++ b/core/lib/zksync_core/src/consensus/storage/mod.rs @@ -292,14 +292,14 @@ impl PersistentBlockStore for BlockStore { .await .wrap("genesis()")? .context("genesis missing")?; - let first_cert = genesis.fork.first_block.max(block_range.start); + let first_expected_cert = genesis.fork.first_block.max(block_range.start); let last_cert = conn .last_certificate(ctx) .await .wrap("last_certificate()")?; - let next_cert = last_cert + let next_expected_cert = last_cert .as_ref() - .map_or(first_cert, |cert| cert.header().number.next()); + .map_or(first_expected_cert, |cert| cert.header().number.next()); // Check that the first certificate in storage has the expected miniblock number. if let Some(got) = conn @@ -307,17 +307,20 @@ impl PersistentBlockStore for BlockStore { .await .wrap("first_certificate()")? { - if got.header().number != first_cert { - return Err(anyhow::format_err!("inconsistent storage: certificates should start at {first_cert}, while they start at {}",got.header().number).into()); + if got.header().number != first_expected_cert { + return Err(anyhow::format_err!( + "inconsistent storage: certificates should start at {first_expected_cert}, while they start at {}", + got.header().number, + ).into()); } } // Check that the node has all the blocks before the next expected certificate, because // the node needs to know the state of the chain up to block `X` to process block `X+1`. - if block_range.end < next_cert { - return Err(anyhow::format_err!("inconsistent storage: cannot start consensus for miniblock {next_cert}, because earlier blocks are missing").into()); + if block_range.end < next_expected_cert { + return Err(anyhow::format_err!("inconsistent storage: cannot start consensus for miniblock {next_expected_cert}, because earlier blocks are missing").into()); } let state = BlockStoreState { - first: first_cert, + first: first_expected_cert, last: last_cert, }; Ok(state) @@ -436,10 +439,11 @@ impl PayloadManager for Store { ctx: &ctx::Ctx, block_number: validator::BlockNumber, ) -> ctx::Result { + const LARGE_PAYLOAD_SIZE: usize = 1 << 20; tracing::info!("proposing block {block_number}"); let payload = self.wait_for_payload(ctx, block_number).await?; let encoded_payload = payload.encode(); - if encoded_payload.0.len() > 1 << 20 { + if encoded_payload.0.len() > LARGE_PAYLOAD_SIZE { tracing::warn!( "large payload ({}B) with {} transactions", encoded_payload.0.len(), diff --git a/core/lib/zksync_core/src/utils/testonly.rs b/core/lib/zksync_core/src/utils/testonly.rs index ed6fc713034..35f3dbdfbe5 100644 --- a/core/lib/zksync_core/src/utils/testonly.rs +++ b/core/lib/zksync_core/src/utils/testonly.rs @@ -157,6 +157,7 @@ pub(crate) struct Snapshot { } impl Snapshot { + // Constructs a dummy Snapshot based on the provided values. pub fn make( l1_batch: L1BatchNumber, miniblock: MiniblockNumber, From 6a554e22960eec9b229581f02dad4c2ecc662fc2 Mon Sep 17 00:00:00 2001 From: Grzegorz Prusak Date: Mon, 18 Mar 2024 14:12:49 +0100 Subject: [PATCH 11/11] bumped consensus deps --- Cargo.lock | 22 +++++++++++----------- core/bin/external_node/Cargo.toml | 4 ++-- core/bin/zksync_server/Cargo.toml | 8 ++++---- core/lib/dal/Cargo.toml | 8 ++++---- core/lib/object_store/Cargo.toml | 2 +- core/lib/protobuf_config/Cargo.toml | 4 ++-- core/lib/types/Cargo.toml | 4 ++-- core/lib/zksync_core/Cargo.toml | 20 ++++++++++---------- prover/Cargo.lock | 14 +++++++------- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4e349cf653..5146cedaade 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7991,7 +7991,7 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "once_cell", @@ -8019,7 +8019,7 @@ dependencies = [ [[package]] name = "zksync_consensus_bft" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "async-trait", @@ -8040,7 +8040,7 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "blst", @@ -8058,7 +8058,7 @@ dependencies = [ [[package]] name = "zksync_consensus_executor" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "rand 0.8.5", @@ -8078,7 +8078,7 @@ dependencies = [ [[package]] name = "zksync_consensus_network" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "async-trait", @@ -8103,7 +8103,7 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "bit-vec", @@ -8123,7 +8123,7 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "async-trait", @@ -8141,7 +8141,7 @@ dependencies = [ [[package]] name = "zksync_consensus_sync_blocks" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "thiserror", @@ -8156,7 +8156,7 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "thiserror", "zksync_concurrency", @@ -8552,7 +8552,7 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "bit-vec", @@ -8570,7 +8570,7 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "heck 0.4.1", diff --git a/core/bin/external_node/Cargo.toml b/core/bin/external_node/Cargo.toml index 4f965a3789b..491e60b58fb 100644 --- a/core/bin/external_node/Cargo.toml +++ b/core/bin/external_node/Cargo.toml @@ -28,8 +28,8 @@ zksync_web3_decl = { path = "../../lib/web3_decl" } zksync_types = { path = "../../lib/types" } vlog = { path = "../../lib/vlog" } -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" } anyhow = "1.0" diff --git a/core/bin/zksync_server/Cargo.toml b/core/bin/zksync_server/Cargo.toml index 04450af5b6c..ad797c4e2b1 100644 --- a/core/bin/zksync_server/Cargo.toml +++ b/core/bin/zksync_server/Cargo.toml @@ -19,10 +19,10 @@ zksync_types = { path = "../../lib/types" } zksync_core = { path = "../../lib/zksync_core" } # Consensus dependenices -zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } vlog = { path = "../../lib/vlog" } anyhow = "1.0" diff --git a/core/lib/dal/Cargo.toml b/core/lib/dal/Cargo.toml index f0a2c76a697..e004a84e53e 100644 --- a/core/lib/dal/Cargo.toml +++ b/core/lib/dal/Cargo.toml @@ -18,9 +18,9 @@ zksync_system_constants = { path = "../constants" } zksync_contracts = { path = "../contracts" } zksync_types = { path = "../types" } zksync_health_check = { path = "../health_check" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } itertools = "0.10.1" thiserror = "1.0" @@ -55,4 +55,4 @@ chrono = { version = "0.4", features = ["serde"] } assert_matches = "1.5.0" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } diff --git a/core/lib/object_store/Cargo.toml b/core/lib/object_store/Cargo.toml index f0dbda7d250..771745b22e2 100644 --- a/core/lib/object_store/Cargo.toml +++ b/core/lib/object_store/Cargo.toml @@ -13,7 +13,7 @@ categories = ["cryptography"] vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" } zksync_config = { path = "../config" } zksync_types = { path = "../types" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } anyhow = "1.0" async-trait = "0.1" bincode = "1" diff --git a/core/lib/protobuf_config/Cargo.toml b/core/lib/protobuf_config/Cargo.toml index 99fbdc21c67..64b5d30c21c 100644 --- a/core/lib/protobuf_config/Cargo.toml +++ b/core/lib/protobuf_config/Cargo.toml @@ -16,7 +16,7 @@ serde_json = "1.0" serde_yaml = "0.9" zksync_basic_types = { path = "../basic_types" } zksync_config = { path = "../config" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } zksync_types = { path = "../types" } anyhow = "1.0" @@ -25,5 +25,5 @@ prost = "0.12.1" rand = "0.8" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } diff --git a/core/lib/types/Cargo.toml b/core/lib/types/Cargo.toml index 04e1ca8449e..77e2a4cf2d4 100644 --- a/core/lib/types/Cargo.toml +++ b/core/lib/types/Cargo.toml @@ -17,7 +17,7 @@ zksync_basic_types = { path = "../basic_types" } zksync_contracts = { path = "../contracts" } zksync_mini_merkle_tree = { path = "../mini_merkle_tree" } zksync_config = { path = "../config" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } anyhow = "1.0.75" chrono = { version = "0.4", features = ["serde"] } @@ -43,4 +43,4 @@ tokio = { version = "1", features = ["rt", "macros"] } serde_with = { version = "1", features = ["hex"] } [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index cee1cfa6df3..fc2d751c247 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -46,15 +46,15 @@ vlog = { path = "../vlog" } multivm = { path = "../multivm" } # Consensus dependenices -zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } -zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } +zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } prost = "0.12.1" serde = { version = "1.0", features = ["derive"] } @@ -103,4 +103,4 @@ tempfile = "3.0.2" test-casing = "0.1.2" [build-dependencies] -zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "2afdb723e40847afacfc0b2446a553d320c86cea" } +zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5329a809cfc06d4939fb5ece26c9ad1e1741c50a" } diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 3bc3f263174..2a2e361a9be 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -6936,7 +6936,7 @@ dependencies = [ [[package]] name = "zksync_concurrency" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "once_cell", @@ -6964,7 +6964,7 @@ dependencies = [ [[package]] name = "zksync_consensus_crypto" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "blst", @@ -6982,7 +6982,7 @@ dependencies = [ [[package]] name = "zksync_consensus_roles" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "bit-vec", @@ -7002,7 +7002,7 @@ dependencies = [ [[package]] name = "zksync_consensus_storage" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "async-trait", @@ -7020,7 +7020,7 @@ dependencies = [ [[package]] name = "zksync_consensus_utils" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "thiserror", "zksync_concurrency", @@ -7175,7 +7175,7 @@ dependencies = [ [[package]] name = "zksync_protobuf" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "bit-vec", @@ -7193,7 +7193,7 @@ dependencies = [ [[package]] name = "zksync_protobuf_build" version = "0.1.0" -source = "git+https://github.com/matter-labs/era-consensus.git?rev=2afdb723e40847afacfc0b2446a553d320c86cea#2afdb723e40847afacfc0b2446a553d320c86cea" +source = "git+https://github.com/matter-labs/era-consensus.git?rev=5329a809cfc06d4939fb5ece26c9ad1e1741c50a#5329a809cfc06d4939fb5ece26c9ad1e1741c50a" dependencies = [ "anyhow", "heck 0.4.1",