Skip to content

Commit

Permalink
feat(eth_sender): Remove generic bounds on L1TxParamsProvider in EthS…
Browse files Browse the repository at this point in the history
…ender (#799)

## What ❔

Follow-up to #792 

## Why ❔

Same reasons

## 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 `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
popzxc authored Jan 3, 2024
1 parent c83db35 commit 29a4f52
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
42 changes: 19 additions & 23 deletions core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> {
aggregator: Aggregator,
eth_client: E,
config: SenderConfig,
timelock_contract_address: Address,
l1_multicall3_address: Address,
Expand All @@ -49,10 +50,11 @@ pub struct EthTxAggregator {
base_nonce: u64,
}

impl EthTxAggregator {
impl<E: BoundEthInterface> EthTxAggregator<E> {
pub fn new(
config: SenderConfig,
aggregator: Aggregator,
eth_client: E,
timelock_contract_address: Address,
l1_multicall3_address: Address,
main_zksync_contract_address: Address,
Expand All @@ -62,6 +64,7 @@ impl EthTxAggregator {
Self {
config,
aggregator,
eth_client,
timelock_contract_address,
l1_multicall3_address,
main_zksync_contract_address,
Expand All @@ -70,10 +73,9 @@ impl EthTxAggregator {
}
}

pub async fn run<E: BoundEthInterface>(
pub async fn run(
mut self,
pool: ConnectionPool,
eth_client: E,
stop_receiver: watch::Receiver<bool>,
) -> anyhow::Result<()> {
loop {
Expand All @@ -84,7 +86,7 @@ impl EthTxAggregator {
break;
}

if let Err(err) = self.loop_iteration(&mut storage, &eth_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:?}");
Expand All @@ -95,12 +97,10 @@ impl EthTxAggregator {
Ok(())
}

pub(super) async fn get_multicall_data<E: BoundEthInterface>(
&mut self,
eth_client: &E,
) -> Result<MulticallData, ETHSenderError> {
pub(super) async fn get_multicall_data(&mut self) -> Result<MulticallData, ETHSenderError> {
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,
Expand Down Expand Up @@ -293,9 +293,8 @@ impl EthTxAggregator {
}

/// Loads current verifier config on L1
async fn get_recursion_scheduler_level_vk_hash<E: BoundEthInterface>(
async fn get_recursion_scheduler_level_vk_hash(
&mut self,
eth_client: &E,
verifier_address: Address,
contracts_are_pre_boojum: bool,
) -> Result<H256, ETHSenderError> {
Expand All @@ -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,
(),
Expand All @@ -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,
(),
Expand All @@ -343,29 +344,24 @@ impl EthTxAggregator {
}
}

#[tracing::instrument(skip(self, storage, eth_client))]
async fn loop_iteration<E: BoundEthInterface>(
#[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:?}");
Expand Down
13 changes: 8 additions & 5 deletions core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E, G> {
pub struct EthTxManager<E> {
ethereum_gateway: E,
config: SenderConfig,
gas_adjuster: Arc<G>,
gas_adjuster: Arc<dyn L1TxParamsProvider>,
}

impl<E, G> EthTxManager<E, G>
impl<E> EthTxManager<E>
where
E: BoundEthInterface + Sync,
G: L1TxParamsProvider,
{
pub fn new(config: SenderConfig, gas_adjuster: Arc<G>, ethereum_gateway: E) -> Self {
pub fn new(
config: SenderConfig,
gas_adjuster: Arc<dyn L1TxParamsProvider>,
ethereum_gateway: E,
) -> Self {
Self {
ethereum_gateway,
config,
Expand Down
7 changes: 4 additions & 3 deletions core/lib/zksync_core/src/eth_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
};

// Alias to conveniently call static methods of ETHSender.
type MockEthTxManager = EthTxManager<Arc<MockEthereum>, GasAdjuster<Arc<MockEthereum>>>;
type MockEthTxManager = EthTxManager<Arc<MockEthereum>>;

static DUMMY_OPERATION: Lazy<AggregatedOperation> = Lazy::new(|| {
AggregatedOperation::Execute(L1BatchExecuteOperation {
Expand All @@ -53,7 +53,7 @@ struct EthSenderTester {
conn: ConnectionPool,
gateway: Arc<MockEthereum>,
manager: MockEthTxManager,
aggregator: EthTxAggregator,
aggregator: EthTxAggregator<Arc<MockEthereum>>,
gas_adjuster: Arc<GasAdjuster<Arc<MockEthereum>>>,
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}

Expand Down
9 changes: 4 additions & 5 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down

0 comments on commit 29a4f52

Please sign in to comment.