fix(InventoryClient): Make blocked-rebalance log figures self-consistent#3552
Open
droplet-rl wants to merge 1 commit into
Open
fix(InventoryClient): Make blocked-rebalance log figures self-consistent#3552droplet-rl wants to merge 1 commit into
droplet-rl wants to merge 1 commit into
Conversation
The 'transfer blocked' log line printed an allocation percentage from the distribution snapshot taken at the top of rebalanceInventoryIfNeeded, next to chain/cumulative balances recomputed after this run's approved rebalances were tracked via trackCrossChainTransfer. Once a transfer was earmarked, the stale percentage no longer matched the live figures (e.g. 909.73/2,082.72 WETH reported as 0.07501% instead of 43.68%). Compute the percentage from the same live balances printed alongside it, and report the unallocated L1 balance remaining at decision time rather than the planning-time balance, which made blocks of tiny transfers look nonsensical (blocked despite the relayer supposedly holding hundreds of WETH on L1). Logging-only change; no behavior change to rebalance planning or execution. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Motivation
The
transfer blockedlines in the "Executed Inventory rebalances" log mix two points in time, producing self-contradictory output. Example from production (Slack, 2026-07-08):909.73 / 2,082.72 is 43.68%, not 0.07501%, and a 102.57 send being blocked while "relayer has 908.16 on L1" looks nonsensical.
Two causes, both in
rebalanceInventoryIfNeeded:distributionPctcame fromtokenDistributionPerL1Token, snapshotted at the top of the function, while the chain balance, cumulative total, and pending-transfer figures on the same line are recomputed after approved rebalances have been tracked viatrackCrossChainTransfer(which moves L1 balance into the destination chain's pending L1→L2 amount). In the example, ~908 WETH was earmarked to Robinhood earlier in the same run: the live balance read 909.73 while the percentage still reflected the pre-run ~1.56 WETH.balanceprinted was the planning-time L1 balance captured in the rebalance object, not the unallocated balance remaining at decision time (the value theamount.lte(unallocatedBalance)gate actually uses), hiding the real reason for the block.Changes
distributionPctfrom the same livegetBalanceOnChain/getCumulativeBalancereads that are printed alongside it, so the figures on one line are always self-consistent.Same scenario after this change:
Logging-only change; no behavior change to rebalance planning or execution. No README/AGENTS updates needed since no documented behavior, config, or interface changes.
Verification
tsc --noEmit: cleaneslint src/clients/InventoryClient.ts: cleannpx hardhat test test/InventoryClient.InventoryRebalance.ts: 15 passing🤖 Generated with Claude Code