loopin: use discovered htlc value for timeout tx

pull/135/head
Joost Jager 4 years ago
parent edac1a4054
commit 9aaef3fd07
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -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 // the swap invoice is either settled or canceled. If the htlc times out, the
// timeout tx will be published. // timeout tx will be published.
func (s *loopInSwap) waitForSwapComplete(ctx context.Context, 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. // Register the htlc spend notification.
rpcCtx, cancel := context.WithCancel(ctx) 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 publishes the timeout tx if the contract has expired.
checkTimeout := func() error { checkTimeout := func() error {
if s.height >= s.LoopInContract.CltvExpiry { if s.height >= s.LoopInContract.CltvExpiry {
return s.publishTimeoutTx(ctx, htlc) return s.publishTimeoutTx(ctx, htlcOutpoint, htlcValue)
} }
return nil 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. // publishTimeoutTx publishes a timeout tx after the on-chain htlc has expired.
// The swap failed and we are reclaiming our funds. // The swap failed and we are reclaiming our funds.
func (s *loopInSwap) publishTimeoutTx(ctx context.Context, func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
htlc *wire.OutPoint) error { htlcOutpoint *wire.OutPoint, htlcValue btcutil.Amount) error {
if s.timeoutAddr == nil { if s.timeoutAddr == nil {
var err error var err error
@ -596,8 +596,8 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
} }
timeoutTx, err := s.sweeper.CreateSweepTx( timeoutTx, err := s.sweeper.CreateSweepTx(
ctx, s.height, s.htlc, *htlc, s.SenderKey, witnessFunc, ctx, s.height, s.htlc, *htlcOutpoint, s.SenderKey, witnessFunc,
s.LoopInContract.AmountRequested, fee, s.timeoutAddr, htlcValue, fee, s.timeoutAddr,
) )
if err != nil { if err != nil {
return err return err

@ -210,11 +210,8 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry
// Expect a signing request for the htlc tx output value. // 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 signReq := <-ctx.lnd.SignOutputRawChannel
if signReq.SignDescriptors[0].Output.Value != if signReq.SignDescriptors[0].Output.Value != htlcTx.TxOut[0].Value {
int64(testLoopInRequest.Amount) {
t.Fatal("invalid signing amount") t.Fatal("invalid signing amount")
} }

Loading…
Cancel
Save