Skip to content

fix: fall back to latest stake when L2 block lookup reverts#593

Merged
rickstaa merged 3 commits intomainfrom
fix/poll-l2-block-fallback
Mar 18, 2026
Merged

fix: fall back to latest stake when L2 block lookup reverts#593
rickstaa merged 3 commits intomainfrom
fix/poll-l2-block-fallback

Conversation

@rickstaa
Copy link
Member

Summary

  • When getL2BlockRangeForL1 reverts for an L1 block (no corresponding Arbitrum batches), the returned lastBlock: 0 was passed to getTotalStake(0), querying the subgraph at block 0 and producing near-zero total stake — potentially causing incorrect poll status (e.g. marking polls as passed when they should be quorum-not-met)
  • Now falls back to querying latest total stake when the L2 block lookup fails, which is a much more reasonable approximation
  • Downgrades noisy console.error (with full RPC error dump) to a clean console.warn

Test plan

  • Load the voting page and confirm the L2 block revert no longer dumps a full error stack
  • Verify finished polls still display correct status and vote percentages
  • Confirm active polls are unaffected (they already used latest stake)

🤖 Generated with Claude Code

When getL2BlockRangeForL1 reverts (e.g. no Arbitrum batches posted for
that L1 block), the returned lastBlock of 0 was passed to getTotalStake,
querying the subgraph at block 0 and producing near-zero stake. This
could cause incorrect poll status calculations.

Now passes undefined instead of 0 so getTotalStake queries latest stake.
Also downgrades console.error to console.warn for expected failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rickstaa rickstaa requested a review from ECWireless as a code owner March 17, 2026 13:59
Copilot AI review requested due to automatic review settings March 17, 2026 13:59
@vercel
Copy link
Contributor

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer-arbitrum-one Ready Ready Preview, Comment Mar 18, 2026 8:36am

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves poll stake calculation robustness by falling back to querying the latest total stake when the L1→L2 block-range lookup fails, avoiding incorrect outcomes for finished polls when the Arbitrum NodeInterface call reverts.

Changes:

  • Refactors getPollExtended to compute an optional l2BlockNumber and pass undefined to getTotalStake when an L2 end block can’t be resolved.
  • Downgrades the L2 block-range lookup failure log from console.error to a cleaner console.warn.
Comments suppressed due to low confidence (1)

lib/api/polls.ts:220

  • Using lastBlock: 0 as the failure sentinel is ambiguous because block 0 is a valid L2 block height. Returning undefined/null (or an ok flag) on failure would make the API unambiguous and avoid relying on lastBlock > 0 checks at call sites.
    return {
      lastBlock: 0,
      firstBlock: 0,
    };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

rickstaa and others added 2 commits March 18, 2026 09:30
@rickstaa rickstaa merged commit 8b3797a into main Mar 18, 2026
8 checks passed
@rickstaa rickstaa deleted the fix/poll-l2-block-fallback branch March 18, 2026 08:36
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