Skip to content

Commit

Permalink
feat: block revert support for consensus component (matter-labs#1213)
Browse files Browse the repository at this point in the history
Reverting blocks in the main node translates to a hard fork of the
consensus blockchain.
This means that every time block reverter is executed, the state of the
consensus has to be reset (aka forked).
To achieve that a `Genesis` of the consensus is introduced. Among other
things, it specifies the number of the fork (incremented at every
forking) and the miniblock number that the fork should start from (set
to the last sealed miniblock at the time of forking). External node
learns the current Genesis from the main node via jsonrpc (eventually
Genesis should be moved to L1 contract, so that hard forks are managed
by governance).

Consensus doesn't support yet synchronization of blocks before the
Genesis first block, therefore for now external node is using jsonrpc
for syncing the blocks before genesis first block.

Fixes BFT-420
  • Loading branch information
pompon0 authored Mar 8, 2024
1 parent f904f6d commit 8a3a938
Show file tree
Hide file tree
Showing 60 changed files with 2,012 additions and 1,825 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ jobs:
integration:
name: Integration (consensus=${{ matrix.consensus }})
strategy:
# In matrix jobs, fail-fast is true by default.
# To be consistent with the rest of the workflow we disable it explicitly.
fail-fast: false
matrix:
consensus: [false, true]
env:
Expand Down Expand Up @@ -252,6 +255,7 @@ jobs:
external-node:
name: External node (consensus=${{ matrix.consensus }})
strategy:
fail-fast: false
matrix:
consensus: [false, true]
runs-on: [matterlabs-ci-runner]
Expand Down Expand Up @@ -291,33 +295,24 @@ jobs:
# `sleep 30` because we need to wait until server started properly
- name: Run server
run: |
ci_run zk server --components=$SERVER_COMPONENTS &>server.log &
ci_run zk server --components=$SERVER_COMPONENTS &>>server.log &
ci_run sleep 30
- name: Run external node
run: |
ci_run zk env ext-node-docker
ci_run zk db setup
ci_run zk external-node $EXT_NODE_FLAGS &>ext-node.log &
ci_run zk external-node $EXT_NODE_FLAGS &>>ext-node.log &
ci_run sleep 30
- name: Integration tests
run: ci_run zk test i server --testPathIgnorePatterns 'contract-verification|snapshots-creator'

- name: Run revert test
run: |
ci_run zk env
ci_run zk env docker
ci_run pkill zksync_server || true
ci_run sleep 2
ci_run zk env
ENABLE_CONSENSUS=${{ matrix.consensus }} PASSED_ENV_VARS=ENABLE_CONSENSUS ci_run zk test i revert
# Check that the rollback was performed on the EN
ci_run sleep 20
ci_run grep -q 'Rollback successfully completed' ext-node.log
# Restart the EN
ci_run zk server --components=$SERVER_COMPONENTS &>>server.log &
ci_run sleep 30
ENABLE_CONSENSUS=${{ matrix.consensus }} PASSED_ENV_VARS=ENABLE_CONSENSUS ci_run zk test i revert-en
# test terminates the nodes, so we restart them.
ZKSYNC_ENV=docker ci_run zk server --components=$SERVER_COMPONENTS &>>server.log &
ZKSYNC_ENV=ext-node-docker ci_run zk external-node $EXT_NODE_FLAGS &>>ext-node.log &
ci_run sleep 30
Expand All @@ -338,9 +333,13 @@ jobs:
if: always()
run: ci_run cat ext-node.log || true

- name: Show revert.log logs
- name: Show revert_main.log logs
if: always()
run: ci_run cat core/tests/revert-test/revert.log || true
run: ci_run cat core/tests/revert-test/revert_main.log || true

- name: Show revert_ext.log logs
if: always()
run: ci_run cat core/tests/revert-test/revert_ext.log || true

- name: Show upgrade.log logs
if: always()
Expand Down
23 changes: 12 additions & 11 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,4 @@ balancer
lookups
stateful
WIP
p2p
4 changes: 3 additions & 1 deletion core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_config::{
PostgresConfig,
};
use zksync_core::block_reverter::{
BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert,
BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert, NodeRole,
};
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
Expand Down Expand Up @@ -104,6 +104,7 @@ async fn main() -> anyhow::Result<()> {
.await
.context("failed to build a connection pool")?;
let mut block_reverter = BlockReverter::new(
NodeRole::Main,
db_config.state_keeper_db_path,
db_config.merkle_tree.path,
Some(config),
Expand Down Expand Up @@ -182,6 +183,7 @@ async fn main() -> anyhow::Result<()> {
if rollback_sk_cache {
flags |= BlockReverterFlags::SK_CACHE;
}

block_reverter
.rollback_db(L1BatchNumber(l1_batch_number), flags)
.await
Expand Down
5 changes: 3 additions & 2 deletions core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ zksync_state = { path = "../../lib/state" }
zksync_basic_types = { path = "../../lib/basic_types" }
zksync_contracts = { path = "../../lib/contracts" }
zksync_l1_contract_interface = { path = "../../lib/l1_contract_interface" }
zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "97d139969476a004c50f8b4a31ece748e5bee14e" }
zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "97d139969476a004c50f8b4a31ece748e5bee14e" }
zksync_snapshots_applier = { path = "../../lib/snapshots_applier" }
zksync_object_store = { path="../../lib/object_store" }
prometheus_exporter = { path = "../../lib/prometheus_exporter" }
zksync_health_check = { path = "../../lib/health_check" }
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" }
vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" }

anyhow = "1.0"
Expand Down
Loading

0 comments on commit 8a3a938

Please sign in to comment.