Skip to content

Commit 9aaef3f

Browse files
committed
loopin: use discovered htlc value for timeout tx
1 parent edac1a4 commit 9aaef3f

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

loopin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
419419
// the swap invoice is either settled or canceled. If the htlc times out, the
420420
// timeout tx will be published.
421421
func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
422-
htlc *wire.OutPoint, htlcValue btcutil.Amount) error {
422+
htlcOutpoint *wire.OutPoint, htlcValue btcutil.Amount) error {
423423

424424
// Register the htlc spend notification.
425425
rpcCtx, cancel := context.WithCancel(ctx)
@@ -445,7 +445,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
445445
// checkTimeout publishes the timeout tx if the contract has expired.
446446
checkTimeout := func() error {
447447
if s.height >= s.LoopInContract.CltvExpiry {
448-
return s.publishTimeoutTx(ctx, htlc)
448+
return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue)
449449
}
450450

451451
return nil
@@ -572,7 +572,7 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context,
572572
// publishTimeoutTx publishes a timeout tx after the on-chain htlc has expired.
573573
// The swap failed and we are reclaiming our funds.
574574
func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
575-
htlc *wire.OutPoint) error {
575+
htlcOutpoint *wire.OutPoint, htlcValue btcutil.Amount) error {
576576

577577
if s.timeoutAddr == nil {
578578
var err error
@@ -596,8 +596,8 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
596596
}
597597

598598
timeoutTx, err := s.sweeper.CreateSweepTx(
599-
ctx, s.height, s.htlc, *htlc, s.SenderKey, witnessFunc,
600-
s.LoopInContract.AmountRequested, fee, s.timeoutAddr,
599+
ctx, s.height, s.htlc, *htlcOutpoint, s.SenderKey, witnessFunc,
600+
htlcValue, fee, s.timeoutAddr,
601601
)
602602
if err != nil {
603603
return err

loopin_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,8 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
210210
ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry
211211

212212
// Expect a signing request for the htlc tx output value.
213-
//
214-
// TODO(joostjager): FIX BUG WHERE WE ALWAYS SIGN FOR THE HTLC AMOUNT.
215213
signReq := <-ctx.lnd.SignOutputRawChannel
216-
if signReq.SignDescriptors[0].Output.Value !=
217-
int64(testLoopInRequest.Amount) {
214+
if signReq.SignDescriptors[0].Output.Value != htlcTx.TxOut[0].Value {
218215

219216
t.Fatal("invalid signing amount")
220217
}

0 commit comments

Comments
 (0)