Skip to content

Commit 84820f2

Browse files
authored
Merge pull request #917 from starius/register-conf-initiation-height
sweepbatcher: fix height hint for confirmations
2 parents ec2bf44 + 4c26aef commit 84820f2

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

sweepbatcher/sweep_batch.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -1707,13 +1707,20 @@ func (b *batch) monitorSpend(ctx context.Context, primarySweep sweep) error {
17071707

17081708
// monitorConfirmations monitors the batch transaction for confirmations.
17091709
func (b *batch) monitorConfirmations(ctx context.Context) error {
1710+
// Find initiationHeight.
1711+
primarySweep, ok := b.sweeps[b.primarySweepID]
1712+
if !ok {
1713+
return fmt.Errorf("can't find primarySweep")
1714+
}
1715+
17101716
reorgChan := make(chan struct{})
17111717

17121718
confCtx, cancel := context.WithCancel(ctx)
17131719

17141720
confChan, errChan, err := b.chainNotifier.RegisterConfirmationsNtfn(
17151721
confCtx, b.batchTxid, b.batchPkScript, batchConfHeight,
1716-
b.currentHeight, lndclient.WithReOrgChan(reorgChan),
1722+
primarySweep.initiationHeight,
1723+
lndclient.WithReOrgChan(reorgChan),
17171724
)
17181725
if err != nil {
17191726
cancel()

sweepbatcher/sweep_batcher_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,15 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
781781
Notifier: &dummyNotifier,
782782
}
783783

784+
const initiationHeight = 550
785+
784786
swap1 := &loopdb.LoopOutContract{
785787
SwapContract: loopdb.SwapContract{
786-
CltvExpiry: 111,
787-
AmountRequested: 111,
788-
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
789-
HtlcKeys: htlcKeys,
788+
CltvExpiry: 111,
789+
AmountRequested: 111,
790+
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
791+
HtlcKeys: htlcKeys,
792+
InitiationHeight: initiationHeight,
790793
},
791794

792795
DestAddr: destAddr,
@@ -871,14 +874,17 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
871874
SpendingTx: spendingTx,
872875
SpenderTxHash: &spendingTxHash,
873876
SpenderInputIndex: 0,
874-
SpendingHeight: 601,
875877
}
876878

877879
// We notify the spend.
878880
lnd.SpendChannel <- spendDetail
879881

880882
// After receiving the spend, the batch is now monitoring for confs.
881-
<-lnd.RegisterConfChannel
883+
confReg := <-lnd.RegisterConfChannel
884+
885+
// Make sure the confirmation has proper height hint. It should pass
886+
// the swap initiation height, not the current height.
887+
require.Equal(t, int32(initiationHeight), confReg.HeightHint)
882888

883889
// The batch should eventually read the spend notification and progress
884890
// its state to closed.

0 commit comments

Comments
 (0)