From 896fd37adff440168f68222d63373404ce234342 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 13 Jun 2025 13:00:54 +0200 Subject: [PATCH 1/3] staticaddr: fix deposit recovery deadlock --- staticaddr/deposit/manager.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/staticaddr/deposit/manager.go b/staticaddr/deposit/manager.go index 4b39690d9..be6f84d11 100644 --- a/staticaddr/deposit/manager.go +++ b/staticaddr/deposit/manager.go @@ -191,10 +191,13 @@ func (m *Manager) recoverDeposits(ctx context.Context) error { } // Send the OnRecover event to the state machine. - err = fsm.SendEvent(ctx, OnRecover, nil) - if err != nil { - log.Errorf("Error sending OnStart event: %v", err) - } + go func(fsm *FSM) { + err := fsm.SendEvent(ctx, OnRecover, nil) + if err != nil { + log.Errorf("Error sending OnStart event: %v", + err) + } + }(fsm) m.mu.Lock() m.activeDeposits[d.OutPoint] = fsm From 57b7ba32a86e4e1028969bdf604d3ecc70993625 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 13 Jun 2025 13:29:54 +0200 Subject: [PATCH 2/3] staticaddr: remove duplicate deposit finalize method --- staticaddr/deposit/actions.go | 15 --------------- staticaddr/deposit/fsm.go | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/staticaddr/deposit/actions.go b/staticaddr/deposit/actions.go index 39b763a43..306cbe89b 100644 --- a/staticaddr/deposit/actions.go +++ b/staticaddr/deposit/actions.go @@ -137,21 +137,6 @@ func (f *FSM) WaitForExpirySweepAction(ctx context.Context, } } -// SweptExpiredDepositAction is the final action of the FSM. It signals to the -// manager that the deposit has been swept and the FSM can be removed. It also -// ends the state machine main loop by cancelling its context. -func (f *FSM) SweptExpiredDepositAction(ctx context.Context, - _ fsm.EventContext) fsm.EventType { - - select { - case <-ctx.Done(): - return fsm.OnError - - case f.finalizedDepositChan <- f.deposit.OutPoint: - return fsm.NoOp - } -} - // FinalizeDepositAction is the final action after a withdrawal. It signals to // the manager that the deposit has been swept and the FSM can be removed. func (f *FSM) FinalizeDepositAction(ctx context.Context, diff --git a/staticaddr/deposit/fsm.go b/staticaddr/deposit/fsm.go index 39c143984..2d1751ffc 100644 --- a/staticaddr/deposit/fsm.go +++ b/staticaddr/deposit/fsm.go @@ -292,7 +292,7 @@ func (f *FSM) DepositStatesV0() fsm.States { Transitions: fsm.Transitions{ OnExpiry: Expired, }, - Action: f.SweptExpiredDepositAction, + Action: f.FinalizeDepositAction, }, Withdrawing: fsm.State{ Transitions: fsm.Transitions{ From 22266d67823babddaac6e74682222ded67e3d457 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Fri, 13 Jun 2025 20:10:08 +0200 Subject: [PATCH 3/3] staticaddr: thread-safe loop-in recovery --- staticaddr/loopin/manager.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/staticaddr/loopin/manager.go b/staticaddr/loopin/manager.go index 106f2b3cf..79423fdc3 100644 --- a/staticaddr/loopin/manager.go +++ b/staticaddr/loopin/manager.go @@ -473,16 +473,15 @@ func (m *Manager) recoverLoopIns(ctx context.Context) error { } // Send the OnRecover event to the state machine. - swapHash := loopIn.SwapHash - go func() { - err = fsm.SendEvent(ctx, OnRecover, nil) + go func(fsm *FSM, swapHash lntypes.Hash) { + err := fsm.SendEvent(ctx, OnRecover, nil) if err != nil { log.Errorf("Error sending OnStart event: %v", err) } m.activeLoopIns[swapHash] = fsm - }() + }(fsm, loopIn.SwapHash) } return nil