Skip to content

fix(provider): avoid confirmation height underflow - #4143

Open
questfever wants to merge 1 commit into
alloy-rs:mainfrom
questfever:fix-zero-confirmation-underflow
Open

fix(provider): avoid confirmation height underflow#4143
questfever wants to merge 1 commit into
alloy-rs:mainfrom
questfever:fix-zero-confirmation-underflow

Conversation

@questfever

Copy link
Copy Markdown

Motivation

PendingTransactionConfig::with_required_confirmations accepts any u64, including 0.

Most heartbeat paths compute the confirmation target block with block_height + confirmations - 1. This can underflow when confirmations == 0 and the transaction is observed at block 0, and it can also overflow for very large confirmation counts.

The new-block path already treats confirmations <= 1 as immediately confirmed, so the historical/already-confirmed paths should handle 0 consistently instead of panicking.

Solution

  • centralize pending transaction confirmation target calculation
  • use saturating arithmetic for block_height + confirmations - 1
  • add regression tests for required_confirmations = 0 in already-confirmed and lookbehind paths

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant