mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr: recover withdrawals in parallel
Use errgroup to publish each transaction in a separate goroutine. Publishing a transaction can take a while in neutrino mode.
This commit is contained in:
parent
6f50b27b7d
commit
38aaa4d07a
2 changed files with 39 additions and 26 deletions
7
go.mod
7
go.mod
|
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/btcsuite/btcd/btcutil v1.1.5
|
||||
github.com/btcsuite/btcd/btcutil/psbt v1.1.10
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
|
||||
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
|
||||
github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
|
||||
github.com/btcsuite/btcwallet v0.16.13
|
||||
github.com/btcsuite/btcwallet/wtxmgr v1.5.6
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
|
|
@ -36,6 +36,7 @@ require (
|
|||
github.com/urfave/cli v1.22.14
|
||||
go.etcd.io/bbolt v1.3.11
|
||||
golang.org/x/net v0.38.0
|
||||
golang.org/x/sync v0.12.0
|
||||
google.golang.org/grpc v1.64.1
|
||||
google.golang.org/protobuf v1.34.2
|
||||
gopkg.in/macaroon-bakery.v2 v2.3.0
|
||||
|
|
@ -43,8 +44,6 @@ require (
|
|||
modernc.org/sqlite v1.34.5
|
||||
)
|
||||
|
||||
require github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.1 // indirect
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
|
||||
|
|
@ -56,6 +55,7 @@ require (
|
|||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
|
||||
github.com/aead/siphash v1.0.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c // indirect
|
||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 // indirect
|
||||
github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 // indirect
|
||||
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.5 // indirect
|
||||
|
|
@ -185,7 +185,6 @@ require (
|
|||
golang.org/x/crypto v0.36.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/term v0.30.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -238,32 +239,45 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
|
|||
)
|
||||
}
|
||||
|
||||
// Publishing a transaction can take a while in neutrino mode, so
|
||||
// do it in parallel.
|
||||
eg := &errgroup.Group{}
|
||||
|
||||
// We can now reinstate each cluster of deposits for a withdrawal.
|
||||
for finalizedWithdrawalTx, deposits := range depositsByWithdrawalTx {
|
||||
tx := finalizedWithdrawalTx
|
||||
err = m.cfg.DepositManager.TransitionDeposits(
|
||||
ctx, deposits, deposit.OnWithdrawInitiated,
|
||||
deposit.Withdrawing,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for tx, deposits := range depositsByWithdrawalTx {
|
||||
eg.Go(func() error {
|
||||
err := m.cfg.DepositManager.TransitionDeposits(
|
||||
ctx, deposits, deposit.OnWithdrawInitiated,
|
||||
deposit.Withdrawing,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = m.publishFinalizedWithdrawalTx(ctx, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.publishFinalizedWithdrawalTx(ctx, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.handleWithdrawal(
|
||||
ctx, deposits, tx.TxHash(), tx.TxOut[0].PkScript,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = m.handleWithdrawal(
|
||||
ctx, deposits, tx.TxHash(),
|
||||
tx.TxOut[0].PkScript,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
m.finalizedWithdrawalTxns[tx.TxHash()] = tx
|
||||
m.mu.Unlock()
|
||||
m.mu.Lock()
|
||||
m.finalizedWithdrawalTxns[tx.TxHash()] = tx
|
||||
m.mu.Unlock()
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Wait for all goroutines to report back.
|
||||
if err := eg.Wait(); err != nil {
|
||||
return fmt.Errorf("error recovering withdrawals: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue