Skip to content

Commit 62be092

Browse files
authored
Merge pull request #306 from lightninglabs/label-tx
Update lndclient, add labels to on-chain transactions
2 parents afc41ad + 6e71185 commit 62be092

File tree

7 files changed

+79
-11
lines changed

7 files changed

+79
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/golang/protobuf v1.3.2
1111
github.com/grpc-ecosystem/grpc-gateway v1.14.3
1212
github.com/jessevdk/go-flags v1.4.0
13-
github.com/lightninglabs/lndclient v0.11.0-0
13+
github.com/lightninglabs/lndclient v0.11.0-3
1414
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d
1515
github.com/lightningnetwork/lnd v0.11.1-beta.rc3
1616
github.com/lightningnetwork/lnd/cert v1.0.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
178178
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
179179
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc=
180180
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk=
181-
github.com/lightninglabs/lndclient v0.11.0-0 h1:tCvhlN/NNC/PeCjifONq/f8vU/6ZJS1ivXhpIfw6JfY=
182-
github.com/lightninglabs/lndclient v0.11.0-0/go.mod h1:8/cTKNwgL87NX123gmlv3Xh6p1a7pvzu+40Un3PhHiI=
181+
github.com/lightninglabs/lndclient v0.11.0-3 h1:x8co3UOeaUwh0iBFNeaPaqJsg8gvlgV/+fQHp2MT9eI=
182+
github.com/lightninglabs/lndclient v0.11.0-3/go.mod h1:8/cTKNwgL87NX123gmlv3Xh6p1a7pvzu+40Un3PhHiI=
183183
github.com/lightninglabs/neutrino v0.11.0/go.mod h1:CuhF0iuzg9Sp2HO6ZgXgayviFTn1QHdSTJlMncK80wg=
184184
github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200 h1:j4iZ1XlUAPQmW6oSzMcJGILYsRHNs+4O3Gk+2Ms5Dww=
185185
github.com/lightninglabs/neutrino v0.11.1-0.20200316235139-bffc52e8f200/go.mod h1:MlZmoKa7CJP3eR1s5yB7Rm5aSyadpKkxqAwLQmog7N0=

labels/lnd_labels.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package labels
2+
3+
import "fmt"
4+
5+
const (
6+
// loopdLabelPattern is the pattern that loop uses to label on-chain
7+
// transactions in the lnd backend.
8+
loopdLabelPattern = "loopd -- %s(swap=%s)"
9+
10+
// loopOutSweepSuccess is the label used for loop out swaps to sweep
11+
// the HTLC in the success case.
12+
loopOutSweepSuccess = "OutSweepSuccess"
13+
14+
// loopInHtlc is the label used for loop in swaps to publish an HTLC.
15+
loopInHtlc = "InHtlc"
16+
17+
// loopInTimeout is the label used for loop in swaps to sweep an HTLC
18+
// that has timed out.
19+
loopInSweepTimeout = "InSweepTimeout"
20+
)
21+
22+
// LoopOutSweepSuccess returns the label used for loop out swaps to sweep the
23+
// HTLC in the success case.
24+
func LoopOutSweepSuccess(swapHash string) string {
25+
return fmt.Sprintf(loopdLabelPattern, loopOutSweepSuccess, swapHash)
26+
}
27+
28+
// LoopInHtlcLabel returns the label used for loop in swaps to publish an HTLC.
29+
func LoopInHtlcLabel(swapHash string) string {
30+
return fmt.Sprintf(loopdLabelPattern, loopInHtlc, swapHash)
31+
}
32+
33+
// LoopInSweepTimeout returns the label used for loop in swaps to sweep an HTLC
34+
// that has timed out.
35+
func LoopInSweepTimeout(swapHash string) string {
36+
return fmt.Sprintf(loopdLabelPattern, loopInSweepTimeout, swapHash)
37+
}

loopin.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/btcsuite/btcd/chaincfg/chainhash"
1515
"github.com/btcsuite/btcd/wire"
1616
"github.com/lightninglabs/lndclient"
17+
"github.com/lightninglabs/loop/labels"
1718
"github.com/lightninglabs/loop/loopdb"
1819
"github.com/lightninglabs/loop/swap"
1920
"github.com/lightningnetwork/lnd/chainntnfs"
@@ -652,12 +653,11 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
652653
s.log.Infof("Publishing on chain HTLC with fee rate %v", feeRate)
653654

