alloy
alloy copied to clipboard
feat: Add mempool drop checks to the provider heartbeat
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:
- 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).
- We cannot rely on new blocks, because e.g.
anvilwon't mine new blocks without need by default. - 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