From 4a0a15586b28f5e82bf4977fe77855558a152b7d Mon Sep 17 00:00:00 2001 From: positiveblue Date: Sat, 11 Mar 2023 23:01:34 -0800 Subject: [PATCH] multi: make linter happy Fix all the linter problems for the `v0.16.0-beta.rc3`. --- config_builder.go | 4 +++- lnutils/chan.go | 2 +- lnwallet/mock.go | 37 ++++++++++++++++++++++++---------- lnwallet/rebroadcaster_test.go | 17 +++++++++------- lnwallet/wallet.go | 3 ++- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/config_builder.go b/config_builder.go index 08b134270e..3ad6f99d69 100644 --- a/config_builder.go +++ b/config_builder.go @@ -652,7 +652,9 @@ type walletReBroadcaster struct { } // newWalletReBroadcaster creates a new instance of the walletReBroadcaster. -func newWalletReBroadcaster(broadcaster *pushtx.Broadcaster) *walletReBroadcaster { +func newWalletReBroadcaster( + broadcaster *pushtx.Broadcaster) *walletReBroadcaster { + return &walletReBroadcaster{ Broadcaster: broadcaster, } diff --git a/lnutils/chan.go b/lnutils/chan.go index b85c0de961..44ff6c3fbf 100644 --- a/lnutils/chan.go +++ b/lnutils/chan.go @@ -6,7 +6,7 @@ import ( ) // RecvOrTimeout attempts to recv over chan c, returning the value. If the -// timeout passes before the recv succeeds, an error is returned +// timeout passes before the recv succeeds, an error is returned. func RecvOrTimeout[T any](c <-chan T, timeout time.Duration) (*T, error) { select { case m := <-c: diff --git a/lnwallet/mock.go b/lnwallet/mock.go index 9fd9891c7e..4012103cf3 100644 --- a/lnwallet/mock.go +++ b/lnwallet/mock.go @@ -21,7 +21,9 @@ import ( ) var ( - CoinPkScript, _ = hex.DecodeString("001431df1bde03c074d0cf21ea2529427e1499b8f1de") + CoinPkScript, _ = hex.DecodeString( + "001431df1bde03c074d0cf21ea2529427e1499b8f1de", + ) ) // mockWalletController is a mock implementation of the WalletController @@ -50,6 +52,7 @@ func (w *mockWalletController) FetchInputInfo( Confirmations: 1, OutPoint: *prevOut, } + return utxo, nil } @@ -74,8 +77,10 @@ func (w *mockWalletController) NewAddress(AddressType, bool, string) (btcutil.Address, error) { addr, _ := btcutil.NewAddressPubKey( - w.RootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams, + w.RootKey.PubKey().SerializeCompressed(), + &chaincfg.MainNetParams, ) + return addr, nil } @@ -176,6 +181,7 @@ func (w *mockWalletController) ListUnspentWitness(int32, int32, atomic.AddUint32(&w.index, 1) var ret []*Utxo ret = append(ret, utxo) + return ret, nil } @@ -200,19 +206,21 @@ func (w *mockWalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint, } // ReleaseOutput currently does nothing. -func (w *mockWalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error { +func (w *mockWalletController) ReleaseOutput(wtxmgr.LockID, + wire.OutPoint) error { + return nil } -func (w *mockWalletController) ListLeasedOutputs() ([]*base.ListLeasedOutputResult, +func (w *mockWalletController) ListLeasedOutputs() ([]*base.ListLeasedOutputResult, //nolint:lll error) { return nil, nil } // FundPsbt currently does nothing. -func (w *mockWalletController) FundPsbt(*psbt.Packet, int32, chainfee.SatPerKWeight, - string, *waddrmgr.KeyScope) (int32, error) { +func (w *mockWalletController) FundPsbt(*psbt.Packet, int32, + chainfee.SatPerKWeight, string, *waddrmgr.KeyScope) (int32, error) { return 0, nil } @@ -228,7 +236,9 @@ func (w *mockWalletController) FinalizePsbt(_ *psbt.Packet, _ string) error { } // PublishTransaction sends a transaction to the PublishedTransactions chan. -func (w *mockWalletController) PublishTransaction(tx *wire.MsgTx, _ string) error { +func (w *mockWalletController) PublishTransaction(tx *wire.MsgTx, + _ string) error { + w.PublishedTransactions <- tx return nil } @@ -286,7 +296,8 @@ type mockChainNotifier struct { // that the tx confirmation will go over. func (c *mockChainNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, pkScript []byte, numConfs, heightHint uint32, - opts ...chainntnfs.NotifierOption) (*chainntnfs.ConfirmationEvent, error) { + opts ...chainntnfs.NotifierOption) (*chainntnfs.ConfirmationEvent, + error) { return &chainntnfs.ConfirmationEvent{ Confirmed: c.ConfChan, @@ -307,8 +318,9 @@ func (c *mockChainNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, // RegisterBlockEpochNtfn returns a BlockEpochEvent that contains a channel that // block epochs will go over. -func (c *mockChainNotifier) RegisterBlockEpochNtfn(blockEpoch *chainntnfs.BlockEpoch) ( - *chainntnfs.BlockEpochEvent, error) { +func (c *mockChainNotifier) RegisterBlockEpochNtfn( + blockEpoch *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, + error) { return &chainntnfs.BlockEpochEvent{ Epochs: c.EpochChan, @@ -339,6 +351,7 @@ func (*mockChainIO) GetBestBlock() (*chainhash.Hash, int32, error) { func (*mockChainIO) GetUtxo(op *wire.OutPoint, _ []byte, heightHint uint32, _ <-chan struct{}) (*wire.TxOut, error) { + return nil, nil } @@ -346,6 +359,8 @@ func (*mockChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) { return nil, nil } -func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) { +func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, + error) { + return nil, nil } diff --git a/lnwallet/rebroadcaster_test.go b/lnwallet/rebroadcaster_test.go index 599d7d64ef..c0467090b9 100644 --- a/lnwallet/rebroadcaster_test.go +++ b/lnwallet/rebroadcaster_test.go @@ -7,7 +7,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/lnutils" "github.com/stretchr/testify/require" @@ -132,7 +131,7 @@ func TestWalletRebroadcaster(t *testing.T) { ChainIO: chainIO, } - t.Run("rebroadcast bypass", func(t *testing.T) { + t.Run("rebroadcast bypass", func(t *testing.T) { //nolint:paralleltest // We'll make a copy of the config, but without the // broadcaster. testCfg := *cfg @@ -148,7 +147,8 @@ func TestWalletRebroadcaster(t *testing.T) { t, wallet, rebroadcaster, walletController, ) - wallet.Shutdown() + err = wallet.Shutdown() + require.NoError(t, err) // If we make a new wallet, that has the broadcaster, but // hasn't started yet, we should see the same behavior. @@ -162,15 +162,19 @@ func TestWalletRebroadcaster(t *testing.T) { t, wallet, rebroadcaster, walletController, ) - wallet.Shutdown() + err = wallet.Shutdown() + require.NoError(t, err) }) - t.Run("rebroadcast normal", func(t *testing.T) { + t.Run("rebroadcast normal", func(t *testing.T) { //nolint:paralleltest wallet, err := NewLightningWallet(*cfg) require.NoError(t, err) require.NoError(t, wallet.Startup()) - defer wallet.Shutdown() + defer func() { + err = wallet.Shutdown() + require.NoError(t, err) + }() // Wait for the broadcaster to start. _, err = lnutils.RecvOrTimeout( @@ -192,6 +196,5 @@ func TestWalletRebroadcaster(t *testing.T) { rebroadcaster.confSignal, time.Second, ) require.NoError(t, err) - }) } diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 091affa349..fec421cc02 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -482,7 +482,8 @@ func (l *LightningWallet) PublishTransaction(tx *wire.MsgTx, const numConfs = 6 txConf, err := l.Cfg.Notifier.RegisterConfirmationsNtfn( - &txHash, tx.TxOut[0].PkScript, numConfs, uint32(bestHeight), + &txHash, tx.TxOut[0].PkScript, numConfs, + uint32(bestHeight), ) if err != nil { return