Merge pull request #306 from lightninglabs/label-tx

Update lndclient, add labels to on-chain transactions
pull/305/head
Oliver Gugger 4 years ago committed by GitHub
commit 62be092c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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=

@ -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)
}

@ -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)
}

@ -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)
}

@ -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

@ -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
}

Loading…
Cancel
Save