From 61542197f68308ff87ea13875dd9676193446cd5 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 23 Jun 2025 09:36:29 -0300 Subject: [PATCH] staticaddr: use tx hash not *wire.MsgTx as a key Do not rely on GetActiveDepositsInState reusing the same *wire.MsgTx pointer for a unique transaction. --- staticaddr/withdraw/manager.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/staticaddr/withdraw/manager.go b/staticaddr/withdraw/manager.go index 2914d518..408d0338 100644 --- a/staticaddr/withdraw/manager.go +++ b/staticaddr/withdraw/manager.go @@ -227,15 +227,18 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error { } // Group the deposits by their finalized withdrawal transaction. - depositsByWithdrawalTx := make(map[*wire.MsgTx][]*deposit.Deposit) + depositsByWithdrawalTx := make(map[chainhash.Hash][]*deposit.Deposit) + hash2tx := make(map[chainhash.Hash]*wire.MsgTx) for _, d := range activeDeposits { withdrawalTx := d.FinalizedWithdrawalTx if withdrawalTx == nil { continue } + txid := withdrawalTx.TxHash() + hash2tx[txid] = withdrawalTx - depositsByWithdrawalTx[withdrawalTx] = append( - depositsByWithdrawalTx[withdrawalTx], d, + depositsByWithdrawalTx[txid] = append( + depositsByWithdrawalTx[txid], d, ) } @@ -244,7 +247,7 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error { eg := &errgroup.Group{} // We can now reinstate each cluster of deposits for a withdrawal. - for tx, deposits := range depositsByWithdrawalTx { + for txid, deposits := range depositsByWithdrawalTx { eg.Go(func() error { err := m.cfg.DepositManager.TransitionDeposits( ctx, deposits, deposit.OnWithdrawInitiated, @@ -254,6 +257,11 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error { return err } + tx, ok := hash2tx[txid] + if !ok { + return fmt.Errorf("can't find tx %v", txid) + } + _, err = m.publishFinalizedWithdrawalTx(ctx, tx) if err != nil { return err