Skip to content

Commit 2108ddd

Browse files
committed
multi: retries for register spend and conf
1 parent a7d7371 commit 2108ddd

File tree

12 files changed

+288
-51
lines changed

12 files changed

+288
-51
lines changed

instantout/actions.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/lightninglabs/loop/loopdb"
1717
"github.com/lightninglabs/loop/swap"
1818
"github.com/lightninglabs/loop/swapserverrpc"
19+
"github.com/lightninglabs/loop/utils"
1920
"github.com/lightningnetwork/lnd/lnrpc"
2021
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2122
"github.com/lightningnetwork/lnd/lntypes"
@@ -460,11 +461,10 @@ func (f *FSM) WaitForSweeplessSweepConfirmedAction(ctx context.Context,
460461
return f.HandleError(err)
461462
}
462463

463-
confChan, confErrChan, err := f.cfg.ChainNotifier.
464-
RegisterConfirmationsNtfn(
465-
ctx, f.InstantOut.SweepTxHash, pkscript,
466-
1, f.InstantOut.initiationHeight,
467-
)
464+
confChan, confErrChan, err := utils.RegisterConfirmationsNtfnWithRetry(
465+
ctx, f.cfg.ChainNotifier, f.InstantOut.SweepTxHash, pkscript,
466+
1, f.InstantOut.initiationHeight,
467+
)
468468
if err != nil {
469469
return f.HandleError(err)
470470
}
@@ -505,12 +505,11 @@ func (f *FSM) PublishHtlcAction(ctx context.Context,
505505
f.Debugf("published htlc tx: %v", txHash)
506506

507507
// We'll now wait for the htlc to be confirmed.
508-
confChan, confErrChan, err := f.cfg.ChainNotifier.
509-
RegisterConfirmationsNtfn(
510-
ctx, &txHash,
511-
f.InstantOut.finalizedHtlcTx.TxOut[0].PkScript,
512-
1, f.InstantOut.initiationHeight,
513-
)
508+
confChan, confErrChan, err := utils.RegisterConfirmationsNtfnWithRetry(
509+
ctx, f.cfg.ChainNotifier, &txHash,
510+
f.InstantOut.finalizedHtlcTx.TxOut[0].PkScript,
511+
1, f.InstantOut.initiationHeight,
512+
)
514513
if err != nil {
515514
return f.HandleError(err)
516515
}
@@ -575,9 +574,9 @@ func (f *FSM) WaitForHtlcSweepConfirmedAction(ctx context.Context,
575574
return f.HandleError(err)
576575
}
577576

578-
confChan, confErrChan, err := f.cfg.ChainNotifier.RegisterConfirmationsNtfn(
579-
ctx, f.InstantOut.SweepTxHash, sweepPkScript,
580-
1, f.InstantOut.initiationHeight,
577+
confChan, confErrChan, err := utils.RegisterConfirmationsNtfnWithRetry(
578+
ctx, f.cfg.ChainNotifier, f.InstantOut.SweepTxHash,
579+
sweepPkScript, 1, f.InstantOut.initiationHeight,
581580
)
582581
if err != nil {
583582
return f.HandleError(err)

instantout/reservation/actions.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func (f *FSM) SubscribeToConfirmationAction(ctx context.Context,
9595
"initiation height: %v", f.reservation.ID, pkscript,
9696
f.reservation.InitiationHeight)
9797

98-
confChan, errConfChan, err := f.cfg.ChainNotifier.RegisterConfirmationsNtfn(
99-
callCtx, nil, pkscript, DefaultConfTarget,
100-
f.reservation.InitiationHeight,
98+
confChan, errConfChan, err := utils.RegisterConfirmationsNtfnWithRetry(
99+
callCtx, f.cfg.ChainNotifier, nil, pkscript,
100+
DefaultConfTarget, f.reservation.InitiationHeight,
101101
)
102102
if err != nil {
103103
f.Errorf("unable to subscribe to conf notification: %v", err)
@@ -173,8 +173,8 @@ func (f *FSM) AsyncWaitForExpiredOrSweptAction(ctx context.Context,
173173
return f.HandleError(err)
174174
}
175175

176-
spendChan, errSpendChan, err := f.cfg.ChainNotifier.RegisterSpendNtfn(
177-
notifCtx, f.reservation.Outpoint, pkScript,
176+
spendChan, errSpendChan, err := utils.RegisterSpendNtfnWithRetry(
177+
notifCtx, f.cfg.ChainNotifier, f.reservation.Outpoint, pkScript,
178178
f.reservation.InitiationHeight,
179179
)
180180
if err != nil {

loopin.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,9 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
702702
return nil, nil, nil
703703
}
704704

705-
return notifier.RegisterConfirmationsNtfn(
706-
ctx, s.htlcTxHash, htlc.PkScript, 1, s.InitiationHeight,
705+
return utils.RegisterConfirmationsNtfnWithRetry(
706+
ctx, notifier, s.htlcTxHash, htlc.PkScript, 1,
707+
s.InitiationHeight,
707708
)
708709
}
709710

@@ -867,8 +868,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
867868
// Register the htlc spend notification.
868869
rpcCtx, cancel := context.WithCancel(ctx)
869870
defer cancel()
870-
spendChan, spendErr, err := s.lnd.ChainNotifier.RegisterSpendNtfn(
871-
rpcCtx, htlcOutpoint, s.htlc.PkScript, s.InitiationHeight,
871+
spendChan, spendErr, err := utils.RegisterSpendNtfnWithRetry(
872+
rpcCtx, s.lnd.ChainNotifier, htlcOutpoint, s.htlc.PkScript,
873+
s.InitiationHeight,
872874
)
873875
if err != nil {
874876
return fmt.Errorf("register spend ntfn: %v", err)

loopout.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,10 @@ func (s *loopOutSwap) waitForConfirmedHtlc(globalCtx context.Context) (
10121012
ctx, cancel := context.WithCancel(globalCtx)
10131013
defer cancel()
10141014
htlcConfChan, htlcErrChan, err :=
1015-
s.lnd.ChainNotifier.RegisterConfirmationsNtfn(
1016-
ctx, s.htlcTxHash, s.htlc.PkScript,
1017-
int32(s.HtlcConfirmations), s.InitiationHeight,
1015+
utils.RegisterConfirmationsNtfnWithRetry(
1016+
ctx, s.lnd.ChainNotifier, s.htlcTxHash,
1017+
s.htlc.PkScript, int32(s.HtlcConfirmations),
1018+
s.InitiationHeight,
10181019
)
10191020
if err != nil {
10201021
return nil, err

staticaddr/deposit/actions.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/lightninglabs/lndclient"
1212
"github.com/lightninglabs/loop/fsm"
1313
"github.com/lightninglabs/loop/staticaddr/script"
14+
"github.com/lightninglabs/loop/utils"
1415
"github.com/lightningnetwork/lnd/lntypes"
1516
)
1617

@@ -123,8 +124,9 @@ func (f *FSM) WaitForExpirySweepAction(ctx context.Context,
123124
txID = &f.deposit.ExpirySweepTxid
124125
}
125126

126-
spendChan, errSpendChan, err := f.cfg.ChainNotifier.RegisterConfirmationsNtfn( //nolint:lll
127-
ctx, txID, f.deposit.TimeOutSweepPkScript, DefaultConfTarget,
127+
spendChan, errSpendChan, err := utils.RegisterConfirmationsNtfnWithRetry( //nolint:lll
128+
ctx, f.cfg.ChainNotifier, txID,
129+
f.deposit.TimeOutSweepPkScript, DefaultConfTarget,
128130
int32(f.deposit.ConfirmationHeight),
129131
)
130132
if err != nil {

staticaddr/deposit/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ func (m *Manager) getBlockHeight(ctx context.Context,
330330
}
331331

332332
notifChan, errChan, err :=
333-
m.cfg.ChainNotifier.RegisterConfirmationsNtfn(
334-
ctx, &utxo.OutPoint.Hash, addressParams.PkScript,
335-
MinConfs, addressParams.InitiationHeight,
333+
utils.RegisterConfirmationsNtfnWithRetry(
334+
ctx, m.cfg.ChainNotifier, &utxo.OutPoint.Hash,
335+
addressParams.PkScript, MinConfs,
336+
addressParams.InitiationHeight,
336337
)
337338
if err != nil {
338339
return 0, err

staticaddr/loopin/actions.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ func (f *FSM) MonitorInvoiceAndHtlcTxAction(ctx context.Context,
482482
registerHtlcConf := func() (chan *chainntnfs.TxConfirmation, chan error,
483483
error) {
484484

485-
return f.cfg.ChainNotifier.RegisterConfirmationsNtfn(
486-
ctx, nil, htlc.PkScript, defaultConfTarget,
487-
int32(f.loopIn.InitiationHeight),
485+
return utils.RegisterConfirmationsNtfnWithRetry(
486+
ctx, f.cfg.ChainNotifier, nil, htlc.PkScript,
487+
defaultConfTarget, int32(f.loopIn.InitiationHeight),
488488
lndclient.WithReOrgChan(reorgChan),
489489
)
490490
}
@@ -732,8 +732,8 @@ func (f *FSM) MonitorHtlcTimeoutSweepAction(ctx context.Context,
732732
}
733733

734734
htlcTimeoutTxidChan, errChan, err :=
735-
f.cfg.ChainNotifier.RegisterConfirmationsNtfn(
736-
ctx, f.loopIn.HtlcTimeoutSweepTxHash,
735+
utils.RegisterConfirmationsNtfnWithRetry(
736+
ctx, f.cfg.ChainNotifier, f.loopIn.HtlcTimeoutSweepTxHash,
737737
timeoutSweepPkScript, defaultConfTarget,
738738
int32(f.loopIn.InitiationHeight),
739739
)

staticaddr/withdraw/manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ func (m *Manager) handleWithdrawal(ctx context.Context,
640640
}
641641

642642
d := deposits[0]
643-
spentChan, errChan, err := m.cfg.ChainNotifier.RegisterSpendNtfn(
644-
ctx, &d.OutPoint, addrParams.PkScript,
643+
spentChan, errChan, err := utils.RegisterSpendNtfnWithRetry(
644+
ctx, m.cfg.ChainNotifier, &d.OutPoint, addrParams.PkScript,
645645
int32(d.ConfirmationHeight),
646646
)
647647

@@ -654,8 +654,9 @@ func (m *Manager) handleWithdrawal(ctx context.Context,
654654
// confirmations.
655655
var confChan chan *chainntnfs.TxConfirmation
656656
confChan, errChan, err =
657-
m.cfg.ChainNotifier.RegisterConfirmationsNtfn(
658-
ctx, spentTx.SpenderTxHash,
657+
utils.RegisterConfirmationsNtfnWithRetry(
658+
ctx, m.cfg.ChainNotifier,
659+
spentTx.SpenderTxHash,
659660
withdrawalPkscript, MinConfs,
660661
int32(m.initiationHeight.Load()),
661662
)

sweepbatcher/sweep_batch.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,9 @@ func (b *batch) monitorSpend(ctx context.Context, primarySweep sweep) error {
19961996

19971997
reorgChan := make(chan struct{}, 1)
19981998

1999-
spendChan, spendErrChan, err := b.chainNotifier.RegisterSpendNtfn(
2000-
ctx, &primarySweep.outpoint, primarySweep.htlc.PkScript,
2001-
primarySweep.initiationHeight,
1999+
spendChan, spendErrChan, err := utils.RegisterSpendNtfnWithRetry(
2000+
ctx, b.chainNotifier, &primarySweep.outpoint,
2001+
primarySweep.htlc.PkScript, primarySweep.initiationHeight,
20022002
lndclient.WithReOrgChan(reorgChan),
20032003
)
20042004
if err != nil {
@@ -2030,9 +2030,9 @@ func (b *batch) monitorConfirmations(ctx context.Context) error {
20302030

20312031
confCtx, cancel := context.WithCancel(ctx)
20322032

2033-
confChan, errChan, err := b.chainNotifier.RegisterConfirmationsNtfn(
2034-
confCtx, b.batchTxid, b.batchPkScript, batchConfHeight,
2035-
primarySweep.initiationHeight,
2033+
confChan, errChan, err := utils.RegisterConfirmationsNtfnWithRetry(
2034+
confCtx, b.chainNotifier, b.batchTxid, b.batchPkScript,
2035+
batchConfHeight, primarySweep.initiationHeight,
20362036
)
20372037
if err != nil {
20382038
cancel()

sweepbatcher/sweep_batcher.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,8 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweeps []*sweep,
12841284

12851285
sweep := sweeps[0]
12861286

1287-
spendChan, spendErr, err := b.chainNotifier.RegisterSpendNtfn(
1288-
spendCtx, &sweep.outpoint, sweep.htlc.PkScript,
1287+
spendChan, spendErr, err := utils.RegisterSpendNtfnWithRetry(
1288+
spendCtx, b.chainNotifier, &sweep.outpoint, sweep.htlc.PkScript,
12891289
sweep.initiationHeight,
12901290
)
12911291
if err != nil {
@@ -1412,9 +1412,10 @@ func (b *Batcher) monitorConfAndNotify(ctx context.Context, sweep *sweep,
14121412

14131413
confCtx, cancel := context.WithCancel(ctx)
14141414

1415-
confChan, errChan, err := b.chainNotifier.RegisterConfirmationsNtfn(
1416-
confCtx, &batchTxid, batchPkScript, batchConfHeight,
1417-
sweep.initiationHeight, lndclient.WithReOrgChan(reorgChan),
1415+
confChan, errChan, err := utils.RegisterConfirmationsNtfnWithRetry(
1416+
confCtx, b.chainNotifier, &batchTxid, batchPkScript,
1417+
batchConfHeight, sweep.initiationHeight,
1418+
lndclient.WithReOrgChan(reorgChan),
14181419
)
14191420
if err != nil {
14201421
cancel()

0 commit comments

Comments
 (0)