From 384fe61e731fb311f220ba1516260bc6b7ce64b1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 9 Feb 2017 15:28:32 -0800 Subject: [PATCH] multi: fix `go vet` warnings throughout code base --- breacharbiter.go | 2 +- chainntnfs/btcdnotify/btcd.go | 4 +++- chainntnfs/interface_test.go | 7 ++++++- lnwallet/interface_test.go | 26 ++++++++++++++++++-------- lnwallet/script_utils_test.go | 22 ++++++++++++++-------- lnwire/channel_announcement.go | 31 ------------------------------- lnwire/node_announcement.go | 17 ----------------- networktest.go | 4 +++- routing/router.go | 6 +++--- rpcserver.go | 10 +++------- server.go | 2 -- utxonursery_test.go | 2 +- 12 files changed, 52 insertions(+), 81 deletions(-) diff --git a/breacharbiter.go b/breacharbiter.go index 35c0029b..3906d27a 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -174,7 +174,7 @@ out: breachTXID := &breachInfo.commitHash confChan, err := b.notifier.RegisterConfirmationsNtfn(breachTXID, 1) if err != nil { - brarLog.Errorf("unable to register for conf for txid: ", + brarLog.Errorf("unable to register for conf for txid: %v", breachTXID) continue } diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index d1996f75..f16ce7ce 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -592,7 +592,9 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint) (*chainntnfs.S } } - return &chainntnfs.SpendEvent{ntfn.spendChan}, nil + return &chainntnfs.SpendEvent{ + Spend: ntfn.spendChan, + }, nil } // confirmationNotification represents a client's intent to receive a diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index 4bd9c909..07e4885e 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -40,7 +40,12 @@ func getTestTxId(miner *rpctest.Harness) (*chainhash.Hash, error) { return nil, err } - outputs := []*wire.TxOut{&wire.TxOut{2e8, script}} + outputs := []*wire.TxOut{ + &wire.TxOut{ + Value: 2e8, + PkScript: script, + }, + } return miner.SendOutputs(outputs, 10) } diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index a65045f1..6b8eb21a 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -94,8 +94,6 @@ func assertChannelOpen(t *testing.T, miner *rpctest.Harness, numConfs uint32, t.Fatalf("channel never opened") return nil } - - return nil } // bobNode represents the other party involved as a node within LN. Bob is our @@ -210,7 +208,10 @@ func newBobNode(miner *rpctest.Harness, amt btcutil.Amount) (*bobNode, error) { } // Give bobNode one 7 BTC output for use in creating channels. - output := &wire.TxOut{7e8, bobAddrScript} + output := &wire.TxOut{ + Value: 7e8, + PkScript: bobAddrScript, + } mainTxid, err := miner.SendOutputs([]*wire.TxOut{output}, 10) if err != nil { return nil, err @@ -284,7 +285,10 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet, numOut addrs = append(addrs, walletAddr) - output := &wire.TxOut{satoshiPerOutput, script} + output := &wire.TxOut{ + Value: satoshiPerOutput, + PkScript: script, + } if _, err := miner.SendOutputs([]*wire.TxOut{output}, 10); err != nil { return err } @@ -949,7 +953,10 @@ func testListTransactionDetails(miner *rpctest.Harness, wallet *lnwallet.Lightni t.Fatalf("unable to create output script: %v", err) } - output := &wire.TxOut{outputAmt, script} + output := &wire.TxOut{ + Value: outputAmt, + PkScript: script, + } txid, err := miner.SendOutputs([]*wire.TxOut{output}, 10) if err != nil { t.Fatalf("unable to send coinbase: %v", err) @@ -1044,7 +1051,7 @@ func testListTransactionDetails(miner *rpctest.Harness, wallet *lnwallet.Lightni } } if !burnTxFound { - t.Fatalf("tx burning btc not found") + t.Fatal("tx burning btc not found") } } @@ -1056,7 +1063,7 @@ func testTransactionSubscriptions(miner *rpctest.Harness, w *lnwallet.LightningW // implementation of the WalletController. txClient, err := w.SubscribeTransactions() if err != nil { - t.Fatalf("unable to generate tx subscription: %v") + t.Fatalf("unable to generate tx subscription: %v", err) } defer txClient.Cancel() @@ -1097,7 +1104,10 @@ func testTransactionSubscriptions(miner *rpctest.Harness, w *lnwallet.LightningW t.Fatalf("unable to create output script: %v", err) } - output := &wire.TxOut{outputAmt, script} + output := &wire.TxOut{ + Value: outputAmt, + PkScript: script, + } if _, err := miner.SendOutputs([]*wire.TxOut{output}, 10); err != nil { t.Fatalf("unable to send coinbase: %v", err) } diff --git a/lnwallet/script_utils_test.go b/lnwallet/script_utils_test.go index 2d3ce567..fb0ec41f 100644 --- a/lnwallet/script_utils_test.go +++ b/lnwallet/script_utils_test.go @@ -65,10 +65,16 @@ func TestCommitmentSpendValidation(t *testing.T) { // transaction which sweeps the funds to a random address. targetOutput, err := commitScriptUnencumbered(aliceKeyPub) if err != nil { - t.Fatalf("unable to create target output: %v") + t.Fatalf("unable to create target output: %v", err) } sweepTx := wire.NewMsgTx(2) - sweepTx.AddTxIn(wire.NewTxIn(&wire.OutPoint{commitmentTx.TxHash(), 0}, nil, nil)) + sweepTx.AddTxIn(wire.NewTxIn(&wire.OutPoint{ + Hash: commitmentTx.TxHash(), + Index: 0, + }, + nil, + nil), + ) sweepTx.AddTxOut(&wire.TxOut{ PkScript: targetOutput, Value: 0.5 * 10e8, @@ -77,7 +83,7 @@ func TestCommitmentSpendValidation(t *testing.T) { // First, we'll test spending with Alice's key after the timeout. delayScript, err := commitScriptToSelf(csvTimeout, aliceKeyPub, revokePubKey) if err != nil { - t.Fatalf("unable to generate alice delay script: %v") + t.Fatalf("unable to generate alice delay script: %v", err) } sweepTx.TxIn[0].Sequence = lockTimeToSequence(false, csvTimeout) signDesc := &SignDescriptor{ @@ -92,7 +98,7 @@ func TestCommitmentSpendValidation(t *testing.T) { aliceWitnessSpend, err := CommitSpendTimeout(aliceSelfOutputSigner, signDesc, sweepTx) if err != nil { - t.Fatalf("unable to generate delay commit spend witness :%v") + t.Fatalf("unable to generate delay commit spend witness: %v", err) } sweepTx.TxIn[0].Witness = aliceWitnessSpend vm, err := txscript.NewEngine(delayOutput.PkScript, @@ -378,8 +384,8 @@ func TestHTLCSenderSpendValidation(t *testing.T) { t.Fatalf("spend test case #%v succeed, spend should be invalid: %v", i, err) } - debugBuf.WriteString(fmt.Sprintf("Stack: ", vm.GetStack())) - debugBuf.WriteString(fmt.Sprintf("AltStack: ", vm.GetAltStack())) + debugBuf.WriteString(fmt.Sprintf("Stack: %v", vm.GetStack())) + debugBuf.WriteString(fmt.Sprintf("AltStack: %v", vm.GetAltStack())) } } } @@ -551,8 +557,8 @@ func TestHTLCReceiverSpendValidation(t *testing.T) { t.Fatalf("spend test case #%v succeed, spend should be invalid: %v", i, err) } - debugBuf.WriteString(fmt.Sprintf("Stack: ", vm.GetStack())) - debugBuf.WriteString(fmt.Sprintf("AltStack: ", vm.GetAltStack())) + debugBuf.WriteString(fmt.Sprintf("Stack: %v", vm.GetStack())) + debugBuf.WriteString(fmt.Sprintf("AltStack: %v", vm.GetAltStack())) } } } diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go index 238c49d6..2439b902 100644 --- a/lnwire/channel_announcement.go +++ b/lnwire/channel_announcement.go @@ -4,9 +4,7 @@ import ( "bytes" "io" - "github.com/go-errors/errors" "github.com/roasbeef/btcd/btcec" - "github.com/roasbeef/btcd/chaincfg/chainhash" ) // ChannelAnnouncement message is used to announce the existence of a channel @@ -50,35 +48,6 @@ var _ Message = (*ChannelAnnouncement)(nil) // // This is part of the lnwire.Message interface. func (a *ChannelAnnouncement) Validate() error { - // TODO(roasbeef): move validation to discovery service - return nil - - var sigHash []byte - - sigHash = chainhash.DoubleHashB(a.FirstNodeID.SerializeCompressed()) - if !a.FirstBitcoinSig.Verify(sigHash, a.FirstBitcoinKey) { - return errors.New("can't verify first bitcoin signature") - } - - sigHash = chainhash.DoubleHashB(a.SecondNodeID.SerializeCompressed()) - if !a.SecondBitcoinSig.Verify(sigHash, a.SecondBitcoinKey) { - return errors.New("can't verify second bitcoin signature") - } - - data, err := a.DataToSign() - if err != nil { - return err - } - dataHash := chainhash.DoubleHashB(data) - - if !a.FirstNodeSig.Verify(dataHash, a.FirstNodeID) { - return errors.New("can't verify data in first node signature") - } - - if !a.SecondNodeSig.Verify(dataHash, a.SecondNodeID) { - return errors.New("can't verify data in second node signature") - } - return nil } diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index fca467f6..5ea1e4be 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -7,7 +7,6 @@ import ( "github.com/go-errors/errors" "github.com/roasbeef/btcd/btcec" - "github.com/roasbeef/btcd/chaincfg/chainhash" ) var ( @@ -108,22 +107,6 @@ var _ Message = (*NodeAnnouncement)(nil) func (a *NodeAnnouncement) Validate() error { // TODO(roasbeef): move validation to discovery service return nil - - if err := a.Alias.Validate(); err != nil { - return err - } - - data, err := a.DataToSign() - if err != nil { - return err - } - - dataHash := chainhash.DoubleHashB(data) - if !a.Signature.Verify(dataHash, a.NodeID) { - return errors.New("can't check the node annoucement signature") - } - - return nil } // Decode deserializes a serialized NodeAnnouncement stored in the diff --git a/networktest.go b/networktest.go index e3faee5a..d831dc07 100644 --- a/networktest.go +++ b/networktest.go @@ -422,7 +422,9 @@ func (n *networkHarness) SetUp() error { // Load up the wallets of the seeder nodes with 10 outputs of 1 BTC // each. ctxb := context.Background() - addrReq := &lnrpc.NewAddressRequest{lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH} + addrReq := &lnrpc.NewAddressRequest{ + Type: lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH, + } clients := []lnrpc.LightningClient{n.Alice, n.Bob} for _, client := range clients { for i := 0; i < 10; i++ { diff --git a/routing/router.go b/routing/router.go index e3ef22db..1775d08e 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1029,9 +1029,9 @@ func generateSphinxPacket(route *Route, paymentHash []byte) ([]byte, error) { // mutating the curve parameters, which are unset in a higher // level in order to avoid spamming the logs. pub := btcec.PublicKey{ - btcec.S256(), - hop.Channel.Node.PubKey.X, - hop.Channel.Node.PubKey.Y, + Curve: btcec.S256(), + X: hop.Channel.Node.PubKey.X, + Y: hop.Channel.Node.PubKey.Y, } nodes[i] = &pub } diff --git a/rpcserver.go b/rpcserver.go index 26c78c91..23aa2ba7 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -705,7 +705,9 @@ func (r *rpcServer) WalletBalance(ctx context.Context, rpcsLog.Debugf("[walletbalance] balance=%v", balance) - return &lnrpc.WalletBalanceResponse{balance.ToBTC()}, nil + return &lnrpc.WalletBalanceResponse{ + Balance: balance.ToBTC(), + }, nil } // ChannelBalance returns the total available channel flow across all open @@ -969,8 +971,6 @@ func (r *rpcServer) SendPayment(paymentStream lnrpc.Lightning_SendPaymentServer) }() } } - - return nil } // SendPaymentSync is the synchronous non-streaming version of SendPayment. @@ -1242,8 +1242,6 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription, return nil } } - - return nil } // SubscribeTransactions creates a uni-directional stream (server -> client) in @@ -1286,8 +1284,6 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest, return nil } } - - return nil } // GetTransactions returns a list of describing all the known transactions diff --git a/server.go b/server.go index d49daa5b..bfbbea4f 100644 --- a/server.go +++ b/server.go @@ -385,8 +385,6 @@ func (s *server) sendToPeer(target *btcec.PublicKey, msgs ...lnwire.Message) err case <-s.quit: return errors.New("server shutting down") } - - return nil } // peerConnected is a function that handles initialization a newly connected diff --git a/utxonursery_test.go b/utxonursery_test.go index d49e0602..8733131c 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -208,7 +208,7 @@ func TestAddSerializedKidsToList(t *testing.T) { kidList, err := deserializeKidList(&b) if err != nil { - t.Fatalf("unable to deserialize kid output list: ", err) + t.Fatalf("unable to deserialize kid output list: %v", err) } for i := 0; i < 3; i++ {