From 3a3571ba6f7f7445dced9bb2e86689f632a1ad4f Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Oct 2020 09:15:12 +0200 Subject: [PATCH 1/3] labels: add on-chain labels for loop in/out --- labels/lnd_labels.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 labels/lnd_labels.go diff --git a/labels/lnd_labels.go b/labels/lnd_labels.go new file mode 100644 index 0000000..c21dee5 --- /dev/null +++ b/labels/lnd_labels.go @@ -0,0 +1,37 @@ +package labels + +import "fmt" + +const ( + // loopdLabelPattern is the pattern that loop uses to label on-chain + // transactions in the lnd backend. + loopdLabelPattern = "loopd -- %s(swap=%s)" + + // loopOutSweepSuccess is the label used for loop out swaps to sweep + // the HTLC in the success case. + loopOutSweepSuccess = "OutSweepSuccess" + + // loopInHtlc is the label used for loop in swaps to publish an HTLC. + loopInHtlc = "InHtlc" + + // loopInTimeout is the label used for loop in swaps to sweep an HTLC + // that has timed out. + loopInSweepTimeout = "InSweepTimeout" +) + +// LoopOutSweepSuccess returns the label used for loop out swaps to sweep the +// HTLC in the success case. +func LoopOutSweepSuccess(swapHash string) string { + return fmt.Sprintf(loopdLabelPattern, loopOutSweepSuccess, swapHash) +} + +// LoopInHtlcLabel returns the label used for loop in swaps to publish an HTLC. +func LoopInHtlcLabel(swapHash string) string { + return fmt.Sprintf(loopdLabelPattern, loopInHtlc, swapHash) +} + +// LoopInSweepTimeout returns the label used for loop in swaps to sweep an HTLC +// that has timed out. +func LoopInSweepTimeout(swapHash string) string { + return fmt.Sprintf(loopdLabelPattern, loopInSweepTimeout, swapHash) +} From 38ddbfb45d6cfa8b9315fbfb00576ce77f89dec0 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Oct 2020 09:15:25 +0200 Subject: [PATCH 2/3] mod+loopin+loopout: update lndclient, add labels to TXs We update to the latest lndclient that now requires a label when publishing an on-chain transaction. Instead of just adding an empty string, we use the proper labels added in a previous commit. --- go.mod | 2 +- go.sum | 4 ++-- loopin.go | 13 ++++++++----- loopout.go | 6 +++++- test/walletkit_mock.go | 17 +++++++++++++++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 8ca6f9f..493b667 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/protobuf v1.3.2 github.com/grpc-ecosystem/grpc-gateway v1.14.3 github.com/jessevdk/go-flags v1.4.0 - github.com/lightninglabs/lndclient v0.11.0-0 + github.com/lightninglabs/lndclient v0.11.0-3 github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d github.com/lightningnetwork/lnd v0.11.1-beta.rc3 github.com/lightningnetwork/lnd/cert v1.0.3 diff --git a/go.sum b/go.sum index 2d18adf..c6011af 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc= github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk= -github.com/lightninglabs/lndclient v0.11.0-0 h1:tCvhlN/NNC/PeCjifONq/f8vU/6ZJS1ivXhpIfw6JfY= -github.com/lightninglabs/lndclient v0.11.0-0/go.mod h1:8/cTKNwgL87NX123gmlv3Xh6p1a7pvzu+40Un3PhHiI= +github.com/lightninglabs/lndclient v0.11.0-3 h1:x8co3UOeaUwh0iBFNeaPaqJsg8gvlgV/+fQHp2MT9eI= +github.com/lightninglabs/lndclient v0.11.0-3/go.mod h1:8/cTKNwgL87NX123gmlv3Xh6p1a7pvzu+40Un3PhHiI= github.com/lightninglabs/neutrino v0.11.0/go.mod h1:CuhF0iuzg9Sp2HO6ZgXgayviFTn1QHdSTJlMncK80wg= github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200 h1:j4iZ1XlUAPQmW6oSzMcJGILYsRHNs+4O3Gk+2Ms5Dww= github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200/go.mod h1:MlZmoKa7CJP3eR1s5yB7Rm5aSyadpKkxqAwLQmog7N0= diff --git a/loopin.go b/loopin.go index 0276412..689976c 100644 --- a/loopin.go +++ b/loopin.go @@ -14,6 +14,7 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/lightninglabs/lndclient" + "github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/swap" "github.com/lightningnetwork/lnd/chainntnfs" @@ -652,12 +653,11 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) { s.log.Infof("Publishing on chain HTLC with fee rate %v", feeRate) // Internal loop-in is always P2WSH. - tx, err := s.lnd.WalletKit.SendOutputs(ctx, - []*wire.TxOut{{ + tx, err := s.lnd.WalletKit.SendOutputs( + ctx, []*wire.TxOut{{ PkScript: s.htlcP2WSH.PkScript, Value: int64(s.LoopInContract.AmountRequested), - }}, - feeRate, + }}, feeRate, labels.LoopInHtlcLabel(swap.ShortHash(&s.hash)), ) if err != nil { return false, fmt.Errorf("send outputs: %v", err) @@ -874,7 +874,10 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context, s.log.Infof("Publishing timeout tx %v with fee %v to addr %v", timeoutTxHash, fee, s.timeoutAddr) - err = s.lnd.WalletKit.PublishTransaction(ctx, timeoutTx) + err = s.lnd.WalletKit.PublishTransaction( + ctx, timeoutTx, + labels.LoopInSweepTimeout(swap.ShortHash(&s.hash)), + ) if err != nil { s.log.Warnf("publish timeout: %v", err) } diff --git a/loopout.go b/loopout.go index b447a6d..dc10020 100644 --- a/loopout.go +++ b/loopout.go @@ -13,6 +13,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/lightninglabs/lndclient" + "github.com/lightninglabs/loop/labels" "github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/sweep" @@ -957,7 +958,10 @@ func (s *loopOutSwap) sweep(ctx context.Context, s.log.Infof("Sweep on chain HTLC to address %v with fee %v (tx %v)", s.DestAddr, fee, sweepTx.TxHash()) - err = s.lnd.WalletKit.PublishTransaction(ctx, sweepTx) + err = s.lnd.WalletKit.PublishTransaction( + ctx, sweepTx, + labels.LoopOutSweepSuccess(swap.ShortHash(&s.hash)), + ) if err != nil { s.log.Warnf("Publish sweep: %v", err) } diff --git a/test/walletkit_mock.go b/test/walletkit_mock.go index 45f2e09..c00ebca 100644 --- a/test/walletkit_mock.go +++ b/test/walletkit_mock.go @@ -80,14 +80,16 @@ func (m *mockWalletKit) NextAddr(ctx context.Context) (btcutil.Address, error) { return addr, nil } -func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx) error { +func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx, + _ string) error { + m.lnd.AddTx(tx) m.lnd.TxPublishChannel <- tx return nil } func (m *mockWalletKit) SendOutputs(ctx context.Context, outputs []*wire.TxOut, - feeRate chainfee.SatPerKWeight) (*wire.MsgTx, error) { + feeRate chainfee.SatPerKWeight, _ string) (*wire.MsgTx, error) { var inputTxHash chainhash.Hash @@ -131,3 +133,14 @@ func (m *mockWalletKit) EstimateFee(ctx context.Context, confTarget int32) ( func (m *mockWalletKit) ListSweeps(_ context.Context) ([]string, error) { return m.lnd.Sweeps, nil } + +// BumpFee attempts to bump the fee of a transaction by spending one of +// its outputs at the given fee rate. This essentially results in a +// child-pays-for-parent (CPFP) scenario. If the given output has been +// used in a previous BumpFee call, then a transaction replacing the +// previous is broadcast, resulting in a replace-by-fee (RBF) scenario. +func (m *mockWalletKit) BumpFee(context.Context, wire.OutPoint, + chainfee.SatPerKWeight) error { + + return nil +} From 6e71185a9badc883f737361bf9cb81e50099ab34 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Oct 2020 09:20:24 +0200 Subject: [PATCH 3/3] release_notes: add labels --- release_notes.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/release_notes.md b/release_notes.md index 79a8cc9..f24734a 100644 --- a/release_notes.md +++ b/release_notes.md @@ -9,6 +9,17 @@ This file tracks release notes for the loop client. * All of the items under the "Next Release" heading should be included in the release notes. * As part of the PR that bumps the client version, the "Next Release" heading should be replaced with the release version including the changes. +## Next release + +#### NewFeatures + +* The loop client now labels all its on-chain transactions to make them easily + identifiable in `lnd`'s `listchaintxns` output. + +#### Breaking Changes + +#### Bug Fixes + ## 0.10.0 #### New Features