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#2357) ## What ❔ * Renames `FetcherTask` to `ExternalNodeTask` * Moves `run_main_node` to `mn::run_main_node` to match `en::run_external_node` * Splits `consensus::storage` into `consensus::storage::connection` and `consensus::storage::store` ## Why ❔ I'm working on matter-labs#2340 where I made these changes either because the naming was confusing or the module was getting very long and I thought it would make it easier to have it in two before adding more trait implementations to it. The PR was getting huge even before I did any actual work, so I decided to make a pure refactoring PR to make the other one easier to review later. ## 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`.
- Loading branch information
Showing
13 changed files
with
743 additions
and
703 deletions.
There are no files selected for viewing
Submodule contracts
updated
2 files
+0 −2 | l1-contracts/deploy-script-config-template/config-deploy-erc20.toml | |
+8 −15 | l1-contracts/deploy-scripts/DeployErc20.s.sol |
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.