Skip to content

Commit 5919d2d

Browse files
committed
Inline slchain data
Signed-off-by: Danil <deniallugo@gmail.com>
1 parent ae40a93 commit 5919d2d

File tree

2 files changed

+20
-27
lines changed
  • core/node
    • eth_watch/src/tests
    • node_sync/src/tree_data_fetcher/provider

2 files changed

+20
-27
lines changed

core/node/eth_watch/src/tests/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use zksync_types::{
1616
ProtocolVersion, ProtocolVersionId, SLChainId, Transaction, H256, U256,
1717
};
1818

19-
use crate::{tests::client::MockEthClient, EthWatch};
19+
use crate::{tests::client::MockEthClient, EthWatch, ZkSyncExtentionEthClient};
2020

2121
mod client;
2222

@@ -97,10 +97,15 @@ async fn create_test_watcher(
9797
settlement_layer: SettlementLayer,
9898
) -> (EthWatch, MockEthClient, MockEthClient) {
9999
let l1_client = MockEthClient::new(SLChainId(42));
100-
let sl_client = MockEthClient::new(settlement_layer.chain_id());
100+
let sl_client = MockEthClient::new(SL_CHAIN_ID);
101+
let sl_l2_client: Box<dyn ZkSyncExtentionEthClient> = if settlement_layer.is_gateway() {
102+
Box::new(sl_client.clone())
103+
} else {
104+
Box::new(l1_client.clone())
105+
};
101106
let watcher = EthWatch::new(
102107
Box::new(l1_client.clone()),
103-
Box::new(sl_client.clone()),
108+
sl_l2_client,
104109
settlement_layer,
105110
connection_pool,
106111
std::time::Duration::from_nanos(1),

core/node/node_sync/src/tree_data_fetcher/provider/mod.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ struct PastL1BatchInfo {
9494
chain_id: SLChainId,
9595
}
9696

97-
#[derive(Debug)]
98-
struct SLChainAccess {
99-
client: Box<dyn EthInterface>,
100-
chain_id: SLChainId,
101-
diamond_proxy_addr: Address,
102-
}
103-
10497
/// Provider of tree data loading it from L1 `BlockCommit` events emitted by the diamond proxy contract.
10598
/// Should be used together with an L2 provider because L1 data can be missing for latest batches,
10699
/// and the provider implementation uses assumptions that can break in some corner cases.
@@ -113,7 +106,9 @@ struct SLChainAccess {
113106
/// (provided it's not too far behind the seal timestamp of the batch).
114107
#[derive(Debug)]
115108
pub(super) struct SLDataProvider {
116-
chain_data: SLChainAccess,
109+
client: Box<dyn EthInterface>,
110+
chain_id: SLChainId,
111+
diamond_proxy_addr: Address,
117112
block_commit_signature: H256,
118113
past_l1_batch: Option<PastL1BatchInfo>,
119114
}
@@ -130,17 +125,14 @@ impl SLDataProvider {
130125
l1_diamond_proxy_addr: Address,
131126
) -> anyhow::Result<Self> {
132127
let l1_chain_id = l1_client.fetch_chain_id().await?;
133-
let chain_data = SLChainAccess {
134-
client: l1_client,
135-
chain_id: l1_chain_id,
136-
diamond_proxy_addr: l1_diamond_proxy_addr,
137-
};
138128
let block_commit_signature = zksync_contracts::hyperchain_contract()
139129
.event("BlockCommit")
140130
.context("missing `BlockCommit` event")?
141131
.signature();
142132
Ok(Self {
143-
chain_data,
133+
client: l1_client,
134+
chain_id: l1_chain_id,
135+
diamond_proxy_addr: l1_diamond_proxy_addr,
144136
block_commit_signature,
145137
past_l1_batch: None,
146138
})
@@ -215,7 +207,7 @@ impl TreeDataProvider for SLDataProvider {
215207
info.number < number,
216208
"`batch_details()` must be called with monotonically increasing numbers"
217209
);
218-
if info.chain_id != self.chain_data.chain_id {
210+
if info.chain_id != self.chain_id {
219211
return None;
220212
}
221213
let threshold_timestamp = info.l1_commit_block_timestamp + Self::L1_BLOCK_RANGE.as_u64() / 2;
@@ -236,7 +228,7 @@ impl TreeDataProvider for SLDataProvider {
236228
Some(number) => number,
237229
None => {
238230
let (approximate_block, steps) = Self::guess_l1_commit_block_number(
239-
self.chain_data.client.as_ref(),
231+
self.client.as_ref(),
240232
l1_batch_seal_timestamp,
241233
)
242234
.await?;
@@ -254,7 +246,7 @@ impl TreeDataProvider for SLDataProvider {
254246

255247
let number_topic = H256::from_low_u64_be(number.0.into());
256248
let filter = web3::FilterBuilder::default()
257-
.address(vec![self.chain_data.diamond_proxy_addr])
249+
.address(vec![self.diamond_proxy_addr])
258250
.from_block(web3::BlockNumber::Number(from_block))
259251
.to_block(web3::BlockNumber::Number(from_block + Self::L1_BLOCK_RANGE))
260252
.topics(
@@ -264,7 +256,7 @@ impl TreeDataProvider for SLDataProvider {
264256
None,
265257
)
266258
.build();
267-
let mut logs = self.chain_data.client.logs(&filter).await?;
259+
let mut logs = self.client.logs(&filter).await?;
268260
logs.retain(|log| !log.is_removed() && log.block_number.is_some());
269261

270262
match logs.as_slice() {
@@ -285,11 +277,7 @@ impl TreeDataProvider for SLDataProvider {
285277
{diff} block(s) after the `from` block from the filter"
286278
);
287279

288-
let l1_commit_block = self
289-
.chain_data
290-
.client
291-
.block(l1_commit_block_number.into())
292-
.await?;
280+
let l1_commit_block = self.client.block(l1_commit_block_number.into()).await?;
293281
let l1_commit_block = l1_commit_block.ok_or_else(|| {
294282
let err = "Block disappeared from L1 RPC provider";
295283
EnrichedClientError::new(ClientError::Custom(err.into()), "batch_details")
@@ -299,7 +287,7 @@ impl TreeDataProvider for SLDataProvider {
299287
number,
300288
l1_commit_block_number,
301289
l1_commit_block_timestamp: l1_commit_block.timestamp,
302-
chain_id: self.chain_data.chain_id,
290+
chain_id: self.chain_id,
303291
});
304292
Ok(Ok(root_hash))
305293
}

0 commit comments

Comments
 (0)