This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Rename consensus tasks and split storage (BFT-476) (matter-…
…labs#2366) ## What ❔ This is a 2nd attempt at matter-labs#2357 to redo it after matter-labs#2364 has reverted it. The fix was cherry picked from matter-labs#2365 ## Why ❔ The other PR accidentally changed the contracts submodule. ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Co-authored-by: matias-gonz <[email protected]>
- Loading branch information
Showing
12 changed files
with
742 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use anyhow::Context as _; | ||
use zksync_concurrency::{ctx, error::Wrap as _, scope}; | ||
use zksync_config::configs::consensus::{ConsensusConfig, ConsensusSecrets}; | ||
use zksync_consensus_executor::{self as executor}; | ||
use zksync_consensus_roles::validator; | ||
use zksync_consensus_storage::{BatchStore, BlockStore}; | ||
|
||
use crate::{ | ||
config, | ||
storage::{ConnectionPool, Store}, | ||
}; | ||
|
||
/// Task running a consensus validator for the main node. | ||
/// Main node is currently the only leader of the consensus - i.e. it proposes all the | ||
/// L2 blocks (generated by `Statekeeper`). | ||
pub async fn run_main_node( | ||
ctx: &ctx::Ctx, | ||
cfg: ConsensusConfig, | ||
secrets: ConsensusSecrets, | ||
pool: ConnectionPool, | ||
) -> anyhow::Result<()> { | ||
let validator_key = config::validator_key(&secrets) | ||
.context("validator_key")? | ||
.context("missing validator_key")?; | ||
|
||
scope::run!(&ctx, |ctx, s| async { | ||
if let Some(spec) = &cfg.genesis_spec { | ||
let spec = config::GenesisSpec::parse(spec).context("GenesisSpec::parse()")?; | ||
|
||
pool.connection(ctx) | ||
.await | ||
.wrap("connection()")? | ||
.adjust_genesis(ctx, &spec) | ||
.await | ||
.wrap("adjust_genesis()")?; | ||
} | ||
|
||
let (store, runner) = Store::new(ctx, pool, None).await.wrap("Store::new()")?; | ||
s.spawn_bg(runner.run(ctx)); | ||
|
||
let (block_store, runner) = BlockStore::new(ctx, Box::new(store.clone())) | ||
.await | ||
.wrap("BlockStore::new()")?; | ||
s.spawn_bg(runner.run(ctx)); | ||
|
||
anyhow::ensure!( | ||
block_store.genesis().leader_selection | ||
== validator::LeaderSelectionMode::Sticky(validator_key.public()), | ||
"unsupported leader selection mode - main node has to be the leader" | ||
); | ||
|
||
// Dummy batch store - we don't gossip batches yet, but we need one anyway. | ||
let (batch_store, runner) = BatchStore::new(ctx, Box::new(store.clone())) | ||
.await | ||
.wrap("BatchStore::new()")?; | ||
s.spawn_bg(async { runner.run(ctx).await.context("BatchStore::runner()") }); | ||
|
||
let executor = executor::Executor { | ||
config: config::executor(&cfg, &secrets)?, | ||
block_store, | ||
batch_store, | ||
attester: None, | ||
validator: Some(executor::Validator { | ||
key: validator_key, | ||
replica_store: Box::new(store.clone()), | ||
payload_manager: Box::new(store.clone()), | ||
}), | ||
}; | ||
executor.run(ctx).await | ||
}) | ||
.await | ||
} |
Oops, something went wrong.