From 8fb54782e204af766326f61b1db7fa6442025402 Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Thu, 23 Feb 2017 21:59:50 +0300 Subject: [PATCH] lnd: fix gosimple warnings --- brontide/noise.go | 21 +++++---------- channeldb/channel.go | 38 ++++++--------------------- channeldb/db.go | 6 +---- channeldb/meta.go | 5 +--- channeldb/nodes.go | 6 +---- channeldb/payments.go | 6 +---- invoiceregistry.go | 6 +---- lnwallet/btcwallet/btcwallet.go | 6 +---- lnwallet/interface_test.go | 19 ++++++-------- lnwire/channel_announcement.go | 14 ++-------- lnwire/channel_update_announcement.go | 14 ++-------- lnwire/close_complete.go | 14 ++-------- lnwire/close_request.go | 14 ++-------- lnwire/commit_sig.go | 13 ++------- lnwire/error_generic.go | 14 ++-------- lnwire/features.go | 7 ++--- lnwire/init_message.go | 16 +++-------- lnwire/message.go | 6 +---- lnwire/node_announcement.go | 14 ++-------- lnwire/ping.go | 14 ++-------- lnwire/pong.go | 14 ++-------- lnwire/revoke_and_ack.go | 14 ++-------- lnwire/single_funding_complete.go | 14 ++-------- lnwire/single_funding_open_proof.go | 0 lnwire/single_funding_signcomplete.go | 14 ++-------- lnwire/update_add_htlc.go | 14 ++-------- lnwire/update_fail_htlc.go | 14 ++-------- lnwire/update_fulfill_htlc.go | 14 ++-------- networktest.go | 7 ++--- utxonursery.go | 34 +++++------------------- 30 files changed, 73 insertions(+), 319 deletions(-) create mode 100644 lnwire/single_funding_open_proof.go diff --git a/brontide/noise.go b/brontide/noise.go index 0198608d..b38f269c 100644 --- a/brontide/noise.go +++ b/brontide/noise.go @@ -443,11 +443,8 @@ func (b *BrontideMachine) RecvActOne(actOne [ActOneSize]byte) error { // If the initiator doesn't know our static key, then this operation // will fail. - if _, err := b.DecryptAndHash(p[:]); err != nil { - return err - } - - return nil + _, err = b.DecryptAndHash(p[:]) + return err } // GenActTwo generates the second packet (act two) to be sent from the @@ -515,11 +512,8 @@ func (b *BrontideMachine) RecvActTwo(actTwo [ActTwoSize]byte) error { s := ecdh(b.remoteEphemeral, b.localEphemeral) b.mixKey(s) - if _, err := b.DecryptAndHash(p[:]); err != nil { - return err - } - - return nil + _, err = b.DecryptAndHash(p[:]) + return err } // GenActThree creates the final (act three) packet of the handshake. Act three @@ -662,11 +656,8 @@ func (b *BrontideMachine) WriteMessage(w io.Writer, p []byte) error { // single packet, as any fragmentation should have taken place at a // higher level. cipherText := b.sendCipher.Encrypt(nil, nil, p) - if _, err := w.Write(cipherText); err != nil { - return err - } - - return nil + _, err := w.Write(cipherText) + return err } // ReadMessage attempts to read the next message from the passed io.Reader. In diff --git a/channeldb/channel.go b/channeldb/channel.go index 5c8575b6..7a5579fc 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -1269,11 +1269,7 @@ func fetchChannelIDs(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { idBytes := nodeChanBucket.Get(idKey) channel.IdentityPub, err = btcec.ParsePubKey(idBytes, btcec.S256()) - if err != nil { - return err - } - - return nil + return err } func putChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { @@ -1329,11 +1325,7 @@ func fetchChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel) erro } channel.OurCommitKey, err = btcec.ParsePubKey(keyBytes[33:], btcec.S256()) - if err != nil { - return err - } - - return nil + return err } func putChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { @@ -1631,11 +1623,7 @@ func fetchChanPreimageState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) e } _, err = io.ReadFull(reader, channel.StateHintObsfucator[:]) - if err != nil { - return err - } - - return nil + return err } func putChanDeliveryScripts(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { @@ -1683,11 +1671,7 @@ func fetchChanDeliveryScripts(nodeChanBucket *bolt.Bucket, channel *OpenChannel) } channel.TheirDeliveryScript, err = wire.ReadVarBytes(deliveryBytes, 0, 520, "") - if err != nil { - return err - } - - return nil + return err } // htlcDiskSize represents the number of btyes a serialized HTLC takes up on @@ -1717,11 +1701,8 @@ func serializeHTLC(w io.Writer, h *HTLC) error { byteOrder.PutUint16(buf[n:], h.OutputIndex) n += 2 - if _, err := w.Write(buf[:]); err != nil { - return err - } - - return nil + _, err := w.Write(buf[:]) + return err } func deserializeHTLC(r io.Reader) (*HTLC, error) { @@ -1980,11 +1961,8 @@ func writeOutpoint(w io.Writer, o *wire.OutPoint) error { } byteOrder.PutUint32(scratch, o.Index) - if _, err := w.Write(scratch); err != nil { - return err - } - - return nil + _, err := w.Write(scratch) + return err } func readOutpoint(r io.Reader, o *wire.OutPoint) error { diff --git a/channeldb/db.go b/channeldb/db.go index 2682a2c6..f5335f68 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -437,11 +437,7 @@ func (d *DB) syncVersions(versions []version) error { } meta.DbVersionNumber = latestVersion - if err := putMeta(meta, tx); err != nil { - return err - } - - return nil + return putMeta(meta, tx) }) } diff --git a/channeldb/meta.go b/channeldb/meta.go index f0fd25eb..cb9feac6 100644 --- a/channeldb/meta.go +++ b/channeldb/meta.go @@ -76,8 +76,5 @@ func putMeta(meta *Meta, tx *bolt.Tx) error { func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error { scratch := make([]byte, 4) byteOrder.PutUint32(scratch, meta.DbVersionNumber) - if err := metaBucket.Put(dbVersionKey, scratch); err != nil { - return err - } - return nil + return metaBucket.Put(dbVersionKey, scratch) } diff --git a/channeldb/nodes.go b/channeldb/nodes.go index c92c004d..e1bafb14 100644 --- a/channeldb/nodes.go +++ b/channeldb/nodes.go @@ -158,11 +158,7 @@ func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) { // returned to the caller. nodeReader := bytes.NewReader(nodeBytes) node, err = deserializeLinkNode(nodeReader) - if err != nil { - return err - } - - return nil + return err }) if err != nil { return nil, err diff --git a/channeldb/payments.go b/channeldb/payments.go index 774eea57..f679050c 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -127,11 +127,7 @@ func (db *DB) DeleteAllPayments() error { } _, err = tx.CreateBucket(paymentBucket) - if err != nil { - return err - } - - return nil + return err }) } diff --git a/invoiceregistry.go b/invoiceregistry.go index ed99dc0f..e8cd263a 100644 --- a/invoiceregistry.go +++ b/invoiceregistry.go @@ -88,14 +88,10 @@ func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) error { })) // TODO(roasbeef): also check in memory for quick lookups/settles? - if err := i.cdb.AddInvoice(invoice); err != nil { - return err - } + return i.cdb.AddInvoice(invoice) // TODO(roasbeef): re-enable? //go i.notifyClients(invoice, false) - - return nil } // lookupInvoice looks up an invoice by its payment hash (R-Hash), if found diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 119f2efa..1942bba5 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -281,11 +281,7 @@ func (b *BtcWallet) FetchRootKey() (*btcec.PrivateKey, error) { rootBucket := tx.RootBucket() rootAddrHash = rootAddr[0].Address().ScriptAddress() - if err := rootBucket.Put(rootKey, rootAddrHash); err != nil { - return err - } - - return nil + return rootBucket.Put(rootKey, rootAddrHash) }); err != nil { return nil, err } diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 707108e8..22eab3f3 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -311,17 +311,14 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet, numOut // Wait until the wallet has finished syncing up to the main chain. ticker := time.NewTicker(100 * time.Millisecond) expectedBalance := btcutil.Amount(satoshiPerOutput * int64(numOutputs)) -out: - for { - select { - case <-ticker.C: - balance, err := w.ConfirmedBalance(1, false) - if err != nil { - return err - } - if balance == expectedBalance { - break out - } + + for range ticker.C { + balance, err := w.ConfirmedBalance(1, false) + if err != nil { + return err + } + if balance == expectedBalance { + break } } ticker.Stop() diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go index 2439b902..2fb2b067 100644 --- a/lnwire/channel_announcement.go +++ b/lnwire/channel_announcement.go @@ -56,7 +56,7 @@ func (a *ChannelAnnouncement) Validate() error { // // This is part of the lnwire.Message interface. func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &c.FirstNodeSig, &c.SecondNodeSig, &c.ChannelID, @@ -67,11 +67,6 @@ func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error { &c.FirstBitcoinKey, &c.SecondBitcoinKey, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target ChannelAnnouncement into the passed io.Writer @@ -79,7 +74,7 @@ func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.FirstNodeSig, c.SecondNodeSig, c.ChannelID, @@ -90,11 +85,6 @@ func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error { c.FirstBitcoinKey, c.SecondBitcoinKey, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/channel_update_announcement.go b/lnwire/channel_update_announcement.go index b37453f2..e3f73f69 100644 --- a/lnwire/channel_update_announcement.go +++ b/lnwire/channel_update_announcement.go @@ -72,7 +72,7 @@ func (a *ChannelUpdateAnnouncement) Validate() error { // // This is part of the lnwire.Message interface. func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &c.Signature, &c.ChannelID, &c.Timestamp, @@ -82,11 +82,6 @@ func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error { &c.FeeBaseMsat, &c.FeeProportionalMillionths, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target ChannelUpdateAnnouncement into the passed @@ -94,7 +89,7 @@ func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.Signature, c.ChannelID, c.Timestamp, @@ -104,11 +99,6 @@ func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error { c.FeeBaseMsat, c.FeeProportionalMillionths, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/close_complete.go b/lnwire/close_complete.go index 2c2fa830..94622be7 100644 --- a/lnwire/close_complete.go +++ b/lnwire/close_complete.go @@ -43,14 +43,9 @@ var _ Message = (*CloseComplete)(nil) func (c *CloseComplete) Decode(r io.Reader, pver uint32) error { // ChannelPoint (8) // ResponderCloseSig (73) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.ResponderCloseSig) - if err != nil { - return err - } - - return nil } // Encode serializes the target CloseComplete into the passed io.Writer observing @@ -60,14 +55,9 @@ func (c *CloseComplete) Decode(r io.Reader, pver uint32) error { func (c *CloseComplete) Encode(w io.Writer, pver uint32) error { // ChannelPoint (8) // ResponderCloseSig (73) - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.ResponderCloseSig) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/close_request.go b/lnwire/close_request.go index f26ee19c..674edddf 100644 --- a/lnwire/close_request.go +++ b/lnwire/close_request.go @@ -57,15 +57,10 @@ func (c *CloseRequest) Decode(r io.Reader, pver uint32) error { // RequesterCloseSig (73) // First byte length then sig // Fee (8) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.RequesterCloseSig, &c.Fee) - if err != nil { - return err - } - - return nil } // Encode serializes the target CloseRequest into the passed io.Writer observing @@ -76,15 +71,10 @@ func (c *CloseRequest) Encode(w io.Writer, pver uint32) error { // ChannelID // RequesterCloseSig // Fee - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.RequesterCloseSig, c.Fee) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/commit_sig.go b/lnwire/commit_sig.go index ba0e141d..f51d35e3 100644 --- a/lnwire/commit_sig.go +++ b/lnwire/commit_sig.go @@ -46,15 +46,10 @@ var _ Message = (*CommitSig)(nil) func (c *CommitSig) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) // RequesterCommitSig(73max+2) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.CommitSig, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target CommitSig into the passed io.Writer @@ -62,14 +57,10 @@ func (c *CommitSig) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *CommitSig) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.CommitSig, ) - if err != nil { - return err - } - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/error_generic.go b/lnwire/error_generic.go index d794b106..4476f9f4 100644 --- a/lnwire/error_generic.go +++ b/lnwire/error_generic.go @@ -73,17 +73,12 @@ var _ Message = (*ErrorGeneric)(nil) func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) // Problem - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.Code, &c.Problem, &c.PendingChannelID, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target ErrorGeneric into the passed io.Writer @@ -91,17 +86,12 @@ func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.Code, c.Problem, c.PendingChannelID, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying an ErrorGeneric message on diff --git a/lnwire/features.go b/lnwire/features.go index 1edaac19..3f80359c 100644 --- a/lnwire/features.go +++ b/lnwire/features.go @@ -197,11 +197,8 @@ func (f *FeatureVector) Encode(w io.Writer) error { setFlag(data, position, flag) } - if _, err := w.Write(data); err != nil { - return err - } - - return nil + _, err := w.Write(data) + return err } // Compare checks that features are compatible and returns the features which diff --git a/lnwire/init_message.go b/lnwire/init_message.go index bdb34874..b9deddd9 100644 --- a/lnwire/init_message.go +++ b/lnwire/init_message.go @@ -1,8 +1,8 @@ package lnwire import ( - "io" "github.com/go-errors/errors" + "io" ) // Init is the first message reveals the features supported or required by this @@ -34,15 +34,10 @@ func NewInitMessage(gf, lf *FeatureVector) *Init { func (msg *Init) Decode(r io.Reader, pver uint32) error { // LocalFeatures(~) // GlobalFeatures(~) - err := readElements(r, + return readElements(r, &msg.LocalFeatures, &msg.GlobalFeatures, ) - if err != nil { - return err - } - - return nil } // A compile time check to ensure Init implements the lnwire.Message @@ -54,15 +49,10 @@ var _ Message = (*Init)(nil) // // This is part of the lnwire.Message interface. func (msg *Init) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, msg.LocalFeatures, msg.GlobalFeatures, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/message.go b/lnwire/message.go index 5e05722b..d89f31db 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -244,11 +244,7 @@ func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet) // Write payload the payload itself after the header. n, err = w.Write(payload) totalBytes += n - if err != nil { - return totalBytes, err - } - - return totalBytes, nil + return totalBytes, err } // ReadMessageN reads, validates, and parses the next bitcoin Message from r for diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index 3b3393c8..4af8b89d 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -128,7 +128,7 @@ func (a *NodeAnnouncement) Validate() error { // // This is part of the lnwire.Message interface. func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &c.Signature, &c.Timestamp, &c.Address, @@ -137,11 +137,6 @@ func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error { &c.pad, &c.Alias, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target NodeAnnouncement into the passed io.Writer @@ -149,7 +144,7 @@ func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.Signature, c.Timestamp, c.Address, @@ -158,11 +153,6 @@ func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error { c.pad, c.Alias, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/ping.go b/lnwire/ping.go index a8b03a6e..fd75d32e 100644 --- a/lnwire/ping.go +++ b/lnwire/ping.go @@ -27,14 +27,9 @@ var _ Message = (*Pong)(nil) // // This is part of the lnwire.Message interface. func (p *Pong) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &p.Nonce, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target Pong into the passed io.Writer observing the @@ -42,14 +37,9 @@ func (p *Pong) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (p *Pong) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, p.Nonce, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/pong.go b/lnwire/pong.go index acfb89e9..2cf2be9b 100644 --- a/lnwire/pong.go +++ b/lnwire/pong.go @@ -26,14 +26,9 @@ var _ Message = (*Ping)(nil) // // This is part of the lnwire.Message interface. func (p *Ping) Decode(r io.Reader, pver uint32) error { - err := readElements(r, + return readElements(r, &p.Nonce, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target Ping into the passed io.Writer observing the @@ -41,14 +36,9 @@ func (p *Ping) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (p *Ping) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, p.Nonce, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/revoke_and_ack.go b/lnwire/revoke_and_ack.go index f733e2a5..205d4c46 100644 --- a/lnwire/revoke_and_ack.go +++ b/lnwire/revoke_and_ack.go @@ -62,17 +62,12 @@ func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error { // Revocation (32) // NextRevocationKey (33) // NextRevocationHash (32) - err := readElements(r, + return readElements(r, &c.ChannelPoint, c.Revocation[:], &c.NextRevocationKey, c.NextRevocationHash[:], ) - if err != nil { - return err - } - - return nil } // Encode serializes the target RevokeAndAck into the passed io.Writer @@ -80,17 +75,12 @@ func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.Revocation[:], c.NextRevocationKey, c.NextRevocationHash[:], ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/single_funding_complete.go b/lnwire/single_funding_complete.go index 00c7533b..a86e8f26 100644 --- a/lnwire/single_funding_complete.go +++ b/lnwire/single_funding_complete.go @@ -69,17 +69,12 @@ func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error { // FundingOutPoint (36) // CommitmentSignature (73) // RevocationKey (33) - err := readElements(r, + return readElements(r, &s.ChannelID, &s.FundingOutPoint, &s.CommitSignature, &s.RevocationKey, s.StateHintObsfucator[:]) - if err != nil { - return err - } - - return nil } // Encode serializes the target SingleFundingComplete into the passed io.Writer @@ -92,17 +87,12 @@ func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error { // FundingOutPoint (36) // Commitment Signature (73) // RevocationKey (33) - err := writeElements(w, + return writeElements(w, s.ChannelID, s.FundingOutPoint, s.CommitSignature, s.RevocationKey, s.StateHintObsfucator[:]) - if err != nil { - return err - } - - return nil } // Command returns the uint32 code which uniquely identifies this message as a diff --git a/lnwire/single_funding_open_proof.go b/lnwire/single_funding_open_proof.go new file mode 100644 index 00000000..e69de29b diff --git a/lnwire/single_funding_signcomplete.go b/lnwire/single_funding_signcomplete.go index 48d8c0d7..471cf530 100644 --- a/lnwire/single_funding_signcomplete.go +++ b/lnwire/single_funding_signcomplete.go @@ -40,14 +40,9 @@ func NewSingleFundingSignComplete(chanID uint64, func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error { // ChannelID (8) // CommitmentSignature (73) - err := readElements(r, + return readElements(r, &c.ChannelID, &c.CommitSignature) - if err != nil { - return err - } - - return nil } // Encode serializes the target SingleFundingSignComplete into the passed @@ -56,14 +51,9 @@ func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelID, c.CommitSignature) - if err != nil { - return err - } - - return nil } // Command returns the uint32 code which uniquely identifies this message as a diff --git a/lnwire/update_add_htlc.go b/lnwire/update_add_htlc.go index baed20d9..416ff069 100644 --- a/lnwire/update_add_htlc.go +++ b/lnwire/update_add_htlc.go @@ -76,7 +76,7 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error { // Amount(8) // PaymentHash(32) // OnionBlob(1254) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.ID, &c.Expiry, @@ -84,11 +84,6 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error { c.PaymentHash[:], c.OnionBlob[:], ) - if err != nil { - return err - } - - return nil } // Encode serializes the target UpdateAddHTLC into the passed io.Writer observing @@ -96,7 +91,7 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.ID, c.Expiry, @@ -104,11 +99,6 @@ func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error { c.PaymentHash[:], c.OnionBlob[:], ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/update_fail_htlc.go b/lnwire/update_fail_htlc.go index c8d663e5..a41b9891 100644 --- a/lnwire/update_fail_htlc.go +++ b/lnwire/update_fail_htlc.go @@ -108,16 +108,11 @@ func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) // HTLCKey(8) // Reason(??) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.ID, &c.Reason, ) - if err != nil { - return err - } - - return nil } // Encode serializes the target UpdateFailHTLC into the passed io.Writer observing @@ -125,16 +120,11 @@ func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.ID, c.Reason, ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/update_fulfill_htlc.go b/lnwire/update_fulfill_htlc.go index d30f6fc3..07699590 100644 --- a/lnwire/update_fulfill_htlc.go +++ b/lnwire/update_fulfill_htlc.go @@ -48,16 +48,11 @@ func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) // ID(8) // PaymentPreimage(32) - err := readElements(r, + return readElements(r, &c.ChannelPoint, &c.ID, c.PaymentPreimage[:], ) - if err != nil { - return err - } - - return nil } // Encode serializes the target UpdateFufillHTLC into the passed io.Writer @@ -65,16 +60,11 @@ func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error { - err := writeElements(w, + return writeElements(w, c.ChannelPoint, c.ID, c.PaymentPreimage[:], ) - if err != nil { - return err - } - - return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/networktest.go b/networktest.go index e19e84f3..5d8dc44c 100644 --- a/networktest.go +++ b/networktest.go @@ -541,11 +541,8 @@ func (n *networkHarness) ConnectNodes(ctx context.Context, a, b *lightningNode) Host: b.p2pAddr, }, } - if _, err := a.ConnectPeer(ctx, req); err != nil { - return err - } - - return nil + _, err = a.ConnectPeer(ctx, req) + return err } // RestartNode attempts to restart a lightning node by shutting it down diff --git a/utxonursery.go b/utxonursery.go index eed390e8..33d749ca 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -668,7 +668,7 @@ func createSweepTx(wallet *lnwallet.LightningWallet, // chain reorganization occurs. This is the final step in the output incubation // process. func deleteGraduatedOutputs(db *channeldb.DB, deleteHeight uint32) error { - err := db.Update(func(tx *bolt.Tx) error { + return db.Update(func(tx *bolt.Tx) error { kgtnBucket := tx.Bucket(kindergartenBucket) if kgtnBucket == nil { return nil @@ -695,18 +695,13 @@ func deleteGraduatedOutputs(db *channeldb.DB, deleteHeight uint32) error { return nil }) - if err != nil { - return err - } - - return nil } // putLastHeightGraduated persists the most recently processed blockheight // to the database. This blockheight is used during restarts to determine if // blocks were missed while the UTXO Nursery was offline. func putLastHeightGraduated(db *channeldb.DB, blockheight uint32) error { - err := db.Update(func(tx *bolt.Tx) error { + return db.Update(func(tx *bolt.Tx) error { kgtnBucket, err := tx.CreateBucketIfNotExists(kindergartenBucket) if err != nil { return nil @@ -714,17 +709,8 @@ func putLastHeightGraduated(db *channeldb.DB, blockheight uint32) error { heightBytes := make([]byte, 4) byteOrder.PutUint32(heightBytes, blockheight) - if err := kgtnBucket.Put(lastGraduatedHeightKey, heightBytes); err != nil { - return err - } - - return nil + return kgtnBucket.Put(lastGraduatedHeightKey, heightBytes) }) - if err != nil { - return err - } - - return nil } // newSweepPkScript creates a new public key script which should be used to @@ -808,11 +794,8 @@ func serializeKidOutput(w io.Writer, kid *kidOutput) error { } byteOrder.PutUint32(scratch[:4], uint32(kid.signDescriptor.HashType)) - if _, err := w.Write(scratch[:4]); err != nil { - return err - } - - return nil + _, err := w.Write(scratch[:4]) + return err } // deserializeKidOutput takes a byte array representation of a kidOutput @@ -899,11 +882,8 @@ func writeOutpoint(w io.Writer, o *wire.OutPoint) error { } byteOrder.PutUint32(scratch, o.Index) - if _, err := w.Write(scratch); err != nil { - return err - } - - return nil + _, err := w.Write(scratch) + return err } // TODO(bvu): copied from channeldb, remove repetition