fix(inventory): Fix cross-chain refund under-counting in BundleDataApproxClient#3172
Merged
nicholaspai merged 6 commits intomasterfrom Apr 9, 2026
Merged
Conversation
…proxClient When a bundle is executed on chain A but the root bundle relay has not yet propagated to chain B (normal cross-chain delay of ~10-20 minutes), fills on chain A with repaymentChainId = B were incorrectly excluded from upcoming refunds. The filter used fromBlocks[fillChain] which advanced when the fill chain processed the bundle, even though the repayment chain's refund leaf had not been executed yet. Fix: expand getUnexecutedBundleStartBlocks to return a 2D block mapping (result[referenceChain][fillChain]) so that refund filtering uses the repayment chain's execution state (fromBlocks[repaymentChainId][fillChain]) rather than the fill chain's own state. Deposit filtering uses the diagonal (fromBlocks[chainId][chainId]) preserving existing behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
pxrl
approved these changes
Apr 9, 2026
bmzig
approved these changes
Apr 9, 2026
pxrl
pushed a commit
that referenced
this pull request
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BundleDataApproxClient.getApproximateRefundsForTokenfiltered fills usingfromBlocks[fillChain], which is derived from the last executed bundle on the fill chain. When a bundle was executed on the fill chain but the root bundle relay had not yet propagated to the repayment chain (normal cross-chain delay of ~10-20 minutes), fills with cross-chain repayment were incorrectly excluded from upcoming refunds. This caused the relayer to under-estimate pending refunds on the repayment chain during the relay propagation window.getUnexecutedBundleStartBlocksnow returns a 2D block mapping (result[referenceChain][fillChain]) containing the matched bundle's end blocks for all chains, not just the reference chain. Refund filtering usesfromBlocks[repaymentChainId][fillChain]so fills are only excluded when the repayment chain's refund leaf has actually been executed. Deposit filtering uses the diagonal (fromBlocks[chainId][chainId]), preserving existing behavior.Root cause
Each bundle cycle, the dataworker executes a bundle on the hub chain and then relays root bundles to each spoke chain. On the hub chain (Ethereum), execution is immediate since it's same-chain. On L2s, the relay takes 10-20+ minutes to propagate. The
BundleDataApproxClienttypically runs shortly after a new bundle is proposed — at which point the previous bundle's relay may not have reached all spoke chains yet.The old code computed a 1D
fromBlocks[chainId]per chain based on that chain's own spoke pool events. A fill on chain X withrepaymentChainId = Ywas filtered byfromBlocks[X]. When chain X advanced (bundle executed there) but chain Y hadn't received the relay, the fill was excluded even though the relayer hadn't received the refund on chain Y.Changes
src/clients/BundleDataApproxClient.tsgetUnexecutedBundleStartBlocksreturns 2D mapping;getApproximateRefundsForTokenindexes by[repaymentChainId][fillChainId];getApproximateDepositsForTokenuses diagonaltest/BundleDataApproxClient.tstest/mocks/MockSpokePoolClient.tsaddRelayerRefundExecutionmethod (replacesas anycast)test/mocks/MockBundleDataApproxClient.tsTest plan
BundleDataApproxClienttests pass (10/10)🤖 Generated with Claude Code