Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-framework): Add consistency checker (#1527)
## What ❔ Consistency-checker component is the component used by EN, so this PR is the first step of porting EN to the framework. ## Why ❔ step-by-step porting EN to framework ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`.
- Loading branch information
1 parent
5899bc6
commit 3c28c25
Showing
8 changed files
with
152 additions
and
4 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
85 changes: 85 additions & 0 deletions
85
core/node/node_framework/src/implementations/layers/consistency_checker.rs
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,85 @@ | ||
use zksync_core::consistency_checker::ConsistencyChecker; | ||
use zksync_types::Address; | ||
|
||
use crate::{ | ||
implementations::resources::{ | ||
eth_interface::EthInterfaceResource, healthcheck::AppHealthCheckResource, | ||
l1_batch_commit_data_generator::L1BatchCommitDataGeneratorResource, | ||
pools::MasterPoolResource, | ||
}, | ||
service::{ServiceContext, StopReceiver}, | ||
task::Task, | ||
wiring_layer::{WiringError, WiringLayer}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct ConsistencyCheckerLayer { | ||
diamond_proxy_addr: Address, | ||
max_batches_to_recheck: u32, | ||
} | ||
|
||
impl ConsistencyCheckerLayer { | ||
pub fn new( | ||
diamond_proxy_addr: Address, | ||
max_batches_to_recheck: u32, | ||
) -> ConsistencyCheckerLayer { | ||
Self { | ||
diamond_proxy_addr, | ||
max_batches_to_recheck, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for ConsistencyCheckerLayer { | ||
fn layer_name(&self) -> &'static str { | ||
"consistency_checker_layer" | ||
} | ||
|
||
async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> { | ||
// Get resources. | ||
let l1_client = context.get_resource::<EthInterfaceResource>().await?.0; | ||
|
||
let pool_resource = context.get_resource::<MasterPoolResource>().await?; | ||
let singleton_pool = pool_resource.get_singleton().await?; | ||
|
||
let l1_batch_commit_data_generator = context | ||
.get_resource::<L1BatchCommitDataGeneratorResource>() | ||
.await? | ||
.0; | ||
|
||
let consistency_checker = ConsistencyChecker::new( | ||
l1_client, | ||
self.max_batches_to_recheck, | ||
singleton_pool, | ||
l1_batch_commit_data_generator, | ||
) | ||
.map_err(WiringError::Internal)? | ||
.with_diamond_proxy_addr(self.diamond_proxy_addr); | ||
|
||
let AppHealthCheckResource(app_health) = context.get_resource_or_default().await; | ||
app_health.insert_component(consistency_checker.health_check().clone()); | ||
|
||
// Create and add tasks. | ||
context.add_task(Box::new(ConsistencyCheckerTask { | ||
consistency_checker, | ||
})); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub struct ConsistencyCheckerTask { | ||
consistency_checker: ConsistencyChecker, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Task for ConsistencyCheckerTask { | ||
fn name(&self) -> &'static str { | ||
"consistency_checker" | ||
} | ||
|
||
async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> { | ||
self.consistency_checker.run(stop_receiver.0).await | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
core/node/node_framework/src/implementations/layers/l1_batch_commit_data_generator.rs
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,46 @@ | ||
use std::sync::Arc; | ||
|
||
use zksync_config::configs::chain::L1BatchCommitDataGeneratorMode; | ||
use zksync_core::eth_sender::l1_batch_commit_data_generator::{ | ||
L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, | ||
ValidiumModeL1BatchCommitDataGenerator, | ||
}; | ||
|
||
use crate::{ | ||
implementations::resources::l1_batch_commit_data_generator::L1BatchCommitDataGeneratorResource, | ||
service::ServiceContext, | ||
wiring_layer::{WiringError, WiringLayer}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct L1BatchCommitDataGeneratorLayer { | ||
mode: L1BatchCommitDataGeneratorMode, | ||
} | ||
|
||
impl L1BatchCommitDataGeneratorLayer { | ||
pub fn new(mode: L1BatchCommitDataGeneratorMode) -> Self { | ||
Self { mode } | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for L1BatchCommitDataGeneratorLayer { | ||
fn layer_name(&self) -> &'static str { | ||
"l1_batch_commit_data_generator" | ||
} | ||
|
||
async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> { | ||
let l1_batch_commit_data_generator: Arc<dyn L1BatchCommitDataGenerator> = match self.mode { | ||
L1BatchCommitDataGeneratorMode::Rollup => { | ||
Arc::new(RollupModeL1BatchCommitDataGenerator {}) | ||
} | ||
L1BatchCommitDataGeneratorMode::Validium => { | ||
Arc::new(ValidiumModeL1BatchCommitDataGenerator {}) | ||
} | ||
}; | ||
context.insert_resource(L1BatchCommitDataGeneratorResource( | ||
l1_batch_commit_data_generator, | ||
))?; | ||
Ok(()) | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
core/node/node_framework/src/implementations/resources/l1_batch_commit_data_generator.rs
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,14 @@ | ||
use std::sync::Arc; | ||
|
||
use zksync_core::eth_sender::l1_batch_commit_data_generator::L1BatchCommitDataGenerator; | ||
|
||
use crate::resource::{Resource, ResourceId}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct L1BatchCommitDataGeneratorResource(pub Arc<dyn L1BatchCommitDataGenerator>); | ||
|
||
impl Resource for L1BatchCommitDataGeneratorResource { | ||
fn resource_id() -> ResourceId { | ||
"common/l1_batch_commit_data_generator".into() | ||
} | ||
} |
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