-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(starknet_l1_provider): implement event fetch #2854
base: gilad/add-scraper
Are you sure you want to change the base?
Conversation
Artifacts upload workflows: |
- Currently only implementing the simplest event to parse, the rest are coming up. - removed two unused error variants: `FeltParseError`, `Serde`
`ser_required_param` seems to be unsupported by the current infra tests and unused elsewhere, using regular `ser_param` instead.
- base layer constant file will hold the identifiers of Starknet Events. - fetch_events will get events from base layer and send to provider
573a0b3
to
75d3714
Compare
4ccd563
to
a840e25
Compare
Benchmark movements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @giladchase and @matan-starkware)
crates/starknet_l1_provider/src/l1_scraper.rs
line 57 at r1 (raw file):
error!("Failed to get latest L1 block number, finality too high."); return Ok(()); };
In case this code is repeated, consider a function.
Code quote:
let latest_l1_block_number = self
.base_layer
.latest_l1_block_number(self.config.finality)
.await
.map_err(L1ScraperError::BaseLayer)?;
let Some(latest_l1_block_number) = latest_l1_block_number else {
error!("Failed to get latest L1 block number, finality too high.");
return Ok(());
};
crates/starknet_l1_provider/src/l1_scraper.rs
line 72 at r1 (raw file):
.into_iter() .map(|event| self.event_from_raw_l1_event(event)) .collect::<L1ScraperResult<Vec<_>, _>>()?;
Do you prefer turbofish over type annotations?
Also, WDYM by collect
ing to a Result
?
Code quote:
::<L1ScraperResult<Vec<_>, _>>
crates/starknet_l1_provider/src/l1_scraper.rs
line 86 at r1 (raw file):
} fn event_from_raw_l1_event(&self, l1_event: L1Event) -> L1ScraperResult<Event, B> {
Can this be Event::TryFrom<L1Event>
method?
Code quote:
event_from_raw_l1_event
crates/starknet_l1_provider/src/l1_scraper.rs
line 92 at r1 (raw file):
ExecutableL1HandlerTransaction::create(tx, chain_id, fee) .map(Event::L1HandlerTransaction) .map_err(L1ScraperError::HashCalculationError)
Not very readable, IMO. Any alternative?
Code quote:
ExecutableL1HandlerTransaction::create(tx, chain_id, fee)
.map(Event::L1HandlerTransaction)
.map_err(L1ScraperError::HashCalculationError)
crates/starknet_l1_provider/src/l1_scraper.rs
line 124 at r1 (raw file):
#[derive(Error, Debug)] pub enum L1ScraperError<T: BaseLayerContract + Send + Sync> {
Is this necessary? What exactly is generic here - the L1, or the contract we're interacting with?
Code quote:
T: BaseLayerContract
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @elintul and @giladchase)
crates/starknet_l1_provider/src/l1_scraper.rs
line 72 at r1 (raw file):
Previously, elintul (Elin) wrote…
Do you prefer turbofish over type annotations?
Also, WDYM bycollect
ing to aResult
?
"Also, WDYM by collect
ing to a Result
?" This tells Rust to iterate over Result<T>
elements and upon encountering a single error exit, returning that error. If no errors are encountered, it produces Vec<T>
.
crates/starknet_l1_provider/src/l1_scraper.rs
line 92 at r1 (raw file):
Previously, elintul (Elin) wrote…
Not very readable, IMO. Any alternative?
Agreed. If you update the error type to HashCalculationError(#[from] StarknetApiError),
Then you could do
let tx = ExecutableL1HandlerTransaction::create(tx, &self.config.chain_id, fee)?;
Ok(Event::L1HandlerTransaction(tx))
crates/starknet_l1_provider/src/l1_scraper.rs
line 55 at r1 (raw file):
let Some(latest_l1_block_number) = latest_l1_block_number else { error!("Failed to get latest L1 block number, finality too high.");
This means that there is no finalized block on ethereum? (dependent upon our config)
Code quote:
error!("Failed to get latest L1 block number, finality too high.");
crates/starknet_l1_provider/src/l1_scraper.rs
line 74 at r1 (raw file):
.collect::<L1ScraperResult<Vec<_>, _>>()?; self.last_block_number_processed = latest_l1_block_number + 1;
Is BaseLayerContract::until_block
inclusive on until_block
? I think that should be explicit in the trait doc.
Code quote:
self.last_block_number_processed = latest_l1_block_number + 1;
crates/starknet_l1_provider/src/l1_scraper.rs
line 128 at r1 (raw file):
BaseLayer(T::Error), #[error("Failed to calculate hash: {0}")] HashCalculationError(StarknetApiError),
Allow for easy conversions
Suggestion:
HashCalculationError(#[from] StarknetApiError),
75d3714
to
717a4de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @giladchase and @matan-starkware)
crates/starknet_l1_provider/src/l1_scraper.rs
line 72 at r1 (raw file):
Previously, matan-starkware wrote…
"Also, WDYM by
collect
ing to aResult
?" This tells Rust to iterate overResult<T>
elements and upon encountering a single error exit, returning that error. If no errors are encountered, it producesVec<T>
.
Thanks!
No description provided.