From 9aaef3fd07b32bf3e006e66359b88b0f5138cf75 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 15 Jan 2020 09:17:01 +0100 Subject: [PATCH] loopin: use discovered htlc value for timeout tx --- loopin.go | 10 +++++----- loopin_test.go | 5 +---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/loopin.go b/loopin.go index c7632f4..f2f9846 100644 --- a/loopin.go +++ b/loopin.go @@ -419,7 +419,7 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) { // the swap invoice is either settled or canceled. If the htlc times out, the // timeout tx will be published. func (s *loopInSwap) waitForSwapComplete(ctx context.Context, - htlc *wire.OutPoint, htlcValue btcutil.Amount) error { + htlcOutpoint *wire.OutPoint, htlcValue btcutil.Amount) error { // Register the htlc spend notification. rpcCtx, cancel := context.WithCancel(ctx) @@ -445,7 +445,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context, // checkTimeout publishes the timeout tx if the contract has expired. checkTimeout := func() error { if s.height >= s.LoopInContract.CltvExpiry { - return s.publishTimeoutTx(ctx, htlc) + return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue) } return nil @@ -572,7 +572,7 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context, // publishTimeoutTx publishes a timeout tx after the on-chain htlc has expired. // The swap failed and we are reclaiming our funds. func (s *loopInSwap) publishTimeoutTx(ctx context.Context, - htlc *wire.OutPoint) error { + htlcOutpoint *wire.OutPoint, htlcValue btcutil.Amount) error { if s.timeoutAddr == nil { var err error @@ -596,8 +596,8 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context, } timeoutTx, err := s.sweeper.CreateSweepTx( - ctx, s.height, s.htlc, *htlc, s.SenderKey, witnessFunc, - s.LoopInContract.AmountRequested, fee, s.timeoutAddr, + ctx, s.height, s.htlc, *htlcOutpoint, s.SenderKey, witnessFunc, + htlcValue, fee, s.timeoutAddr, ) if err != nil { return err diff --git a/loopin_test.go b/loopin_test.go index b1b94b3..f74ac75 100644 --- a/loopin_test.go +++ b/loopin_test.go @@ -210,11 +210,8 @@ func testLoopInTimeout(t *testing.T, externalValue int64) { ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry // Expect a signing request for the htlc tx output value. - // - // TODO(joostjager): FIX BUG WHERE WE ALWAYS SIGN FOR THE HTLC AMOUNT. signReq := <-ctx.lnd.SignOutputRawChannel - if signReq.SignDescriptors[0].Output.Value != - int64(testLoopInRequest.Amount) { + if signReq.SignDescriptors[0].Output.Value != htlcTx.TxOut[0].Value { t.Fatal("invalid signing amount") }