-
Notifications
You must be signed in to change notification settings - Fork 2k
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): Support Eth Watch in the framework (#1145)
## What ❔ - Small change in the `EthWatch` component. Now `Eth Watch` 's `pool` field is used instead of `ConnectionPool` passed in the Eth Watch's `run()` method. - Adds `Eth Watch` implementation, i. e. `EthWatchLayer` and `EthWatchTask`, in the same way it was done for `StateKeeper ` [here](https://github.com/matter-labs/zksync-era/pull/1043/files#diff-8ff8babf7b83c79dbf96f4998cf71d888beaeb265c7ce33192b0bb0c808f662b). Current "external" point of view for the framework(the only thing changed is that we add ` .add_eth_watch_layer()?` after `.add_state_keeper_layer()?`): ```rust fn main() -> anyhow::Result<()> { #[allow(deprecated)] // TODO (QIT-21): Use centralized configuration approach. let log_format = vlog::log_format_from_env(); let _guard = vlog::ObservabilityBuilder::new() .with_log_format(log_format) .build(); MainNodeBuilder::new() .add_pools_layer()? .add_fee_input_layer()? .add_object_store_layer()? .add_metadata_calculator_layer()? .add_state_keeper_layer()? .add_eth_watch_layer()? .add_healthcheck_layer()? .build() .run()?; Ok(()) } ```
- Loading branch information
1 parent
e75aa11
commit 4f41b68
Showing
8 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
88 changes: 88 additions & 0 deletions
88
core/node/node_framework/src/implementations/layers/eth_watch.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,88 @@ | ||
use std::time::Duration; | ||
|
||
use zksync_config::{ContractsConfig, ETHWatchConfig}; | ||
use zksync_contracts::governance_contract; | ||
use zksync_core::eth_watch::{client::EthHttpQueryClient, EthWatch}; | ||
use zksync_dal::ConnectionPool; | ||
use zksync_types::{ethabi::Contract, Address}; | ||
|
||
use crate::{ | ||
implementations::resources::{eth_interface::EthInterfaceResource, pools::MasterPoolResource}, | ||
service::{ServiceContext, StopReceiver}, | ||
task::Task, | ||
wiring_layer::{WiringError, WiringLayer}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct EthWatchLayer { | ||
eth_watch_config: ETHWatchConfig, | ||
contracts_config: ContractsConfig, | ||
} | ||
|
||
impl EthWatchLayer { | ||
pub fn new(eth_watch_config: ETHWatchConfig, contracts_config: ContractsConfig) -> Self { | ||
Self { | ||
eth_watch_config, | ||
contracts_config, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for EthWatchLayer { | ||
fn layer_name(&self) -> &'static str { | ||
"eth_watch_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 client = context.get_resource::<EthInterfaceResource>().await?.0; | ||
|
||
let eth_client = EthHttpQueryClient::new( | ||
client, | ||
self.contracts_config.diamond_proxy_addr, | ||
Some(self.contracts_config.governance_addr), | ||
self.eth_watch_config.confirmations_for_eth_event, | ||
); | ||
context.add_task(Box::new(EthWatchTask { | ||
main_pool, | ||
client: eth_client, | ||
governance_contract: Some(governance_contract()), | ||
diamond_proxy_address: self.contracts_config.diamond_proxy_addr, | ||
poll_interval: self.eth_watch_config.poll_interval(), | ||
})); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
struct EthWatchTask { | ||
main_pool: ConnectionPool, | ||
client: EthHttpQueryClient, | ||
governance_contract: Option<Contract>, | ||
diamond_proxy_address: Address, | ||
poll_interval: Duration, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Task for EthWatchTask { | ||
fn name(&self) -> &'static str { | ||
"eth_watch" | ||
} | ||
|
||
async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> { | ||
let eth_watch = EthWatch::new( | ||
self.diamond_proxy_address, | ||
self.governance_contract, | ||
Box::new(self.client), | ||
self.main_pool, | ||
self.poll_interval, | ||
) | ||
.await; | ||
|
||
eth_watch.run(stop_receiver.0).await | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod eth_watch; | ||
pub mod fee_input; | ||
pub mod healtcheck_server; | ||
pub mod metadata_calculator; | ||
|
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