Skip to content

Commit c957dd8

Browse files
authored
fix(eth_watch): fix get_events_inner (#2882)
## What ❔ - `get_events_inner` should recursively call itself - `get_events_inner` should allow passing `None` as topics and/or addresses ## Why ❔ bug fix ## 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`.
1 parent b894039 commit c957dd8

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ categories = ["cryptography"]
105105
anyhow = "1"
106106
assert_matches = "1.5"
107107
async-trait = "0.1"
108+
async-recursion = "1"
108109
axum = "0.7.5"
109110
backon = "0.4.4"
110111
bigdecimal = "0.4.5"

core/node/eth_watch/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ anyhow.workspace = true
2424
thiserror.workspace = true
2525
async-trait.workspace = true
2626
tracing.workspace = true
27+
async-recursion.workspace = true
2728

2829
[dev-dependencies]
2930
zksync_concurrency.workspace = true

core/node/eth_watch/src/client.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,24 @@ impl EthHttpQueryClient {
100100
.collect()
101101
}
102102

103+
#[async_recursion::async_recursion]
103104
async fn get_events_inner(
104105
&self,
105106
from: BlockNumber,
106107
to: BlockNumber,
107-
topics1: Vec<H256>,
108-
topics2: Vec<H256>,
109-
addresses: Vec<Address>,
108+
topics1: Option<Vec<H256>>,
109+
topics2: Option<Vec<H256>>,
110+
addresses: Option<Vec<Address>>,
110111
retries_left: usize,
111112
) -> EnrichedClientResult<Vec<Log>> {
112-
let filter = FilterBuilder::default()
113+
let mut builder = FilterBuilder::default()
113114
.from_block(from)
114115
.to_block(to)
115-
.topics(Some(topics1), Some(topics2), None, None)
116-
.address(addresses)
117-
.build();
116+
.topics(topics1.clone(), topics2.clone(), None, None);
117+
if let Some(addresses) = addresses.clone() {
118+
builder = builder.address(addresses);
119+
}
120+
let filter = builder.build();
118121
let mut result = self.client.logs(&filter).await;
119122

120123
// This code is compatible with both Infura and Alchemy API providers.
@@ -168,17 +171,33 @@ impl EthHttpQueryClient {
168171

169172
tracing::warn!("Splitting block range in half: {from:?} - {mid:?} - {to:?}");
170173
let mut first_half = self
171-
.get_events(from, BlockNumber::Number(mid), RETRY_LIMIT)
174+
.get_events_inner(
175+
from,
176+
BlockNumber::Number(mid),
177+
topics1.clone(),
178+
topics2.clone(),
179+
addresses.clone(),
180+
RETRY_LIMIT,
181+
)
172182
.await?;
173183
let mut second_half = self
174-
.get_events(BlockNumber::Number(mid + 1u64), to, RETRY_LIMIT)
184+
.get_events_inner(
185+
BlockNumber::Number(mid + 1u64),
186+
to,
187+
topics1,
188+
topics2,
189+
addresses,
190+
RETRY_LIMIT,
191+
)
175192
.await?;
176193

177194
first_half.append(&mut second_half);
178195
result = Ok(first_half);
179196
} else if should_retry(err_code, err_message) && retries_left > 0 {
180197
tracing::warn!("Retrying. Retries left: {retries_left}");
181-
result = self.get_events(from, to, retries_left - 1).await;
198+
result = self
199+
.get_events_inner(from, to, topics1, topics2, addresses, retries_left - 1)
200+
.await;
182201
}
183202
}
184203

@@ -216,9 +235,9 @@ impl EthClient for EthHttpQueryClient {
216235
.get_events_inner(
217236
from_block.into(),
218237
to_block.into(),
219-
vec![self.new_upgrade_cut_data_signature],
220-
vec![packed_version],
221-
vec![state_transition_manager_address],
238+
Some(vec![self.new_upgrade_cut_data_signature]),
239+
Some(vec![packed_version]),
240+
Some(vec![state_transition_manager_address]),
222241
RETRY_LIMIT,
223242
)
224243
.await?;
@@ -235,9 +254,9 @@ impl EthClient for EthHttpQueryClient {
235254
self.get_events_inner(
236255
from,
237256
to,
238-
self.topics.clone(),
239-
Vec::new(),
240-
self.get_default_address_list(),
257+
Some(self.topics.clone()),
258+
None,
259+
Some(self.get_default_address_list()),
241260
retries_left,
242261
)
243262
.await

0 commit comments

Comments
 (0)