Browse Source

multi: integrate the new htlc v2 scripts to loop in/out

This commit bumps the current protocol version and integrates htlc v2
with loop in/out for new swaps, while keeping htlc v1 for any pending
swaps with previous protocol versions.
Andras Banki-Horvath 3 months ago
committed by András Bánki-Horváth
9 changed files with 143 additions and 97 deletions
  1. +12
  2. +2
  3. +8
  4. +2
  5. +5
  6. +5
  7. +85
  8. +3
  9. +21

+ 12
- 9
client.go View File

@ -175,9 +175,10 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
for _, swp := range loopOutSwaps {
htlc, err := swap.NewHtlc(
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
if err != nil {
return nil, err
@ -195,18 +196,20 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
for _, swp := range loopInSwaps {
htlcNP2WSH, err := swap.NewHtlc(
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcNP2WSH, s.lndServices.ChainParams,
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcNP2WSH,
if err != nil {
return nil, err
htlcP2WSH, err := swap.NewHtlc(
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
if err != nil {
return nil, err

+ 2
- 2
loopd/view.go View File

@ -50,7 +50,7 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
for _, s := range swaps {
htlc, err := swap.NewHtlc(
@ -102,7 +102,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
for _, s := range swaps {
htlc, err := swap.NewHtlc(

+ 8
- 1
loopdb/protocol_version.go View File

@ -31,13 +31,17 @@ const (
// propose a cltv expiry height for loop out.
ProtocolVersionUserExpiryLoopOut ProtocolVersion = 4
// ProtocolVersionHtlcV2 indicates that the client will use the new
// HTLC v2 scrips for swaps.
ProtocolVersionHtlcV2 ProtocolVersion = 5
// ProtocolVersionUnrecorded is set for swaps were created before we
// started saving protocol version with swaps.
ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
// CurrentRpcProtocolVersion defines the version of the RPC protocol
// that is currently supported by the loop client.
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_HTLC_V2
// CurrentInteranlProtocolVersionInternal defines the RPC current
// protocol in the internal representation.
@ -70,6 +74,9 @@ func (p ProtocolVersion) String() string {
case ProtocolVersionUserExpiryLoopOut:
return "User Expiry Loop Out"
case ProtocolVersionHtlcV2:
return "HTLC V2"
return "Unknown"

+ 2
- 0
loopdb/protocol_version_test.go View File

@ -19,6 +19,7 @@ func TestProtocolVersionSanity(t *testing.T) {
rpcVersions := [...]looprpc.ProtocolVersion{
@ -27,6 +28,7 @@ func TestProtocolVersionSanity(t *testing.T) {
require.Equal(t, len(versions), len(rpcVersions))

+ 5
- 2
loopin.go View File

@ -172,11 +172,13 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
MaxMinerFee: request.MaxMinerFee,
MaxSwapFee: request.MaxSwapFee,
Label: request.Label,
ProtocolVersion: loopdb.CurrentInternalProtocolVersion,
swapKit := newSwapKit(
swapHash, swap.TypeIn, cfg, &contract.SwapContract,
swapHash, swap.TypeIn,
cfg, &contract.SwapContract,
swapKit.lastUpdateTime = initiationTime
@ -217,7 +219,8 @@ func resumeLoopInSwap(reqContext context.Context, cfg *swapConfig,
log.Infof("Resuming loop in swap %v", hash)
swapKit := newSwapKit(
hash, swap.TypeIn, cfg, &pend.Contract.SwapContract,
hash, swap.TypeIn, cfg,
swap := &loopInSwap{

+ 5
- 2
loopout.go View File

@ -171,12 +171,14 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
MaxMinerFee: request.MaxMinerFee,
MaxSwapFee: request.MaxSwapFee,
Label: request.Label,
ProtocolVersion: loopdb.CurrentInternalProtocolVersion,
OutgoingChanSet: chanSet,
swapKit := newSwapKit(
swapHash, swap.TypeOut, cfg, &contract.SwapContract,
swapHash, swap.TypeOut,
cfg, &contract.SwapContract,
swapKit.lastUpdateTime = initiationTime
@ -223,7 +225,8 @@ func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig,
log.Infof("Resuming loop out swap %v", hash)
swapKit := newSwapKit(
hash, swap.TypeOut, cfg, &pend.Contract.SwapContract,
hash, swap.TypeOut, cfg,
// Create the htlc.

+ 85
- 80
looprpc/server.pb.go View File

@ -49,6 +49,8 @@ const (
ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT ProtocolVersion = 3
// The client will propose a cltv expiry height for loop out.
ProtocolVersion_USER_EXPIRY_LOOP_OUT ProtocolVersion = 4
// The client will use the new v2 HTLC scripts.
ProtocolVersion_HTLC_V2 ProtocolVersion = 5
var ProtocolVersion_name = map[int32]string{
@ -57,6 +59,7 @@ var ProtocolVersion_name = map[int32]string{
5: "HTLC_V2",
var ProtocolVersion_value = map[string]int32{
@ -65,6 +68,7 @@ var ProtocolVersion_value = map[string]int32{
"HTLC_V2": 5,
func (x ProtocolVersion) String() string {
@ -1185,87 +1189,88 @@ func init() {
func init() { proto.RegisterFile("server.proto", fileDescriptor_ad098daeda4239f7) }
var fileDescriptor_ad098daeda4239f7 = []byte{
// 1275 bytes of a gzipped FileDescriptorProto
// 1285 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xdd, 0x72, 0xdb, 0x44,
0x14, 0x46, 0xb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23,
0xb8, 0x9b, 0xe3, 0x00, 0xe8, 0xab, 0xfc, 0xd7, 0x72, 0xac, 0xaa, 0xb1, 0xf7, 0x31, 0x50, 0x51,
0x6d, 0xa6, 0x47, 0xfc, 0xef, 0xf4, 0x1a, 0x3d, 0xd2, 0x1f, 0xc9, 0xeb, 0xf4, 0x88, 0x0f, 0xe8,
0x40, 0x35, 0xed, 0xd5, 0x3b, 0x39, 0xd8, 0xec, 0x87, 0xa2, 0xd1, 0xb8, 0x1e, 0x82, 0x3a, 0xb0,
0x26, 0xd4, 0x35, 0xb8, 0xb3, 0xa3, 0x47, 0xb9, 0xe0, 0xe4, 0xa8, 0xed, 0x6b, 0xb2, 0x82, 0xac,
0x9d, 0xf4, 0x16, 0xb7, 0x9a, 0xdf, 0x5b, 0x86, 0xaa, 0x7a, 0x13, 0x44, 0x9c, 0x7a, 0x96, 0xf2,
0xe4, 0xac, 0x2d, 0xa2, 0xe6, 0xec, 0xf5, 0x7c, 0xd7, 0x6e, 0xec, 0x2e, 0x22, 0xf2, 0xad, 0xf5,
0x99, 0x84, 0x28, 0x6c, 0xe6, 0x3b, 0xe1, 0x47, 0xd4, 0xf9, 0x32, 0xbf, 0xce, 0x82, 0x99, 0x3e,
0x93, 0x4e, 0xca, 0xfc, 0xa3, 0xf0, 0xf5, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbf, 0xd7, 0x01,
0x1e, 0x88, 0x0f, 0x00, 0x00,
// Reference imports to suppress errors if they are not otherwise used.

+ 3
- 0
looprpc/server.proto View File

@ -57,6 +57,9 @@ enum ProtocolVersion {
// The client will propose a cltv expiry height for loop out.
// The client will use the new v2 HTLC scripts.
HTLC_V2 = 5;
message ServerLoopOutRequest {

+ 21
- 1
swap.go View File

@ -48,10 +48,30 @@ func newSwapKit(hash lntypes.Hash, swapType swap.Type, cfg *swapConfig,
// GetHtlcScriptVersion returns the correct HTLC script version for the passed
// protocol version.
func GetHtlcScriptVersion(
protocolVersion loopdb.ProtocolVersion) swap.ScriptVersion {
if protocolVersion != loopdb.ProtocolVersionUnrecorded &&
protocolVersion >= loopdb.ProtocolVersionHtlcV2 {
// Use HTLC v2 script only if we know the swap was initiated
// with a client that supports HTLC v2. Unrecorded protocol
// version implies that there was no protocol version stored
// along side a serialized swap that we're resuming in which
// case the swap was initiated with HTLC v1 script.
return swap.HtlcV2
return swap.HtlcV1
// getHtlc composes and returns the on-chain swap script.
func (s *swapKit) getHtlc(outputType swap.HtlcOutputType) (*swap.Htlc, error) {
return swap.NewHtlc(
swap.HtlcV1, s.contract.CltvExpiry, s.contract.SenderKey,
s.contract.CltvExpiry, s.contract.SenderKey,
s.contract.ReceiverKey, s.hash, outputType,