Browse Source

loopin: use discovered htlc value for timeout tx

pull/135/head
Joost Jager 1 year ago
parent
commit
9aaef3fd07
No known key found for this signature in database GPG Key ID: A61B9D4C393C59C7
2 changed files with 6 additions and 9 deletions
  1. +5
    -5
      loopin.go
  2. +1
    -4
      loopin_test.go

+ 5
- 5
loopin.go View File

@ -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

+ 1
- 4
loopin_test.go View File

@ -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")
}

Loading…
Cancel
Save