Skip to content

Commit 78e35d4

Browse files
authored
Merge pull request #535 from bhandras/sunset-htlcv1
multi: sunset support for nested segwit HTLCs
2 parents 17a1a3f + 7341a14 commit 78e35d4

16 files changed

+414
-775
lines changed

client.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,6 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
267267

268268
swapInfo.HtlcAddressP2TR = htlcP2TR.Address
269269
} else {
270-
htlcNP2WSH, err := swap.NewHtlc(
271-
swap.HtlcV1, swp.Contract.CltvExpiry,
272-
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
273-
swp.Hash, swap.HtlcNP2WSH,
274-
s.lndServices.ChainParams,
275-
)
276-
if err != nil {
277-
return nil, err
278-
}
279-
280270
htlcP2WSH, err := swap.NewHtlc(
281271
swap.HtlcV2, swp.Contract.CltvExpiry,
282272
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
@@ -288,7 +278,6 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
288278
}
289279

290280
swapInfo.HtlcAddressP2WSH = htlcP2WSH.Address
291-
swapInfo.HtlcAddressNP2WSH = htlcNP2WSH.Address
292281
}
293282

294283
swaps = append(swaps, swapInfo)
@@ -615,7 +604,6 @@ func (s *Client) LoopIn(globalCtx context.Context,
615604
}
616605

