Skip to content

Conversation

@tomg10
Copy link
Contributor

@tomg10 tomg10 commented Oct 25, 2024

No description provided.

log: &Log,
) -> PriorityOpId {
assert_eq!(event_type, RollupEventType::NewPriorityTx);
L1Tx::try_from(log.clone()).unwrap().common_data.serial_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error

.await
.unwrap();
let mut end_block = last_l1_block_number;
// we use step override as such big step value guarantees that we don't miss
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. Can you elaborate?

end_block = last_l1_block_number;
let mut current_block = start_block;
loop {
let filter_to_block = cmp::min(current_block + step - 1, end_block);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, instead of cmp::min you can use min method (no imports required), for example
let filter_to_block = end_block.min(...).

)
.await;
let tx =
L1Fetcher::get_transaction_by_hash(&self.eth_client, logs[0].transaction_hash.unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't want to make these methods of L1Fetcher, then consider wrapping eth_client into yet another type instead and making functions like get_transaction_by_hash methods of that new type instead.

hyperchain_contract()
}

fn commit_functions() -> Result<Vec<Function>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason why those functions are members of L1Fetcher class?

) -> Vec<CommitBlock> {
let end_block = L1Fetcher::get_last_l1_block_number(&self.eth_client)
.await
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error

RollupEventsFilter::L1BatchNumber(l1_batch_number + 1),
)
.await
.unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an error. In general in places that you can statically guarantee that an error will never occur (and therefore unwrap call is legitimate), document in a comment why it is the case.

// This code is compatible with both Infura and Alchemy API providers.
// Note: we don't handle rate-limits here - assumption is that we're never going to hit them.
if let Err(err) = &result {
tracing::warn!("Provider returned error message: {err}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, by default choose "{err:#}" for error printing, as "{err}" tends to not display the cause.

} else if should_retry(err_code, err_message) && retries_left > 0 {
tracing::warn!("Retrying. Retries left: {retries_left}");
result = self
.get_events_inner(from, to, topics1, topics2, addresses, retries_left - 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it seems wasteful to use recursion for retries instead of a loop, no?
Also the layout/block nesting of this function could be improved, by inverting success and failure branches, i.e.:

let err = match result {
  Ok(res) => return res;
  Err(err) => err
};
// error handling.


async fn get_logs(
&self,
start_block: U64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would be nice to have a dedicated type for L1 block numbers (or at least an alias), instead of plain U64

.ok_or_else(|| anyhow!("found latest block, but it contained no block number"))
}

async fn retry_call<T, E, Fut>(callback: impl Fn() -> Fut, err: L1FetchError) -> Result<T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not map_err() at the call site?

@tomg10 tomg10 changed the title feat(l1-recover): DO NOT MERGE, work in progress feat(l1-recover): Recovery of Main Node / External Node from L1 Jan 9, 2025
@tomg10 tomg10 closed this Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants