From 61991a1c8923402864fe5d46aad620ec009973ee Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Thu, 9 Mar 2017 07:44:32 +0300 Subject: [PATCH] lnd: fix latest goclean.sh lint warning --- README.md | 2 +- channeldb/channel.go | 2 +- channeldb/db.go | 9 ++------- channeldb/graph.go | 4 ++-- cmd/lncli/commands.go | 18 +++++++++--------- cmd/lncli/main.go | 2 +- fundingmanager.go | 4 ++-- lnd_test.go | 16 ++++++++-------- lnwire/funding_locked.go | 17 ++++------------- lnwire/single_funding_open_proof.go | 0 lnwire/single_funding_request.go | 16 +++------------- lnwire/single_funding_response.go | 14 ++------------ routing/notifications.go | 4 ++-- routing/notifications_test.go | 2 +- routing/pathfind_test.go | 15 ++++----------- shachain/producer.go | 7 ++----- 16 files changed, 44 insertions(+), 88 deletions(-) delete mode 100644 lnwire/single_funding_open_proof.go diff --git a/README.md b/README.md index 71a6a4d1..cec2f16f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Godoc](https://godoc.org/github.com/lightningnetwork/lnd?status.svg)] (https://godoc.org/github.com/lightningnetwork/lnd)      -[![Coverage Status](https://coveralls.io/repos/github/AndrewSamokhvalov/lnd/badge.svg?branch=master)](https://coveralls.io/github/AndrewSamokhvalov/lnd?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/lightningnetwork/lnd/badge.svg?branch=master)](https://coveralls.io/github/lightningnetwork/lnd?branch=master) The Lightning Network Daemon (`lnd`) - is a complete implementation of a [Lightning Network](https://lightning.network) node and currently diff --git a/channeldb/channel.go b/channeldb/channel.go index d2eec4ca..cec92072 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -1453,7 +1453,7 @@ func putChanFundingInfo(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error return err } - byteOrder.PutUint16(scratch[:2], uint16(channel.NumConfsRequired)) + byteOrder.PutUint16(scratch[:2], channel.NumConfsRequired) if _, err := b.Write(scratch[:2]); err != nil { return err } diff --git a/channeldb/db.go b/channeldb/db.go index 21e3d057..909f227c 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -346,7 +346,7 @@ func fetchChannels(d *DB, pendingOnly bool) ([]*OpenChannel, error) { } if pendingOnly { for _, channel := range nodeChannels { - if channel.IsPending == true { + if channel.IsPending { channels = append(channels, channel) } } @@ -363,7 +363,7 @@ func fetchChannels(d *DB, pendingOnly bool) ([]*OpenChannel, error) { // MarkChannelAsOpen records the finalization of the funding process and marks // a channel as available for use. func (d *DB) MarkChannelAsOpen(outpoint *wire.OutPoint) error { - err := d.Update(func(tx *bolt.Tx) error { + return d.Update(func(tx *bolt.Tx) error { openChanBucket := tx.Bucket(openChannelBucket) if openChanBucket == nil { return ErrNoActiveChannels @@ -385,11 +385,6 @@ func (d *DB) MarkChannelAsOpen(outpoint *wire.OutPoint) error { byteOrder.PutUint16(scratch, uint16(0)) return openChanBucket.Put(keyPrefix, scratch) }) - if err != nil { - return err - } - - return nil } // syncVersions function is used for safe db version synchronization. It applies diff --git a/channeldb/graph.go b/channeldb/graph.go index ea90f52b..eefe64eb 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -751,8 +751,8 @@ func delChannelByEdge(edges *bolt.Bucket, edgeIndex *bolt.Bucket, // updated, otherwise it's the second node's information. The node ordering is // determined tby the lexicographical ordering of the identity public keys of // the nodes on either side of the channel. -func (r *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error { - return r.db.Update(func(tx *bolt.Tx) error { +func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error { + return c.db.Update(func(tx *bolt.Tx) error { edges, err := tx.CreateBucketIfNotExists(edgeBucket) if err != nil { return err diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 6730f05a..f33bea81 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -1096,7 +1096,7 @@ func normalizeFunc(edges []*lnrpc.ChannelEdge, scaleFactor float64) func(int64) y := math.Log2(float64(x)) // TODO(roasbeef): results in min being zero - return y - min/max - min*scaleFactor + return (y - min) / (max - min) * scaleFactor } } @@ -1259,21 +1259,21 @@ func getChanInfo(ctx *cli.Context) error { defer cleanUp() var ( - chan_id int64 - err error + chanID int64 + err error ) switch { case ctx.IsSet("chan_id"): - chan_id = ctx.Int64("chan_id") + chanID = ctx.Int64("chan_id") case ctx.Args().Present(): - chan_id, err = strconv.ParseInt(ctx.Args().First(), 10, 64) + chanID, err = strconv.ParseInt(ctx.Args().First(), 10, 64) default: return fmt.Errorf("chan_id argument missing") } req := &lnrpc.ChanInfoRequest{ - ChanId: uint64(chan_id), + ChanId: uint64(chanID), } chanInfo, err := client.GetChanInfo(ctxb, req) @@ -1491,11 +1491,11 @@ func decodePayReq(ctx *cli.Context) error { return nil } -var ListChainTxns = cli.Command{ +var listChainTxnsCommand = cli.Command{ Name: "listchaintxns", Usage: "List transactions from the wallet.", Description: "List all transactions an address of the wallet was involved in.", - Action: listChainTxns, + Action: listChainTxns, } func listChainTxns(ctx *cli.Context) error { @@ -1509,6 +1509,6 @@ func listChainTxns(ctx *cli.Context) error { return err } - printRespJson(resp) + printRespJSON(resp) return nil } diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index fdef04a5..6d6f64a3 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -77,7 +77,7 @@ func main() { getNetworkInfoCommand, debugLevelCommand, decodePayReqComamnd, - ListChainTxns, + listChainTxnsCommand, } if err := app.Run(os.Args); err != nil { diff --git a/fundingmanager.go b/fundingmanager.go index fe50c608..8dc30e37 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1097,13 +1097,13 @@ func newChanAnnouncement(localIdentity, remotePub *btcec.PublicKey, // network to recognize the legitimacy of the channel. The crafted // announcements are then send to the channel router to handle broadcasting to // the network during its next trickle. -func (f *fundingManager) announceChannel(idKey, remoteIdKey *btcec.PublicKey, +func (f *fundingManager) announceChannel(idKey, remoteIDKey *btcec.PublicKey, channel *lnwallet.LightningChannel, chanID lnwire.ChannelID, localProof, remoteProof *channelProof) { // TODO(roasbeef): need a Signer.SignMessage method to finalize // advertisements - chanAnnouncement := newChanAnnouncement(idKey, remoteIdKey, channel, chanID, + chanAnnouncement := newChanAnnouncement(idKey, remoteIDKey, channel, chanID, localProof, remoteProof) f.cfg.SendToRouter(chanAnnouncement.chanAnn) diff --git a/lnd_test.go b/lnd_test.go index b165719c..4e2d95ca 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -200,7 +200,7 @@ func closeChannelAndAssert(ctx context.Context, t *harnessTest, net *networkHarn // numChannelsPending sends an RPC request to a node to get a count of the // node's channels that are currently in a pending state (with a broadcast, // but not confirmed funding transaction). -func numChannelsPending(node *lightningNode, ctxt context.Context) (int, error) { +func numChannelsPending(ctxt context.Context, node *lightningNode) (int, error) { pendingChansRequest := &lnrpc.PendingChannelRequest{ Status: lnrpc.ChannelStatus_OPENING, } @@ -213,14 +213,14 @@ func numChannelsPending(node *lightningNode, ctxt context.Context) (int, error) // assertNumChannelsPending asserts that a pair of nodes have the expected // number of pending channels between them. -func assertNumChannelsPending(t *harnessTest, ctxt context.Context, +func assertNumChannelsPending(ctxt context.Context, t *harnessTest, alice, bob *lightningNode, expected int) { - aliceNumChans, err := numChannelsPending(alice, ctxt) + aliceNumChans, err := numChannelsPending(ctxt, alice) if err != nil { t.Fatalf("error fetching alice's node (%v) pending channels %v", alice.nodeID, err) } - bobNumChans, err := numChannelsPending(bob, ctxt) + bobNumChans, err := numChannelsPending(ctxt, bob) if err != nil { t.Fatalf("error fetching bob's node (%v) pending channels %v", bob.nodeID, err) @@ -313,7 +313,7 @@ func testChannelFundingPersistence(net *networkHarness, t *harnessTest) { // been broadcast, but not confirmed. Alice and Bob's nodes // should reflect this when queried via RPC. ctxt, _ = context.WithTimeout(ctxb, timeout) - assertNumChannelsPending(t, ctxt, net.Alice, net.Bob, 1) + assertNumChannelsPending(ctxt, t, net.Alice, net.Bob, 1) // Restart both nodes to test that the appropriate state has been // persisted and that both nodes recover gracefully. @@ -376,7 +376,7 @@ peersPoll: // Both nodes should still show a single channel as pending. time.Sleep(time.Millisecond * 300) ctxt, _ = context.WithTimeout(ctxb, timeout) - assertNumChannelsPending(t, ctxt, net.Alice, net.Bob, 1) + assertNumChannelsPending(ctxt, t, net.Alice, net.Bob, 1) // Finally, mine the last block which should mark the channel as open. if _, err := net.Miner.Node.Generate(1); err != nil { @@ -387,7 +387,7 @@ peersPoll: // be no pending channels remaining for either node. time.Sleep(time.Millisecond * 300) ctxt, _ = context.WithTimeout(ctxb, timeout) - assertNumChannelsPending(t, ctxt, net.Alice, net.Bob, 0) + assertNumChannelsPending(ctxt, t, net.Alice, net.Bob, 0) // The channel should be listed in the peer information returned by // both peers. @@ -1009,7 +1009,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) { } if len(chanGraph.Edges) != 2 { t.Fatalf("only two channels should be seen as active in the "+ - "network, instead %v are: ", len(chanGraph.Edges), + "network, instead %v are: %v", len(chanGraph.Edges), chanGraph.Edges) } for _, link := range chanGraph.Edges { diff --git a/lnwire/funding_locked.go b/lnwire/funding_locked.go index 32f06d18..da2c5fd3 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -49,15 +49,10 @@ var _ Message = (*FundingLocked)(nil) // // This is part of the lnwire.Message interface. func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &c.ChannelOutpoint, &c.ChannelID, &c.NextPerCommitmentPoint) - if err != nil { - return err - } - - return nil } // Encode serializes the target FundingLocked message into the passed io.Writer @@ -66,15 +61,10 @@ func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *FundingLocked) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelOutpoint, c.ChannelID, c.NextPerCommitmentPoint) - if err != nil { - return err - } - - return nil } // Command returns the uint32 code which uniquely identifies this message as a @@ -111,7 +101,8 @@ func (c *FundingLocked) MaxPayloadLength(uint32) uint32 { // This is part of the lnwire.Message interface. func (c *FundingLocked) Validate() error { if c.NextPerCommitmentPoint == nil { - return fmt.Errorf("The next per commitment point must be non-nil.") + return fmt.Errorf("the next per commitment point must be " + + "non-nil.") } // We're good! diff --git a/lnwire/single_funding_open_proof.go b/lnwire/single_funding_open_proof.go deleted file mode 100644 index e69de29b..00000000 diff --git a/lnwire/single_funding_request.go b/lnwire/single_funding_request.go index 5c9f62e8..fa0f8ec0 100644 --- a/lnwire/single_funding_request.go +++ b/lnwire/single_funding_request.go @@ -112,7 +112,7 @@ func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64, // // This is part of the lnwire.Message interface. func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &c.ChannelID, &c.ChannelType, &c.CoinType, @@ -125,11 +125,6 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error { &c.DeliveryPkScript, &c.DustLimit, &c.ConfirmationDepth) - if err != nil { - return err - } - - return nil } // Encode serializes the target SingleFundingRequest into the passed io.Writer @@ -138,7 +133,7 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelID, c.ChannelType, c.CoinType, @@ -151,11 +146,6 @@ func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error { c.DeliveryPkScript, c.DustLimit, c.ConfirmationDepth) - if err != nil { - return err - } - - return nil } // Command returns the uint32 code which uniquely identifies this message as a @@ -179,7 +169,7 @@ func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 { length += 8 // ChannelType - 1 byte - length += 1 + length++ // CoinType - 8 bytes length += 8 diff --git a/lnwire/single_funding_response.go b/lnwire/single_funding_response.go index cb18969d..6f56dc62 100644 --- a/lnwire/single_funding_response.go +++ b/lnwire/single_funding_response.go @@ -94,7 +94,7 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error { // DeliveryPkScript (final delivery) // DustLimit (8) // ConfirmationDepth (4) - err := readElements(r, + return readElements(r, &c.ChannelID, &c.ChannelDerivationPoint, &c.CommitmentKey, @@ -103,11 +103,6 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error { &c.DeliveryPkScript, &c.DustLimit, &c.ConfirmationDepth) - if err != nil { - return err - } - - return nil } // Encode serializes the target SingleFundingResponse into the passed io.Writer @@ -116,7 +111,7 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelID, c.ChannelDerivationPoint, c.CommitmentKey, @@ -125,11 +120,6 @@ func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error { c.DeliveryPkScript, c.DustLimit, c.ConfirmationDepth) - if err != nil { - return err - } - - return nil } // Command returns the uint32 code which uniquely identifies this message as a diff --git a/routing/notifications.go b/routing/notifications.go index 3177f5a5..31cce8e3 100644 --- a/routing/notifications.go +++ b/routing/notifications.go @@ -107,11 +107,11 @@ func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) { // In this case we'll try to send the notification // directly to the upstream client consumer. - case client.ntfnChan <- topologyDiff: + case c.ntfnChan <- topologyDiff: // If the client cancel's the notifications, then we'll // exit early. - case <-client.exit: + case <-c.exit: // Similarly, if the ChannelRouter itself exists early, // then we'll also exit ourselves. diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 94970d0d..405b348f 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -664,7 +664,7 @@ func TestChannelCloseNotification(t *testing.T) { Transactions: []*wire.MsgTx{ { TxIn: []*wire.TxIn{ - &wire.TxIn{ + { PreviousOutPoint: chanUtxo, }, }, diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 0e9b9f4b..8d949d91 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -4,11 +4,6 @@ import ( "encoding/hex" "encoding/json" "errors" - "github.com/lightningnetwork/lnd/channeldb" - "github.com/roasbeef/btcd/btcec" - "github.com/roasbeef/btcd/chaincfg/chainhash" - "github.com/roasbeef/btcd/wire" - "github.com/roasbeef/btcutil" "io/ioutil" "math/big" "net" @@ -17,13 +12,13 @@ import ( "testing" "time" - prand "math/rand" - "github.com/lightningnetwork/lnd/channeldb" "github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcutil" + + prand "math/rand" ) const ( @@ -344,8 +339,7 @@ func TestBasicGraphPathFinding(t *testing.T) { // The length of the path should be exactly one hop as it's the // "shortest" known path in the graph. if len(route.Hops) != 1 { - t.Fatalf("shortest path not selected, should be of length 1, "+ - "is instead: %v", len(route.Hops)) + t.Fatalf("shortest path not selected, should be of length 1, "+"is instead: %v", len(route.Hops)) } // As we have a direct path, the total time lock value should be @@ -388,8 +382,7 @@ func TestNewRoutePathTooLong(t *testing.T) { target = aliases["vincent"] route, err = findRoute(graph, target, paymentAmt) if err == nil { - t.Fatalf("should not have been able to find path, supposed to be "+ - "greater than 20 hops, found route with %v hops", len(route.Hops)) + t.Fatalf("should not have been able to find path, supposed to be "+"greater than 20 hops, found route with %v hops", len(route.Hops)) } } diff --git a/shachain/producer.go b/shachain/producer.go index c31f4d7b..87f5aff8 100644 --- a/shachain/producer.go +++ b/shachain/producer.go @@ -85,9 +85,6 @@ func (p *RevocationProducer) AtIndex(v uint64) (*chainhash.Hash, error) { // // NOTE: Part of the Producer interface. func (p *RevocationProducer) Encode(w io.Writer) error { - if _, err := w.Write(p.root.hash[:]); err != nil { - return err - } - - return nil + _, err := w.Write(p.root.hash[:]) + return err }