Skip to content

Commit

Permalink
Merge pull request #376 from lightninglabs/better-logging
Browse files Browse the repository at this point in the history
Update dependencies, improve trace logging
  • Loading branch information
guggero authored Jun 20, 2022
2 parents 6ff0d43 + bd58d1e commit 76bac18
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 64 deletions.
13 changes: 8 additions & 5 deletions account/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/lightninglabs/pool/poolscript"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
Expand Down Expand Up @@ -1345,7 +1346,8 @@ func (m *manager) CloseAccount(ctx context.Context, traderKey *btcec.PublicKey,
// script was not populated, we'll generate one from the backing lnd
// node's wallet.
if feeExpr, ok := feeExpr.(*OutputWithFee); ok && feeExpr.PkScript == nil {
addr, err := m.cfg.Wallet.NextAddr(ctx)
changeType := walletrpc.AddressType_WITNESS_PUBKEY_HASH
addr, err := m.cfg.Wallet.NextAddr(ctx, "", changeType, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1825,11 +1827,12 @@ coinSelection:
// A change output will only exist as long as the remaining amount is
// above the network's dust limit.
var changeOutput *wire.TxOut
dustLimit := lnwallet.DustLimitForSize(
input.P2WPKHSize,
)
dustLimit := lnwallet.DustLimitForSize(input.P2WPKHSize)
changeType := walletrpc.AddressType_WITNESS_PUBKEY_HASH
if changeAmt >= dustLimit {
addr, err := m.cfg.Wallet.NextAddr(context.Background())
addr, err := m.cfg.Wallet.NextAddr(
context.Background(), "", changeType, true,
)
if err != nil {
releaseInputs()
return nil, nil, nil, err
Expand Down
44 changes: 43 additions & 1 deletion account/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/lightninglabs/lndclient"
Expand All @@ -19,6 +21,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)
Expand Down Expand Up @@ -275,7 +278,9 @@ func (w *mockWallet) SendOutputs(ctx context.Context, outputs []*wire.TxOut,
return tx, nil
}

func (w *mockWallet) NextAddr(ctx context.Context) (btcutil.Address, error) {
func (w *mockWallet) NextAddr(context.Context, string,
walletrpc.AddressType, bool) (btcutil.Address, error) {

pubKeyHash := btcutil.Hash160(testTraderKey.SerializeCompressed())
return btcutil.NewAddressWitnessPubKeyHash(
pubKeyHash, &chaincfg.MainNetParams,
Expand Down Expand Up @@ -346,6 +351,43 @@ func (w *mockWallet) EstimateFeeToP2WSH(_ context.Context, _ btcutil.Amount,
return btcutil.Amount(chainfee.FeePerKwFloor), nil
}

func (w *mockWallet) FundPsbt(_ context.Context,
req *walletrpc.FundPsbtRequest) (*psbt.Packet, int32,
[]*walletrpc.UtxoLease, error) {

return nil, 0, nil, nil
}

func (w *mockWallet) SignPsbt(_ context.Context,
packet *psbt.Packet) (*psbt.Packet, error) {

for idx := range packet.Inputs {
packet.Inputs[idx].PartialSigs = []*psbt.PartialSig{{
Signature: []byte{
// A dummy signature must still have the sighash
// flag appended correctly.
33, 44, 55, 66, byte(txscript.SigHashAll),
},
}}
}

return packet, nil
}

func (w *mockWallet) FinalizePsbt(_ context.Context, packet *psbt.Packet,
account string) (*psbt.Packet, *wire.MsgTx, error) {

for idx := range packet.UnsignedTx.TxIn {
packet.UnsignedTx.TxIn[idx].Witness = [][]byte{{
// A dummy signature must still have the sighash flag
// appended correctly.
33, 44, 55, 66, byte(txscript.SigHashAll),
}}
}

return packet, packet.UnsignedTx, nil
}

type mockChainNotifier struct {
lndclient.ChainNotifierClient

Expand Down
4 changes: 3 additions & 1 deletion auctioneer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ func (c *Client) readIncomingStream() { // nolint:gocyclo

// Read next message from server.
msg, err := c.serverStream.Recv()
log.Tracef("Received msg=%#v, err=%v from server", msg, err)
log.Tracef("Received msg=%v, err=%v from server",
poolrpc.PrintMsg(msg), err)

switch {
// EOF is the "normal" close signal, meaning the server has
// cut its side of the connection. We will only get this during
Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module github.com/lightninglabs/pool
go 1.16

require (
github.com/btcsuite/btcd v0.22.0-beta.0.20220413172512-bf64c8bdbbbf
github.com/btcsuite/btcd v0.23.1
github.com/btcsuite/btcd/btcec/v2 v2.2.0
github.com/btcsuite/btcd/btcutil v1.1.1
github.com/btcsuite/btcd/btcutil/psbt v1.1.4
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet v0.15.1-0.20220512002839-af5562928b70
github.com/btcsuite/btcwallet v0.15.1
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0
github.com/btcsuite/btcwallet/wtxmgr v1.5.0
github.com/davecgh/go-spew v1.1.1
Expand All @@ -17,13 +18,13 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.1.18-beta
github.com/lightninglabs/lndclient v0.15.0-6
github.com/lightninglabs/lndclient v0.15.0-9
github.com/lightninglabs/pool/auctioneerrpc v1.0.7
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightningnetwork/lnd v0.15.0-beta.rc3
github.com/lightningnetwork/lnd v0.15.0-beta.rc6
github.com/lightningnetwork/lnd/cert v1.1.1
github.com/lightningnetwork/lnd/tlv v1.0.3
github.com/lightningnetwork/lnd/tor v1.0.0
github.com/lightningnetwork/lnd/tor v1.0.1
github.com/stretchr/testify v1.7.1
github.com/urfave/cli v1.22.4
go.etcd.io/bbolt v1.3.6
Expand Down
Loading

0 comments on commit 76bac18

Please sign in to comment.