Coordination windows performance improvements#3864
Open
lrsaturnino wants to merge 4 commits intomainfrom
Open
Conversation
…ries Add a configurable look-back period (DepositSweepLookBackBlocks = 216000 blocks, ~30 days) to FindDepositsToSweep so it only scans recent blocks for DepositRevealed events instead of the full chain history. When the current block exceeds the look-back window, filterStartBlock is computed as currentBlock - lookBackBlocks; otherwise it falls back to 0 to guard against underflow. FindDeposits (used by the MovingFunds safety guard) continues to scan from block 0 to preserve full-history coverage. Add tests for both the bounded lookback path (currentBlock=300000, filterStartBlock=84000) and the underflow guard path (currentBlock=100000, filterStartBlock=0). Wire MockBlockCounter into the existing JSON-driven scenario tests so they pass with the new BlockCounter dependency.
Deposits targeting different vaults cannot be swept in the same transaction. This change groups unswept deposits by their vault address (with case-insensitive normalization) and selects the largest group to maximize per-transaction throughput. Vault=0x0 (nil-vault) deposits that are not selected are logged at Warn level for operator awareness, as they remain recoverable via later sweep cycles, depositor refunds, or reinitializer re-assignment. Also propagates the Vault field through DepositReference and Deposit structs so downstream consumers have access to it.
… sweeps Introduce DepositSweepEveryWindowActivationBlock constant that controls when DepositSweep and MovedFundsSweep actions switch from every 4th coordination window to every window. MovingFunds retains the 4th-window gate to avoid multiplying its full-history chain scan load. The activation block is currently set to 0 (placeholder) and must be replaced with the actual mainnet block height before release. Update getActionsChecklist to accept coordinationBlock and branch on the activation gate. Expand tests with post-activation safety invariants and canonical ordering assertions.
Set DepositSweepEveryWindowActivationBlock to 24559289, the estimated Ethereum block height for March 1st 00:00 UTC. Before this block, all three actions (DepositSweep, MovedFundsSweep, MovingFunds) remain gated to every 4th coordination window. After this block, DepositSweep and MovedFundsSweep run on every window while MovingFunds stays gated. Update tests to cover both pre-activation (low block numbers) and post-activation (blocks above 24559289) code paths with correct expected checklists for each regime.
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
FindDepositsToSweepnow limitsDepositRevealedevent scanning to the most recent ~30 days (DepositSweepLookBackBlocks = 216000blocks) instead of querying from block 0, significantly reducing RPC load on long-running nodescurrentBlock < 216000,filterStartBlockremains0to avoid uint64 wraparoundFindDeposits(used by the MovingFunds safety guard) continues to scan from block 0 to preserve full-history coverage for wallet safety checksVaultfield is propagated throughDepositReferenceandDepositstructs for downstream consumersCoordination actions — before and after
Before:
redemptionTimeoutwas ~20 years, exceeds chain heightAfter (block >= 24559289):
redemptionTimeoutchanged to 13 days on-chainChanges
Coordination layer (
coordination.go):DepositSweepEveryWindowActivationBlockconstant set to block 24559289 (~March 1st 2026 00:00 UTC)coordinationBlockparameter togetActionsChecklistCoordination tests (
coordination_test.go):TestCoordinationExecutor_GetActionsChecklistcovers pre-activation behavior (blocks below 24559289): non-4th windows get only Redemption, 4th windows get all actionsTestCoordinationExecutor_GetActionsChecklist_PostActivationcovers post-activation behavior (blocks above 24559289) with safety invariant assertionsassertPostActivationSafetyhelper — verifies ActionRedemption at index 0, DepositSweep and MovedFundsSweep always present, MovingFunds absent on non-4th windowsassertChecklistOrderinghelper — verifies canonical priority ordering across the checklistProduction code (
deposit_sweep.go):DepositSweepLookBackBlocksconstant (216000 blocks, ~30 days at 12s/block)filterStartBlockparameter to internalfindDeposits()functionFindDepositsToSweep()computes bounded start block viaBlockCounter.CurrentBlock()with underflow guardFindDeposits()passesfilterStartBlock=0to preserve full-history behaviorDepositRevealedEventFilter.StartBlockfrom the computed valueVaultfield throughDepositandDepositReferencestructsTest helpers (
tbtcpgtest.go):Vaultfield to testDepositstruct andDepositsReferences()outputTests (
deposit_sweep_test.go):TestDepositSweepLookBackBlocks— validates the constant equals 216000TestDepositSweepTask_FindDepositsToSweep_BoundedLookback— exercises the bounded path withcurrentBlock=300000TestDepositSweepTask_FindDepositsToSweep_UnderflowGuard— exercises the underflow path withcurrentBlock=100000MockBlockCounterinto existing JSON-driven scenario testsTestFindDepositsToSweep_VaultGroupingwith 10 sub-tests covering nil vaults, mixed vaults, case normalization, tied groups, and multi-group selectionTest plan
go test ./pkg/tbtcpg/... -v— all tests passgo test ./pkg/tbtc/... -run TestCoordinationExecutor_GetActionsChecklist -v— all coordination tests passgo build ./pkg/...— compiles cleanlygo vet ./pkg/...— no new issuesFindDeposits(MovingFunds path) still usesfilterStartBlock=0