617606
if loopdb.CurrentProtocolVersion() < loopdb.ProtocolVersionHtlcV3 {
618-
swapInfo.HtlcAddressNP2WSH = swap.htlcNP2WSH.Address
619607
swapInfo.HtlcAddressP2WSH = swap.htlcP2WSH.Address
620608
} else {
621609
swapInfo.HtlcAddressP2TR = swap.htlcP2TR.Address

client_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,6 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
370370

371371
var preImageIndex int
372372
switch scriptVersion {
373-
case swap.HtlcV1:
374-
preImageIndex = 1
375-
376373
case swap.HtlcV2:
377374
preImageIndex = 0
378375

cmd/loop/loopin.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ func loopIn(ctx *cli.Context) error {
208208
if resp.HtlcAddressP2Tr != "" {
209209
fmt.Printf("HTLC address (P2TR): %v\n", resp.HtlcAddressP2Tr)
210210
} else {
211-
if external {
212-
fmt.Printf("HTLC address (NP2WSH): %v\n",
213-
resp.HtlcAddressNp2Wsh)
214-
}
215211
fmt.Printf("HTLC address (P2WSH): %v\n", resp.HtlcAddressP2Wsh)
216212
}
217213

cmd/loop/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ func logSwap(swap *looprpc.SwapStatus) {
350350
fmt.Printf(" P2WSH: %v", swap.HtlcAddressP2Wsh)
351351
}
352352

353-
if swap.HtlcAddressNp2Wsh != "" {
354-
fmt.Printf(" NP2WSH: %v", swap.HtlcAddressNp2Wsh)
355-
}
356-
357353
if swap.HtlcAddressP2Tr != "" {
358354
fmt.Printf(" P2TR: %v", swap.HtlcAddressP2Tr)
359355
}

interface.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ type LoopInSwapInfo struct { // nolint
294294
// where the loop-in funds may be paid.
295295
HtlcAddressP2WSH btcutil.Address
296296

297-
// HtlcAddressNP2WSH contains the nested segwit swap htlc address,
298-
// where the loop-in funds may be paid.
299-
HtlcAddressNP2WSH btcutil.Address
300-
301297
// HtlcAddresP2TR contains the v3 (pay to taproot) htlc address.
302298
HtlcAddressP2TR btcutil.Address
303299

@@ -350,10 +346,6 @@ type SwapInfo struct {
350346
// swap htlc. This is used for both loop-in and loop-out.
351347
HtlcAddressP2WSH btcutil.Address
352348

353-
// HtlcAddressNP2WSH stores the address of the NP2WSH (nested segwit)
354-
// swap htlc. This is only used for external loop-in.
355-
HtlcAddressNP2WSH btcutil.Address
356-
357349
// HtlcAddressP2TR stores the address of the P2TR (taproot) swap htlc.
358350
// This is used for both internal and external loop-in and loop out.
359351
HtlcAddressP2TR btcutil.Address

liquidity/liquidity.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
406406
}
407407

408408
log.Infof("loop in automatically dispatched: hash: %v, "+
409-
"address: np2wsh(%v), p2wsh(%v), p2tr(%v)",
410-
loopIn.SwapHash, loopIn.HtlcAddressNP2WSH,
409+
"address: p2wsh(%v), p2tr(%v)", loopIn.SwapHash,
411410
loopIn.HtlcAddressP2WSH, loopIn.HtlcAddressP2TR)
412411
}
413412

loopd/swapclient_server.go

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
230230

231231
var swapType clientrpc.SwapType
232232
var (
233-
htlcAddress string
234-
htlcAddressP2TR string
235-
htlcAddressP2WSH string
236-
htlcAddressNP2WSH string
233+
htlcAddress string
234+
htlcAddressP2TR string
235+
htlcAddressP2WSH string
237236
)
238237
var outGoingChanSet []uint64
239238
var lastHop []byte
@@ -248,14 +247,7 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
248247
} else {
249248
htlcAddressP2WSH =
250249
loopSwap.HtlcAddressP2WSH.EncodeAddress()
251-
252-
if loopSwap.ExternalHtlc {
253-
htlcAddressNP2WSH =
254-
loopSwap.HtlcAddressNP2WSH.EncodeAddress()
255-
htlcAddress = htlcAddressNP2WSH
256-
} else {
257-
htlcAddress = htlcAddressP2WSH
258-
}
250+
htlcAddress = htlcAddressP2WSH
259251
}
260252

261253
if loopSwap.LastHop != nil {
@@ -279,24 +271,23 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
279271
}
280272

281273
return &clientrpc.SwapStatus{
282-
Amt: int64(loopSwap.AmountRequested),
283-
Id: loopSwap.SwapHash.String(),
284-
IdBytes: loopSwap.SwapHash[:],
285-
State: state,
286-
FailureReason: failureReason,
287-
InitiationTime: loopSwap.InitiationTime.UnixNano(),
288-
LastUpdateTime: loopSwap.LastUpdate.UnixNano(),
289-
HtlcAddress: htlcAddress,
290-
HtlcAddressP2Tr: htlcAddressP2TR,
291-
HtlcAddressP2Wsh: htlcAddressP2WSH,
292-
HtlcAddressNp2Wsh: htlcAddressNP2WSH,
293-
Type: swapType,
294-
CostServer: int64(loopSwap.Cost.Server),
295-
CostOnchain: int64(loopSwap.Cost.Onchain),
296-
CostOffchain: int64(loopSwap.Cost.Offchain),
297-
Label: loopSwap.Label,
298-
LastHop: lastHop,
299-
OutgoingChanSet: outGoingChanSet,
274+
Amt: int64(loopSwap.AmountRequested),
275+
Id: loopSwap.SwapHash.String(),
276+
IdBytes: loopSwap.SwapHash[:],
277+
State: state,
278+
FailureReason: failureReason,
279+
InitiationTime: loopSwap.InitiationTime.UnixNano(),
280+
LastUpdateTime: loopSwap.LastUpdate.UnixNano(),
281+
HtlcAddress: htlcAddress,
282+
HtlcAddressP2Tr: htlcAddressP2TR,
283+
HtlcAddressP2Wsh: htlcAddressP2WSH,
284+
Type: swapType,
285+
CostServer: int64(loopSwap.Cost.Server),
286+
CostOnchain: int64(loopSwap.Cost.Onchain),
287+
CostOffchain: int64(loopSwap.Cost.Offchain),
288+
Label: loopSwap.Label,
289+
LastHop: lastHop,
290+
OutgoingChanSet: outGoingChanSet,
300291
}, nil
301292
}
302293

@@ -701,15 +692,9 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
701692
}
702693

