Skip to content

Conversation

@lrsaturnino
Copy link
Member

@lrsaturnino lrsaturnino commented Feb 13, 2026

Summary

  • FindDepositsToSweep now limits DepositRevealed event scanning to the most recent ~30 days (DepositSweepLookBackBlocks = 216000 blocks) instead of querying from block 0, significantly reducing RPC load on long-running nodes
  • Includes underflow protection: when currentBlock < 216000, filterStartBlock remains 0 to avoid uint64 wraparound
  • FindDeposits (used by the MovingFunds safety guard) continues to scan from block 0 to preserve full-history coverage for wallet safety checks

Changes

Production code (deposit_sweep.go):

  • Add exported DepositSweepLookBackBlocks constant (216000 blocks, ~30 days at 12s/block)
  • Add filterStartBlock parameter to internal findDeposits() function
  • FindDepositsToSweep() computes bounded start block via BlockCounter.CurrentBlock() with underflow guard
  • FindDeposits() passes filterStartBlock=0 to preserve full-history behavior
  • Set DepositRevealedEventFilter.StartBlock from the computed value

Tests (deposit_sweep_test.go):

  • Add TestDepositSweepLookBackBlocks — validates the constant equals 216000
  • Add TestDepositSweepTask_FindDepositsToSweep_BoundedLookback — exercises the bounded path with currentBlock=300000, producing filterStartBlock=84000
  • Add TestDepositSweepTask_FindDepositsToSweep_UnderflowGuard — exercises the underflow path with currentBlock=100000, keeping filterStartBlock=0
  • Wire MockBlockCounter into existing JSON-driven scenario tests to satisfy the new BlockCounter dependency

Test plan

  • go test ./pkg/tbtcpg/... -v — all 20 test functions pass (0.3s)
  • go build ./pkg/tbtcpg/... — compiles cleanly
  • go vet ./pkg/tbtcpg/... — no new issues
  • No JSON test data files modified (scenarios unchanged)
  • Verify FindDeposits (MovingFunds path) still uses filterStartBlock=0

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant