@@ -26,7 +26,6 @@ import (
2626 "github.com/lightningnetwork/lnd/lntypes"
2727 "github.com/lightningnetwork/lnd/lnwallet"
2828 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
29- "golang.org/x/sync/errgroup"
3029)
3130
3231var (
@@ -227,65 +226,44 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
227226 }
228227
229228 // Group the deposits by their finalized withdrawal transaction.
230- depositsByWithdrawalTx := make (map [chainhash.Hash ][]* deposit.Deposit )
231- hash2tx := make (map [chainhash.Hash ]* wire.MsgTx )
229+ depositsByWithdrawalTx := make (map [* wire.MsgTx ][]* deposit.Deposit )
232230 for _ , d := range activeDeposits {
233231 withdrawalTx := d .FinalizedWithdrawalTx
234232 if withdrawalTx == nil {
235233 continue
236234 }
237- txid := withdrawalTx .TxHash ()
238- hash2tx [txid ] = withdrawalTx
239235
240- depositsByWithdrawalTx [txid ] = append (
241- depositsByWithdrawalTx [txid ], d ,
236+ depositsByWithdrawalTx [withdrawalTx ] = append (
237+ depositsByWithdrawalTx [withdrawalTx ], d ,
242238 )
243239 }
244240
245- // Publishing a transaction can take a while in neutrino mode, so
246- // do it in parallel.
247- eg := & errgroup.Group {}
248-
249241 // We can now reinstate each cluster of deposits for a withdrawal.
250- for txid , deposits := range depositsByWithdrawalTx {
251- eg .Go (func () error {
252- err := m .cfg .DepositManager .TransitionDeposits (
253- ctx , deposits , deposit .OnWithdrawInitiated ,
254- deposit .Withdrawing ,
255- )
256- if err != nil {
257- return err
258- }
259-
260- tx , ok := hash2tx [txid ]
261- if ! ok {
262- return fmt .Errorf ("can't find tx %v" , txid )
263- }
264-
265- _ , err = m .publishFinalizedWithdrawalTx (ctx , tx )
266- if err != nil {
267- return err
268- }
269-
270- err = m .handleWithdrawal (
271- ctx , deposits , tx .TxHash (),
272- tx .TxOut [0 ].PkScript ,
273- )
274- if err != nil {
275- return err
276- }
242+ for finalizedWithdrawalTx , deposits := range depositsByWithdrawalTx {
243+ tx := finalizedWithdrawalTx
244+ err = m .cfg .DepositManager .TransitionDeposits (
245+ ctx , deposits , deposit .OnWithdrawInitiated ,
246+ deposit .Withdrawing ,
247+ )
248+ if err != nil {
249+ return err
250+ }
277251
278- m .mu .Lock ()
279- m .finalizedWithdrawalTxns [tx .TxHash ()] = tx
280- m .mu .Unlock ()
252+ _ , err = m .publishFinalizedWithdrawalTx (ctx , tx )
253+ if err != nil {
254+ return err
255+ }
281256
282- return nil
283- })
284- }
257+ err = m .handleWithdrawal (
258+ ctx , deposits , tx .TxHash (), tx .TxOut [0 ].PkScript ,
259+ )
260+ if err != nil {
261+ return err
262+ }
285263
286- // Wait for all goroutines to report back.
287- if err := eg . Wait (); err != nil {
288- return fmt . Errorf ( "error recovering withdrawals: %w" , err )
264+ m . mu . Lock ()
265+ m . finalizedWithdrawalTxns [ tx . TxHash ()] = tx
266+ m . mu . Unlock ( )
289267 }
290268
291269 return nil
0 commit comments