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 Main Node Client layer #2132

Merged
merged 1 commit into from
Jun 4, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::num::NonZeroUsize;

use anyhow::Context;
use zksync_types::{url::SensitiveUrl, L2ChainId};
use zksync_web3_decl::client::{Client, DynClient, L2};

use crate::{
implementations::resources::main_node_client::MainNodeClientResource,
service::ServiceContext,
wiring_layer::{WiringError, WiringLayer},
};

#[derive(Debug)]
pub struct MainNodeClientLayer {
url: SensitiveUrl,
rate_limit_rps: NonZeroUsize,
l2_chain_id: L2ChainId,
}

impl MainNodeClientLayer {
pub fn new(url: SensitiveUrl, rate_limit_rps: NonZeroUsize, l2_chain_id: L2ChainId) -> Self {
Self {
url,
rate_limit_rps,
l2_chain_id,
}
}
}

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

async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> {
let main_node_client = Client::http(self.url)
.context("failed creating JSON-RPC client for main node")?
.for_network(self.l2_chain_id.into())
.with_allowed_requests_per_second(self.rate_limit_rps)
.build();

context.insert_resource(MainNodeClientResource(
Box::new(main_node_client) as Box<DynClient<L2>>
))?;
Ok(())
}
}
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
Expand Up @@ -8,6 +8,7 @@ pub mod eth_watch;
pub mod healtcheck_server;
pub mod house_keeper;
pub mod l1_gas;
pub mod main_node_client;
pub mod metadata_calculator;
pub mod object_store;
pub mod pk_signing_eth_client;
Expand Down
Loading