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 eth sender layer (#1390)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## 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
90dee73
commit 0affdf8
Showing
11 changed files
with
204 additions
and
23 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
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
140 changes: 140 additions & 0 deletions
140
core/node/node_framework/src/implementations/layers/eth_sender.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,140 @@ | ||
use std::sync::Arc; | ||
|
||
use zksync_config::configs::{ | ||
chain::NetworkConfig, eth_sender::ETHSenderConfig, ContractsConfig, ETHClientConfig, | ||
}; | ||
use zksync_core::eth_sender::{Aggregator, EthTxAggregator, EthTxManager}; | ||
use zksync_eth_client::{clients::PKSigningClient, BoundEthInterface}; | ||
|
||
use crate::{ | ||
implementations::resources::{ | ||
eth_interface::BoundEthInterfaceResource, l1_tx_params::L1TxParamsResource, | ||
object_store::ObjectStoreResource, pools::MasterPoolResource, | ||
}, | ||
service::{ServiceContext, StopReceiver}, | ||
task::Task, | ||
wiring_layer::{WiringError, WiringLayer}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct EthSenderLayer { | ||
eth_sender_config: ETHSenderConfig, | ||
contracts_config: ContractsConfig, | ||
eth_client_config: ETHClientConfig, | ||
network_config: NetworkConfig, | ||
} | ||
|
||
impl EthSenderLayer { | ||
pub fn new( | ||
eth_sender_config: ETHSenderConfig, | ||
contracts_config: ContractsConfig, | ||
eth_client_config: ETHClientConfig, | ||
network_config: NetworkConfig, | ||
) -> Self { | ||
Self { | ||
eth_sender_config, | ||
contracts_config, | ||
eth_client_config, | ||
network_config, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl WiringLayer for EthSenderLayer { | ||
fn layer_name(&self) -> &'static str { | ||
"eth_sender_layer" | ||
} | ||
|
||
async fn wire(self: Box<Self>, mut context: ServiceContext<'_>) -> Result<(), WiringError> { | ||
// Get resources | ||
let pool_resource = context.get_resource::<MasterPoolResource>().await?; | ||
let pool = pool_resource.get().await.unwrap(); | ||
|
||
let eth_client = context.get_resource::<BoundEthInterfaceResource>().await?.0; | ||
|
||
let object_store = context.get_resource::<ObjectStoreResource>().await?.0; | ||
|
||
// Create and add tasks | ||
let eth_client_blobs = PKSigningClient::from_config_blobs( | ||
&self.eth_sender_config, | ||
&self.contracts_config, | ||
&self.eth_client_config, | ||
); | ||
let eth_client_blobs_addr = eth_client_blobs.clone().map(|k| k.sender_account()); | ||
|
||
let aggregator = Aggregator::new( | ||
self.eth_sender_config.sender.clone(), | ||
object_store, | ||
eth_client_blobs_addr.is_some(), | ||
self.eth_sender_config.sender.pubdata_sending_mode.into(), | ||
); | ||
|
||
let config = self.eth_sender_config.sender; | ||
|
||
let eth_tx_aggregator_actor = EthTxAggregator::new( | ||
pool.clone(), | ||
config.clone(), | ||
aggregator, | ||
eth_client.clone(), | ||
self.contracts_config.validator_timelock_addr, | ||
self.contracts_config.l1_multicall3_addr, | ||
self.contracts_config.diamond_proxy_addr, | ||
self.network_config.zksync_network_id, | ||
eth_client_blobs_addr, | ||
) | ||
.await; | ||
|
||
context.add_task(Box::new(EthTxAggregatorTask { | ||
eth_tx_aggregator_actor, | ||
})); | ||
|
||
let gas_adjuster = context.get_resource::<L1TxParamsResource>().await?.0; | ||
|
||
let eth_tx_manager_actor = EthTxManager::new( | ||
pool, | ||
config, | ||
gas_adjuster, | ||
eth_client, | ||
eth_client_blobs.map(|c| Arc::new(c) as Arc<dyn BoundEthInterface>), | ||
); | ||
|
||
context.add_task(Box::new(EthTxManagerTask { | ||
eth_tx_manager_actor, | ||
})); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
struct EthTxAggregatorTask { | ||
eth_tx_aggregator_actor: EthTxAggregator, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Task for EthTxAggregatorTask { | ||
fn name(&self) -> &'static str { | ||
"eth_tx_aggregator" | ||
} | ||
|
||
async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> { | ||
self.eth_tx_aggregator_actor.run(stop_receiver.0).await | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
struct EthTxManagerTask { | ||
eth_tx_manager_actor: EthTxManager, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Task for EthTxManagerTask { | ||
fn name(&self) -> &'static str { | ||
"eth_tx_manager" | ||
} | ||
|
||
async fn run(self: Box<Self>, stop_receiver: StopReceiver) -> anyhow::Result<()> { | ||
self.eth_tx_manager_actor.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
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
Oops, something went wrong.