Skip to content

Commit ad23568

Browse files
committed
Revert "staticaddr: recover withdrawals in parallel"
This reverts commit 38aaa4d
1 parent 1104e92 commit ad23568

File tree

2 files changed

+29
-50
lines changed

2 files changed

+29
-50
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/btcsuite/btcd/btcutil v1.1.5
77
github.com/btcsuite/btcd/btcutil/psbt v1.1.10
88
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
9-
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
9+
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
1010
github.com/btcsuite/btcwallet v0.16.13
1111
github.com/btcsuite/btcwallet/wtxmgr v1.5.6
1212
github.com/davecgh/go-spew v1.1.1
@@ -36,14 +36,15 @@ require (
3636
github.com/urfave/cli v1.22.14
3737
go.etcd.io/bbolt v1.3.11
3838
golang.org/x/net v0.38.0
39-
golang.org/x/sync v0.12.0
4039
google.golang.org/grpc v1.64.1
4140
google.golang.org/protobuf v1.34.2
4241
gopkg.in/macaroon-bakery.v2 v2.3.0
4342
gopkg.in/macaroon.v2 v2.1.0
4443
modernc.org/sqlite v1.34.5
4544
)
4645

46+
require github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
47+
4748
require (
4849
dario.cat/mergo v1.0.1 // indirect
4950
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
@@ -55,7 +56,6 @@ require (
5556
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
5657
github.com/aead/siphash v1.0.1 // indirect
5758
github.com/beorn7/perks v1.0.1 // indirect
58-
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
5959
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 // indirect
6060
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 // indirect
6161
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.5 // indirect
@@ -185,6 +185,7 @@ require (
185185
golang.org/x/crypto v0.36.0 // indirect
186186
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
187187
golang.org/x/mod v0.21.0 // indirect
188+
golang.org/x/sync v0.12.0 // indirect
188189
golang.org/x/sys v0.31.0 // indirect
189190
golang.org/x/term v0.30.0 // indirect
190191
golang.org/x/text v0.23.0 // indirect

staticaddr/withdraw/manager.go

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3231
var (
@@ -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

Comments
 (0)