654655
// Internal loop-in is always P2WSH.
655-
tx, err := s.lnd.WalletKit.SendOutputs(ctx,
656-
[]*wire.TxOut{{
656+
tx, err := s.lnd.WalletKit.SendOutputs(
657+
ctx, []*wire.TxOut{{
657658
PkScript: s.htlcP2WSH.PkScript,
658659
Value: int64(s.LoopInContract.AmountRequested),
659-
}},
660-
feeRate,
660+
}}, feeRate, labels.LoopInHtlcLabel(swap.ShortHash(&s.hash)),
661661
)
662662
if err != nil {
663663
return false, fmt.Errorf("send outputs: %v", err)
@@ -874,7 +874,10 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
874874
s.log.Infof("Publishing timeout tx %v with fee %v to addr %v",
875875
timeoutTxHash, fee, s.timeoutAddr)
876876

877-
err = s.lnd.WalletKit.PublishTransaction(ctx, timeoutTx)
877+
err = s.lnd.WalletKit.PublishTransaction(
878+
ctx, timeoutTx,
879+
labels.LoopInSweepTimeout(swap.ShortHash(&s.hash)),
880+
)
878881
if err != nil {
879882
s.log.Warnf("publish timeout: %v", err)
880883
}

loopout.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/btcsuite/btcd/wire"
1414
"github.com/btcsuite/btcutil"
1515
"github.com/lightninglabs/lndclient"
16+
"github.com/lightninglabs/loop/labels"
1617
"github.com/lightninglabs/loop/loopdb"
1718
"github.com/lightninglabs/loop/swap"
1819
"github.com/lightninglabs/loop/sweep"
@@ -957,7 +958,10 @@ func (s *loopOutSwap) sweep(ctx context.Context,
957958
s.log.Infof("Sweep on chain HTLC to address %v with fee %v (tx %v)",
958959
s.DestAddr, fee, sweepTx.TxHash())
959960

960-
err = s.lnd.WalletKit.PublishTransaction(ctx, sweepTx)
961+
err = s.lnd.WalletKit.PublishTransaction(
962+
ctx, sweepTx,
963+
labels.LoopOutSweepSuccess(swap.ShortHash(&s.hash)),
964+
)
961965
if err != nil {
962966
s.log.Warnf("Publish sweep: %v", err)
963967
}

release_notes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ This file tracks release notes for the loop client.
99
* All of the items under the "Next Release" heading should be included in the release notes.
1010
* As part of the PR that bumps the client version, the "Next Release" heading should be replaced with the release version including the changes.
1111

12+
## Next release
13+
14+
#### NewFeatures
15+
16+
* The loop client now labels all its on-chain transactions to make them easily
17+
identifiable in `lnd`'s `listchaintxns` output.
18+
19+
#### Breaking Changes
20+
21+
#### Bug Fixes
22+
1223
## 0.10.0
1324

1425
#### New Features

test/walletkit_mock.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ func (m *mockWalletKit) NextAddr(ctx context.Context) (btcutil.Address, error) {
8080
return addr, nil
8181
}
8282

83-
func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx) error {
83+
func (m *mockWalletKit) PublishTransaction(ctx context.Context, tx *wire.MsgTx,
84+
_ string) error {
85+
8486
m.lnd.AddTx(tx)
8587
m.lnd.TxPublishChannel <- tx
8688
return nil
8789
}
8890

8991
func (m *mockWalletKit) SendOutputs(ctx context.Context, outputs []*wire.TxOut,
90-
feeRate chainfee.SatPerKWeight) (*wire.MsgTx, error) {
92+
feeRate chainfee.SatPerKWeight, _ string) (*wire.MsgTx, error) {
9193

9294
var inputTxHash chainhash.Hash
9395

@@ -131,3 +133,14 @@ func (m *mockWalletKit) EstimateFee(ctx context.Context, confTarget int32) (
131133
func (m *mockWalletKit) ListSweeps(_ context.Context) ([]string, error) {
132134
return m.lnd.Sweeps, nil
133135
}
136+
137+
// BumpFee attempts to bump the fee of a transaction by spending one of
138+
// its outputs at the given fee rate. This essentially results in a
139+
// child-pays-for-parent (CPFP) scenario. If the given output has been
140+
// used in a previous BumpFee call, then a transaction replacing the
141+
// previous is broadcast, resulting in a replace-by-fee (RBF) scenario.
142+
func (m *mockWalletKit) BumpFee(context.Context, wire.OutPoint,
143+
chainfee.SatPerKWeight) error {
144+
145+
return nil
146+
}

0 commit comments

Comments
 (0)