-
Notifications
You must be signed in to change notification settings - Fork 123
staticaddr: neutrino fixes #967
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
+61
−37
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc5113d
staticaddr: remove an unused interface method
starius 3ed8c7a
staticaddr/withdraw: log PublishTransaction start
starius 6f50b27
loopd: increase withdrawal manager start timeout
starius 38aaa4d
staticaddr: recover withdrawals in parallel
starius 6154219
staticaddr: use tx hash not *wire.MsgTx as a key
starius 51b7451
staticaddr: fix error formatting in the log
starius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ( | ||
|
@@ -226,44 +227,65 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the fix! |
||
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, | ||
) | ||
} | ||
|
||
// 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 txid, deposits := range depositsByWithdrawalTx { | ||
eg.Go(func() error { | ||
hieblmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} | ||
tx, ok := hash2tx[txid] | ||
if !ok { | ||
return fmt.Errorf("can't find tx %v", txid) | ||
} | ||
|
||
err = m.handleWithdrawal( | ||
ctx, deposits, tx.TxHash(), tx.TxOut[0].PkScript, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = m.publishFinalizedWithdrawalTx(ctx, tx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
m.mu.Lock() | ||
m.finalizedWithdrawalTxns[tx.TxHash()] = tx | ||
m.mu.Unlock() | ||
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() | ||
|
||
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 | ||
|
@@ -558,6 +580,9 @@ func (m *Manager) publishFinalizedWithdrawalTx(ctx context.Context, | |
"withdrawal tx is nil") | ||
} | ||
|
||
log.Debugf("Publishing deposit withdrawal with txid: %v ...", | ||
tx.TxHash()) | ||
|
||
txLabel := fmt.Sprintf("deposit-withdrawal-%v", tx.TxHash()) | ||
|
||
// Publish the withdrawal sweep transaction. | ||
|
@@ -577,7 +602,7 @@ func (m *Manager) publishFinalizedWithdrawalTx(ctx context.Context, | |
return false, nil | ||
} | ||
} else { | ||
log.Debugf("published deposit withdrawal with txid: %v", | ||
log.Debugf("Published deposit withdrawal with txid: %v", | ||
tx.TxHash()) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.