Skip to content
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

POS efficient l1 polling #2506

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
pass contract to fetcher
  • Loading branch information
tbro committed Jan 29, 2025
commit e956d6e254c15a3f1b54fc9d5684ea247b8b90ba
38 changes: 18 additions & 20 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,14 @@ impl L1Client {
let L1Event::NewHead { head } = event else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the latest L1 block (that may not be finalized yet). We should only consider finalized blocks for the stake table because otherwise the stake table may change on L1 after we fetched it.

continue;
};
if let Some(tables) = L1Client::update_stake_table(last_head, head).await.ok()
if let Some(tables) =
L1Client::update_stake_table(last_head, head, stake_table_contract.clone())
.await
.ok()
{
state.lock().await.stake.put(head, tables);
} else {
sleep(retry_delay).await;
}
sleep(retry_delay).await;
}
sleep(retry_delay).await;
}
Expand Down Expand Up @@ -820,26 +822,22 @@ impl L1Client {
async fn update_stake_table(
from_block: u64,
to_block: u64,
contract: PermissionedStakeTable<Provider<MultiRpcClient>>,
) -> anyhow::Result<StakeTables> {
// Fetch events for each chunk.
let stake_table_contract =
PermissionedStakeTable::new(Address::default(), self.provider.clone());

// query for stake table events, loop until successful.
match stake_table_contract
.stakers_updated_filter()
.from_block(from_block)
.to_block(to_block)
.query()
.await
{
Ok(events) => Ok(StakeTables::from_l1_events(events)),
Err(err) => {
tracing::warn!(from_block, to_block, %err, "StakeTable L1Event Error");
anyhow::bail!(err);
}
match contract
.stakers_updated_filter()
.from_block(from_block)
.to_block(to_block)
.query()
.await
{
Ok(events) => Ok(StakeTables::from_l1_events(events)),
Err(err) => {
tracing::warn!(from_block, to_block, %err, "StakeTable L1Event Error");
anyhow::bail!(err);
}

}
}
fn options(&self) -> &L1ClientOptions {
(*self.provider).as_ref().options()
Expand Down