-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 Main Node Client layer (#2132)
Note: healthchecks for `Main Node` and `Eth` client layers will be added in the next PR(there is a general principle of change.) ## 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`.
- Loading branch information
1 parent
f179681
commit 927d842
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
core/node/node_framework/src/implementations/layers/main_node_client.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,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(()) | ||
} | ||
} |
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