Skip to content

Commit 38ddbfb

Browse files
committed
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.
1 parent 3a3571b commit 38ddbfb

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-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=

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
}

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)