Skip to content

staticaddr: simplify withdrawal fsm transition #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions staticaddr/deposit/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ func (f *FSM) DepositStatesV0() fsm.States {
// OnWithdrawInitiated is sent if a fee bump was
// requested and the withdrawal was republished.
OnWithdrawInitiated: Withdrawing,
// Upon recovery, we go back to the Deposited
// state. The deposit by then has a withdrawal
// address stamped to it which will cause it to
// transition into the Withdrawing state again.
OnRecover: Deposited,

// Upon recovery, we remain in the Withdrawing
// state so that the withdrawal manager can
// reinstate the withdrawal.
OnRecover: Withdrawing,

// A precondition for the Withdrawing state is
// that the withdrawal transaction has been
Expand Down
14 changes: 6 additions & 8 deletions staticaddr/withdraw/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error {
}

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