Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node-framework): Add commitment generator layer #1402

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/node/node_framework/examples/main_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use zksync_core::{
use zksync_env_config::FromEnv;
use zksync_node_framework::{
implementations::layers::{
commitment_generator::CommitmentGeneratorLayer,
eth_watch::EthWatchLayer,
fee_input::SequencerFeeInputLayer,
healtcheck_server::HealthCheckLayer,
Expand Down Expand Up @@ -237,6 +238,12 @@ impl MainNodeBuilder {
Ok(self)
}

fn add_commitment_generator_layer(mut self) -> anyhow::Result<Self> {
self.node.add_layer(CommitmentGeneratorLayer);

Ok(self)
}

fn build(self) -> ZkStackService {
self.node
}
Expand Down Expand Up @@ -267,6 +274,7 @@ fn main() -> anyhow::Result<()> {
.add_tree_api_client_layer()?
.add_http_web3_api_layer()?
.add_ws_web3_api_layer()?
.add_commitment_generator_layer()?
.build()
.run()?;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use zksync_core::commitment_generator::CommitmentGenerator;

use crate::{
implementations::resources::{healthcheck::AppHealthCheckResource, pools::MasterPoolResource},
service::{ServiceContext, StopReceiver},
task::Task,
wiring_layer::{WiringError, WiringLayer},
};

pub struct CommitmentGeneratorLayer;

#[async_trait::async_trait]
impl WiringLayer for CommitmentGeneratorLayer {
fn layer_name(&self) -> &'static str {
"commitment_generator_layer"
}

async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> {
let pool_resource = context.get_resource::<MasterPoolResource>().await?;
let main_pool = pool_resource.get().await.unwrap();

let commitment_generator = CommitmentGenerator::new(main_pool);

let AppHealthCheckResource(app_health) = context.get_resource_or_default().await;
app_health.insert_component(commitment_generator.health_check());

context.add_task(Box::new(CommitmentGeneratorTask {
commitment_generator,
}));

Ok(())
}
}

#[derive(Debug)]
struct CommitmentGeneratorTask {
commitment_generator: CommitmentGenerator,
}

#[async_trait::async_trait]
impl Task for CommitmentGeneratorTask {
fn name(&self) -> &'static str {
"commitment_generator"
}

async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> {
self.commitment_generator.run(stop_receiver.0).await
}
}
1 change: 1 addition & 0 deletions core/node/node_framework/src/implementations/layers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod commitment_generator;
pub mod eth_watch;
pub mod fee_input;
pub mod healtcheck_server;
Expand Down
Loading