diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index 49ba4129dfc5..5e07c3604b6c 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -39,8 +39,9 @@ pub struct MulticallData { /// Such as CommitBlocks, PublishProofBlocksOnchain and ExecuteBlock /// These eth_txs will be used as a queue for generating signed txs and send them later #[derive(Debug)] -pub struct EthTxAggregator { +pub struct EthTxAggregator { aggregator: Aggregator, + eth_client: E, config: SenderConfig, timelock_contract_address: Address, l1_multicall3_address: Address, @@ -49,10 +50,11 @@ pub struct EthTxAggregator { base_nonce: u64, } -impl EthTxAggregator { +impl EthTxAggregator { pub fn new( config: SenderConfig, aggregator: Aggregator, + eth_client: E, timelock_contract_address: Address, l1_multicall3_address: Address, main_zksync_contract_address: Address, @@ -62,6 +64,7 @@ impl EthTxAggregator { Self { config, aggregator, + eth_client, timelock_contract_address, l1_multicall3_address, main_zksync_contract_address, @@ -70,10 +73,9 @@ impl EthTxAggregator { } } - pub async fn run( + pub async fn run( mut self, pool: ConnectionPool, - eth_client: E, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { loop { @@ -84,7 +86,7 @@ impl EthTxAggregator { break; } - if let Err(err) = self.loop_iteration(&mut storage, ð_client).await { + if let Err(err) = self.loop_iteration(&mut storage).await { // Web3 API request failures can cause this, // and anything more important is already properly reported. tracing::warn!("eth_sender error {err:?}"); @@ -95,12 +97,10 @@ impl EthTxAggregator { Ok(()) } - pub(super) async fn get_multicall_data( - &mut self, - eth_client: &E, - ) -> Result { + pub(super) async fn get_multicall_data(&mut self) -> Result { let calldata = self.generate_calldata_for_multicall(); - let aggregate3_result = eth_client + let aggregate3_result = self + .eth_client .call_contract_function( &self.functions.aggregate3.name, calldata, @@ -293,9 +293,8 @@ impl EthTxAggregator { } /// Loads current verifier config on L1 - async fn get_recursion_scheduler_level_vk_hash( + async fn get_recursion_scheduler_level_vk_hash( &mut self, - eth_client: &E, verifier_address: Address, contracts_are_pre_boojum: bool, ) -> Result { @@ -313,7 +312,8 @@ impl EthTxAggregator { .collect(), ..Default::default() }; - let vk = eth_client + let vk = self + .eth_client .call_contract_function( &self.functions.get_verification_key.name, (), @@ -328,7 +328,8 @@ impl EthTxAggregator { } else { let get_vk_hash = self.functions.verification_key_hash.as_ref(); tracing::debug!("Calling verificationKeyHash"); - let vk_hash = eth_client + let vk_hash = self + .eth_client .call_contract_function( &get_vk_hash.unwrap().name, (), @@ -343,29 +344,24 @@ impl EthTxAggregator { } } - #[tracing::instrument(skip(self, storage, eth_client))] - async fn loop_iteration( + #[tracing::instrument(skip(self, storage))] + async fn loop_iteration( &mut self, storage: &mut StorageProcessor<'_>, - eth_client: &E, ) -> Result<(), ETHSenderError> { let MulticallData { base_system_contracts_hashes, verifier_params, verifier_address, protocol_version_id, - } = self.get_multicall_data(eth_client).await.map_err(|err| { + } = self.get_multicall_data().await.map_err(|err| { tracing::error!("Failed to get multicall data {err:?}"); err })?; let contracts_are_pre_boojum = protocol_version_id.is_pre_boojum(); let recursion_scheduler_level_vk_hash = self - .get_recursion_scheduler_level_vk_hash( - eth_client, - verifier_address, - contracts_are_pre_boojum, - ) + .get_recursion_scheduler_level_vk_hash(verifier_address, contracts_are_pre_boojum) .await .map_err(|err| { tracing::error!("Failed to get VK hash from the Verifier {err:?}"); diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs index 2ef9ea87a7c7..0d219b38da43 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs @@ -48,18 +48,21 @@ pub(super) struct L1BlockNumbers { /// Based on eth_tx_history queue the component can mark txs as stuck and create the new attempt /// with higher gas price #[derive(Debug)] -pub struct EthTxManager { +pub struct EthTxManager { ethereum_gateway: E, config: SenderConfig, - gas_adjuster: Arc, + gas_adjuster: Arc, } -impl EthTxManager +impl EthTxManager where E: BoundEthInterface + Sync, - G: L1TxParamsProvider, { - pub fn new(config: SenderConfig, gas_adjuster: Arc, ethereum_gateway: E) -> Self { + pub fn new( + config: SenderConfig, + gas_adjuster: Arc, + ethereum_gateway: E, + ) -> Self { Self { ethereum_gateway, config, diff --git a/core/lib/zksync_core/src/eth_sender/tests.rs b/core/lib/zksync_core/src/eth_sender/tests.rs index 01781a424f5c..b563cf0443e7 100644 --- a/core/lib/zksync_core/src/eth_sender/tests.rs +++ b/core/lib/zksync_core/src/eth_sender/tests.rs @@ -30,7 +30,7 @@ use crate::{ }; // Alias to conveniently call static methods of ETHSender. -type MockEthTxManager = EthTxManager, GasAdjuster>>; +type MockEthTxManager = EthTxManager>; static DUMMY_OPERATION: Lazy = Lazy::new(|| { AggregatedOperation::Execute(L1BatchExecuteOperation { @@ -53,7 +53,7 @@ struct EthSenderTester { conn: ConnectionPool, gateway: Arc, manager: MockEthTxManager, - aggregator: EthTxAggregator, + aggregator: EthTxAggregator>, gas_adjuster: Arc>>, } @@ -113,6 +113,7 @@ impl EthSenderTester { aggregator_config.clone(), store_factory.create_store().await, ), + gateway.clone(), // zkSync contract address Address::random(), contracts_config.l1_multicall3_addr, @@ -859,7 +860,7 @@ async fn test_parse_multicall_data() { async fn get_multicall_data() { let connection_pool = ConnectionPool::test_pool().await; let mut tester = EthSenderTester::new(connection_pool, vec![100; 100], false).await; - let multicall_data = tester.aggregator.get_multicall_data(&tester.gateway).await; + let multicall_data = tester.aggregator.get_multicall_data().await; assert!(multicall_data.is_ok()); } diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index d44f62efda6b..133814c0abaa 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -558,16 +558,15 @@ pub async fn initialize_components( eth_sender.sender.clone(), store_factory.create_store().await, ), + eth_client, contracts_config.validator_timelock_addr, contracts_config.l1_multicall3_addr, main_zksync_contract_address, nonce.as_u64(), ); - task_futures.push(tokio::spawn(eth_tx_aggregator_actor.run( - eth_sender_pool, - eth_client, - stop_receiver.clone(), - ))); + task_futures.push(tokio::spawn( + eth_tx_aggregator_actor.run(eth_sender_pool, stop_receiver.clone()), + )); let elapsed = started_at.elapsed(); APP_METRICS.init_latency[&InitStage::EthTxAggregator].set(elapsed); tracing::info!("initialized ETH-TxAggregator in {elapsed:?}");