703694
if loopdb.CurrentProtocolVersion() < loopdb.ProtocolVersionHtlcV3 {
704-
if req.ExternalHtlc {
705-
np2wshAddr := swapInfo.HtlcAddressNP2WSH.String()
706-
response.HtlcAddress = np2wshAddr
707-
response.HtlcAddressNp2Wsh = np2wshAddr
708-
} else {
709-
p2wshAddr := swapInfo.HtlcAddressP2WSH.String()
710-
response.HtlcAddress = p2wshAddr
711-
response.HtlcAddressP2Wsh = p2wshAddr
712-
}
695+
p2wshAddr := swapInfo.HtlcAddressP2WSH.String()
696+
response.HtlcAddress = p2wshAddr
697+
response.HtlcAddressP2Wsh = p2wshAddr
713698
} else {
714699
p2trAddr := swapInfo.HtlcAddressP2TR.String()
715700
response.HtlcAddress = p2trAddr

loopd/view.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,24 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
4949
}
5050

5151
for _, s := range swaps {
52+
scriptVersion := loop.GetHtlcScriptVersion(
53+
s.Contract.ProtocolVersion,
54+
)
55+
56+
var outputType swap.HtlcOutputType
57+
switch scriptVersion {
58+
case swap.HtlcV2:
59+
outputType = swap.HtlcP2WSH
60+
61+
case swap.HtlcV3:
62+
outputType = swap.HtlcP2TR
63+
}
5264
htlc, err := swap.NewHtlc(
5365
loop.GetHtlcScriptVersion(s.Contract.ProtocolVersion),
5466
s.Contract.CltvExpiry,
5567
s.Contract.SenderKey,
5668
s.Contract.ReceiverKey,
57-
s.Hash, swap.HtlcP2WSH, chainParams,
69+
s.Hash, outputType, chainParams,
5870
)
5971
if err != nil {
6072
return err
@@ -106,7 +118,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
106118
s.Contract.CltvExpiry,
107119
s.Contract.SenderKey,
108120
s.Contract.ReceiverKey,
109-
s.Hash, swap.HtlcNP2WSH, chainParams,
121+
s.Hash, swap.HtlcP2WSH, chainParams,
110122
)
111123
if err != nil {
112124
return err

loopin.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ type loopInSwap struct {
6161

6262
htlcP2WSH *swap.Htlc
6363

64-
htlcNP2WSH *swap.Htlc
65-
6664
htlcP2TR *swap.Htlc
6765

6866
// htlcTxHash is the confirmed htlc tx id.
@@ -423,17 +421,9 @@ func (s *loopInSwap) initHtlcs() error {
423421
return err
424422
}
425423

426-
htlcNP2WSH, err := s.swapKit.getHtlc(swap.HtlcNP2WSH)
427-
if err != nil {
428-
return err
429-
}
430-
431424
// Log htlc addresses for debugging.
432425
s.swapKit.log.Infof("Htlc address (P2WSH): %v", htlcP2WSH.Address)
433-
s.swapKit.log.Infof("Htlc address (NP2WSH): %v", htlcNP2WSH.Address)
434-
435426
s.htlcP2WSH = htlcP2WSH
436-
s.htlcNP2WSH = htlcNP2WSH
437427

438428
return nil
439429
}
@@ -447,7 +437,6 @@ func (s *loopInSwap) sendUpdate(ctx context.Context) error {
447437
info.HtlcAddressP2TR = s.htlcP2TR.Address
448438
} else {
449439
info.HtlcAddressP2WSH = s.htlcP2WSH.Address
450-
info.HtlcAddressNP2WSH = s.htlcNP2WSH.Address
451440
}
452441

453442
info.ExternalHtlc = s.ExternalHtlc
@@ -643,11 +632,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
643632
return nil, err
644633
}
645634

646-
confChanNP2WSH, confErrNP2WSH, err := notifyConfirmation(s.htlcNP2WSH)
647-
if err != nil {
648-
return nil, err
649-
}
650-
651635
confChanP2TR, confErrP2TR, err := notifyConfirmation(s.htlcP2TR)
652636
if err != nil {
653637
return nil, err
@@ -662,11 +646,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
662646
s.htlc = s.htlcP2WSH
663647
s.log.Infof("P2WSH htlc confirmed")
664648

665-
// NP2WSH htlc confirmed.
666-
case conf = <-confChanNP2WSH:
667-
s.htlc = s.htlcNP2WSH
668-
s.log.Infof("NP2WSH htlc confirmed")
669-
670649
// P2TR htlc confirmed.
671650
case conf = <-confChanP2TR:
672651
s.htlc = s.htlcP2TR
@@ -676,10 +655,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
676655
case err := <-confErrP2WSH:
677656
return nil, err
678657

679-
// Conf ntfn error.
680-
case err := <-confErrNP2WSH:
681-
return nil, err
682-
683658
// Conf ntfn error.
684659
case err := <-confErrP2TR:
685660
return nil, err

loopin_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ func testLoopInSuccess(t *testing.T) {
104104
// Expect register for htlc conf (only one, since the htlc is p2tr).
105105
<-ctx.lnd.RegisterConfChannel
106106

107-
// If the swap is legacy, then we'll register two confirmation
108-
// notifications.
109-
if !IsTaprootSwap(&inSwap.SwapContract) {
110-
<-ctx.lnd.RegisterConfChannel
111-
}
112-
113107
// Confirm htlc.
114108
ctx.lnd.ConfChannel <- &chainntnfs.TxConfirmation{
115109
Tx: &htlcTx,
@@ -266,11 +260,7 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
266260
// Create an external htlc publish tx.
267261
var pkScript []byte
268262
if !IsTaprootSwap(&inSwap.SwapContract) {
269-
if req.ExternalHtlc {
270-
pkScript = inSwap.htlcNP2WSH.PkScript
271-
} else {
272-
pkScript = inSwap.htlcP2WSH.PkScript
273-
}
263+
pkScript = inSwap.htlcP2WSH.PkScript
274264
} else {
275265
pkScript = inSwap.htlcP2TR.PkScript
276266
}
@@ -288,12 +278,6 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
288278
// Expect register for htlc conf.
289279
<-ctx.lnd.RegisterConfChannel
290280

291-
// If the swap is legacy, then we'll register two confirmation
292-
// notifications.
293-
if !IsTaprootSwap(&inSwap.SwapContract) {
294-
<-ctx.lnd.RegisterConfChannel
295-
}
296-
297281
// Confirm htlc.
298282
ctx.lnd.ConfChannel <- &chainntnfs.TxConfirmation{
299283
Tx: &htlcTx,
@@ -473,7 +457,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
473457

474458
scriptVersion := GetHtlcScriptVersion(storedVersion)
475459

476-
outputType := swap.HtlcNP2WSH
460+
outputType := swap.HtlcP2WSH
477461
if scriptVersion == swap.HtlcV3 {
478462
outputType = swap.HtlcP2TR
479463
}
@@ -571,12 +555,6 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
571555
// Expect register for htlc conf.
572556
<-ctx.lnd.RegisterConfChannel
573557

574-
// If the swap is legacy, then we'll register two confirmation
575-
// notifications.
576-
if !IsTaprootSwap(&inSwap.SwapContract) {
577-
<-ctx.lnd.RegisterConfChannel
578-
}
579-
580558
// Confirm htlc.
581559
ctx.lnd.ConfChannel <- &chainntnfs.TxConfirmation{
582560
Tx: &htlcTx,

0 commit comments

Comments
 (0)