Skip to content

Commit 412fe7f

Browse files
committed
staticaddr: simplify withdrawal fsm transition
previously upon recovery, a withdrawing deposit was first transitioned into the Deposited state by the deposit manager, and then again into the Withdrawing state by the withdrawal manager. The first transition is unnecessary, so we just remain in the Withdrawing state upon recovery.
1 parent 1104e92 commit 412fe7f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

staticaddr/deposit/fsm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,11 @@ func (f *FSM) DepositStatesV0() fsm.States {
300300
// OnWithdrawInitiated is sent if a fee bump was
301301
// requested and the withdrawal was republished.
302302
OnWithdrawInitiated: Withdrawing,
303-
// Upon recovery, we go back to the Deposited
304-
// state. The deposit by then has a withdrawal
305-
// address stamped to it which will cause it to
306-
// transition into the Withdrawing state again.
307-
OnRecover: Deposited,
303+
304+
// Upon recovery, we remain in the Withdrawing
305+
// state so that the withdrawal manager can
306+
// reinstate the withdrawal.
307+
OnRecover: Withdrawing,
308308

309309
// A precondition for the Withdrawing state is
310310
// that the withdrawal transaction has been

staticaddr/withdraw/manager.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,11 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
214214
}
215215

216216
func (m *Manager) recoverWithdrawals(ctx context.Context) error {
217-
// To recover withdrawals we skim through all active deposits and check
218-
// if they have a withdrawal address set. For the ones that do we
219-
// cluster those with equal withdrawal addresses and kick-off
220-
// their withdrawal. Each cluster represents a separate withdrawal
221-
// intent by the user.
222-
activeDeposits, err := m.cfg.DepositManager.GetActiveDepositsInState(
223-
deposit.Deposited,
217+
// To recover withdrawals we cluster those with equal withdrawal
218+
// addresses and publish their withdrawal tx. Each cluster represents a
219+
// separate withdrawal intent by the user.
220+
withdrawingDeposits, err := m.cfg.DepositManager.GetActiveDepositsInState(
221+
deposit.Withdrawing,
224222
)
225223
if err != nil {
226224
return err
@@ -229,7 +227,7 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
229227
// Group the deposits by their finalized withdrawal transaction.
230228
depositsByWithdrawalTx := make(map[chainhash.Hash][]*deposit.Deposit)
231229
hash2tx := make(map[chainhash.Hash]*wire.MsgTx)
232-
for _, d := range activeDeposits {
230+
for _, d := range withdrawingDeposits {
233231
withdrawalTx := d.FinalizedWithdrawalTx
234232
if withdrawalTx == nil {
235233
continue

0 commit comments

Comments
 (0)