Skip to content
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

StaticAddr: fix deposit detection #862

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions loopd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
ChainParams: d.lnd.ChainParams,
ChainNotifier: d.lnd.ChainNotifier,
Signer: d.lnd.Signer,
LndClient: d.lnd.Client,
}
depositManager = deposit.NewManager(depoCfg)

Expand Down
48 changes: 10 additions & 38 deletions staticaddr/deposit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type ManagerConfig struct {

// Signer is the signer client that is used to sign transactions.
Signer lndclient.SignerClient

// LndClient is used to add invoices and select hop hints.
LndClient lndclient.LightningClient
}

// Manager manages the address state machines.
Expand Down Expand Up @@ -280,11 +283,6 @@ func (m *Manager) reconcileDeposits(ctx context.Context) error {
func (m *Manager) createNewDeposit(ctx context.Context,
utxo *lnwallet.Utxo) (*Deposit, error) {

blockHeight, err := m.getBlockHeight(ctx, utxo)
if err != nil {
return nil, err
}

// Get the sweep pk script.
addr, err := m.cfg.WalletKit.NextAddr(
ctx, lnwallet.DefaultAccountName,
Expand All @@ -303,12 +301,18 @@ func (m *Manager) createNewDeposit(ctx context.Context,
if err != nil {
return nil, err
}

info, err := m.cfg.LndClient.GetInfo(ctx)
if err != nil {
return nil, err
}

deposit := &Deposit{
ID: id,
state: Deposited,
OutPoint: utxo.OutPoint,
Value: utxo.Value,
ConfirmationHeight: int64(blockHeight),
ConfirmationHeight: int64(info.BlockHeight),
TimeOutSweepPkScript: timeoutSweepPkScript,
}

Expand All @@ -324,38 +328,6 @@ func (m *Manager) createNewDeposit(ctx context.Context,
return deposit, nil
}

// getBlockHeight retrieves the block height of a given utxo.
func (m *Manager) getBlockHeight(ctx context.Context,
utxo *lnwallet.Utxo) (uint32, error) {

addressParams, err := m.cfg.AddressManager.GetStaticAddressParameters(
ctx,
)
if err != nil {
return 0, fmt.Errorf("couldn't get confirmation height for "+
"deposit, %w", err)
}

notifChan, errChan, err := m.cfg.ChainNotifier.RegisterConfirmationsNtfn( //nolint:lll
ctx, &utxo.OutPoint.Hash, addressParams.PkScript, MinConfs,
int32(m.initiationHeight),
)
if err != nil {
return 0, err
}

select {
case tx := <-notifChan:
return tx.BlockHeight, nil

case err := <-errChan:
return 0, err

case <-ctx.Done():
return 0, ctx.Err()
}
}

// filterNewDeposits filters the given utxos for new deposits that we haven't
// seen before.
func (m *Manager) filterNewDeposits(utxos []*lnwallet.Utxo) []*lnwallet.Utxo {
Expand Down
Loading