Skip to content

Commit 6ad7484

Browse files
committed
feat(tbtc): add activation-gated every-window deposit and moved-funds 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.
1 parent a07df43 commit 6ad7484

2 files changed

Lines changed: 359 additions & 22 deletions

File tree

pkg/tbtc/coordination.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ const (
5959
// and before they are filtered out as not interesting for the follower,
6060
// they are buffered in the channel.
6161
coordinationMessageReceiveBuffer = 512
62+
63+
// DepositSweepEveryWindowActivationBlock is the Ethereum block height at
64+
// which DepositSweep and MovedFundsSweep actions become available on every
65+
// coordination window instead of every 4th window only. All operators must
66+
// upgrade to a binary containing this constant before the activation block
67+
// is reached. The placeholder value must be replaced with the actual
68+
// activation block height before release.
69+
DepositSweepEveryWindowActivationBlock = uint64(0)
6270
)
6371

6472
// errCoordinationExecutorBusy is an error returned when the coordination
@@ -387,7 +395,7 @@ func (ce *coordinationExecutor) coordinate(
387395

388396
execLogger.Infof("coordination leader is: [%s]", leader)
389397

390-
actionsChecklist := ce.getActionsChecklist(window.index(), seed)
398+
actionsChecklist := ce.getActionsChecklist(window.index(), seed, window.coordinationBlock)
391399

392400
execLogger.Infof("actions checklist is: [%v]", actionsChecklist)
393401

@@ -575,6 +583,7 @@ func (ce *coordinationExecutor) getLeader(seed [32]byte) chain.Address {
575583
func (ce *coordinationExecutor) getActionsChecklist(
576584
windowIndex uint64,
577585
seed [32]byte,
586+
coordinationBlock uint64,
578587
) []WalletActionType {
579588
// Return nil checklist for incorrect coordination windows.
580589
if windowIndex == 0 {
@@ -591,16 +600,36 @@ func (ce *coordinationExecutor) getActionsChecklist(
591600
// frequency is every 4 coordination windows.
592601
frequencyWindows := uint64(4)
593602

594-
if windowIndex%frequencyWindows == 0 {
595-
actions = append(actions, ActionDepositSweep)
596-
}
603+
// The activation gate determines how often DepositSweep and
604+
// MovedFundsSweep actions are checked. Before the activation block,
605+
// all three actions (DepositSweep, MovedFundsSweep, MovingFunds)
606+
// are gated by the frequency window. After the activation block,
607+
// DepositSweep and MovedFundsSweep are checked on every coordination
608+
// window while MovingFunds stays frequency-gated because its
609+
// proposal generator performs a full-history chain scan.
610+
if coordinationBlock < DepositSweepEveryWindowActivationBlock {
611+
if windowIndex%frequencyWindows == 0 {
612+
actions = append(actions, ActionDepositSweep)
613+
}
614+
615+
if windowIndex%frequencyWindows == 0 {
616+
actions = append(actions, ActionMovedFundsSweep)
617+
}
597618

598-
if windowIndex%frequencyWindows == 0 {
619+
if windowIndex%frequencyWindows == 0 {
620+
actions = append(actions, ActionMovingFunds)
621+
}
622+
} else {
623+
actions = append(actions, ActionDepositSweep)
599624
actions = append(actions, ActionMovedFundsSweep)
600-
}
601625

602-
if windowIndex%frequencyWindows == 0 {
603-
actions = append(actions, ActionMovingFunds)
626+
// MovingFunds retains the frequency guard because its proposal
627+
// generator (MovingFundsTask.Run) calls FindDeposits which scans
628+
// from block 0, i.e. the full Ethereum history. Removing this
629+
// guard would multiply the scan load proportionally.
630+
if windowIndex%frequencyWindows == 0 {
631+
actions = append(actions, ActionMovingFunds)
632+
}
604633
}
605634

606635
// #nosec G404 (insecure random number source (rand))

0 commit comments

Comments
 (0)