alloy icon indicating copy to clipboard operation
alloy copied to clipboard

feat: Add mempool drop checks to the provider heartbeat

Open popzxc opened this issue 4 months ago • 2 comments
trafficstars

Motivation

Fixes #2678

Solution

Adds a period check to the heartbeat to check if transactions are still present in mempool. This turned out to be more complex than I initially expected. Reasons:

  1. We cannot distinguish a situation where transaction was dropped from a mempool from the situation where it didn't reach the mempool yet (and transaction could've been dropped before we started watching it).
  2. We cannot rely on new blocks, because e.g. anvil won't mine new blocks without need by default.
  3. We want this to be configurable, because some people might handle this kind of behavior by other means.

So I introduced configurable mempool check interval on the root provider. If it's not provided, we will set it to poll_interval * 10 (which seems to be a reasonable amount of time for transaction to appear in mempool). If it's provided and it's Some, we will use provided interval. For provided None, we will disable checks.

Heartbeat integration is pretty straightforward: for any unconfirmed transaction we remember when it was added to the watch list, and start checking it only after configured interval has passed.

cc @mattsse

PR Checklist

  • [x] Added Tests
  • [x] Added Documentation
  • [ ] Breaking changes

popzxc avatar Jul 10 '25 12:07 popzxc