lnd: fix gosimple warnings

This commit is contained in:
Andrey Samokhvalov 2017-02-23 21:59:50 +03:00 committed by Olaoluwa Osuntokun
parent f5fd4138a0
commit 8fb54782e2
30 changed files with 73 additions and 319 deletions

@ -443,11 +443,8 @@ func (b *BrontideMachine) RecvActOne(actOne [ActOneSize]byte) error {
// If the initiator doesn't know our static key, then this operation // If the initiator doesn't know our static key, then this operation
// will fail. // will fail.
if _, err := b.DecryptAndHash(p[:]); err != nil { _, err = b.DecryptAndHash(p[:])
return err return err
}
return nil
} }
// GenActTwo generates the second packet (act two) to be sent from the // 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) s := ecdh(b.remoteEphemeral, b.localEphemeral)
b.mixKey(s) b.mixKey(s)
if _, err := b.DecryptAndHash(p[:]); err != nil { _, err = b.DecryptAndHash(p[:])
return err return err
}
return nil
} }
// GenActThree creates the final (act three) packet of the handshake. Act three // 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 // single packet, as any fragmentation should have taken place at a
// higher level. // higher level.
cipherText := b.sendCipher.Encrypt(nil, nil, p) cipherText := b.sendCipher.Encrypt(nil, nil, p)
if _, err := w.Write(cipherText); err != nil { _, err := w.Write(cipherText)
return err return err
}
return nil
} }
// ReadMessage attempts to read the next message from the passed io.Reader. In // ReadMessage attempts to read the next message from the passed io.Reader. In

@ -1269,11 +1269,7 @@ func fetchChannelIDs(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error {
idBytes := nodeChanBucket.Get(idKey) idBytes := nodeChanBucket.Get(idKey)
channel.IdentityPub, err = btcec.ParsePubKey(idBytes, btcec.S256()) channel.IdentityPub, err = btcec.ParsePubKey(idBytes, btcec.S256())
if err != nil { return err
return err
}
return nil
} }
func putChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { 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()) channel.OurCommitKey, err = btcec.ParsePubKey(keyBytes[33:], btcec.S256())
if err != nil { return err
return err
}
return nil
} }
func putChanCommitTxns(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { 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[:]) _, err = io.ReadFull(reader, channel.StateHintObsfucator[:])
if err != nil { return err
return err
}
return nil
} }
func putChanDeliveryScripts(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error { 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, "") channel.TheirDeliveryScript, err = wire.ReadVarBytes(deliveryBytes, 0, 520, "")
if err != nil { return err
return err
}
return nil
} }
// htlcDiskSize represents the number of btyes a serialized HTLC takes up on // 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) byteOrder.PutUint16(buf[n:], h.OutputIndex)
n += 2 n += 2
if _, err := w.Write(buf[:]); err != nil { _, err := w.Write(buf[:])
return err return err
}
return nil
} }
func deserializeHTLC(r io.Reader) (*HTLC, error) { 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) byteOrder.PutUint32(scratch, o.Index)
if _, err := w.Write(scratch); err != nil { _, err := w.Write(scratch)
return err return err
}
return nil
} }
func readOutpoint(r io.Reader, o *wire.OutPoint) error { func readOutpoint(r io.Reader, o *wire.OutPoint) error {

@ -437,11 +437,7 @@ func (d *DB) syncVersions(versions []version) error {
} }
meta.DbVersionNumber = latestVersion meta.DbVersionNumber = latestVersion
if err := putMeta(meta, tx); err != nil { return putMeta(meta, tx)
return err
}
return nil
}) })
} }

@ -76,8 +76,5 @@ func putMeta(meta *Meta, tx *bolt.Tx) error {
func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error { func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error {
scratch := make([]byte, 4) scratch := make([]byte, 4)
byteOrder.PutUint32(scratch, meta.DbVersionNumber) byteOrder.PutUint32(scratch, meta.DbVersionNumber)
if err := metaBucket.Put(dbVersionKey, scratch); err != nil { return metaBucket.Put(dbVersionKey, scratch)
return err
}
return nil
} }

@ -158,11 +158,7 @@ func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) {
// returned to the caller. // returned to the caller.
nodeReader := bytes.NewReader(nodeBytes) nodeReader := bytes.NewReader(nodeBytes)
node, err = deserializeLinkNode(nodeReader) node, err = deserializeLinkNode(nodeReader)
if err != nil { return err
return err
}
return nil
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -127,11 +127,7 @@ func (db *DB) DeleteAllPayments() error {
} }
_, err = tx.CreateBucket(paymentBucket) _, err = tx.CreateBucket(paymentBucket)
if err != nil { return err
return err
}
return nil
}) })
} }

@ -88,14 +88,10 @@ func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) error {
})) }))
// TODO(roasbeef): also check in memory for quick lookups/settles? // TODO(roasbeef): also check in memory for quick lookups/settles?
if err := i.cdb.AddInvoice(invoice); err != nil { return i.cdb.AddInvoice(invoice)
return err
}
// TODO(roasbeef): re-enable? // TODO(roasbeef): re-enable?
//go i.notifyClients(invoice, false) //go i.notifyClients(invoice, false)
return nil
} }
// lookupInvoice looks up an invoice by its payment hash (R-Hash), if found // lookupInvoice looks up an invoice by its payment hash (R-Hash), if found

@ -281,11 +281,7 @@ func (b *BtcWallet) FetchRootKey() (*btcec.PrivateKey, error) {
rootBucket := tx.RootBucket() rootBucket := tx.RootBucket()
rootAddrHash = rootAddr[0].Address().ScriptAddress() rootAddrHash = rootAddr[0].Address().ScriptAddress()
if err := rootBucket.Put(rootKey, rootAddrHash); err != nil { return rootBucket.Put(rootKey, rootAddrHash)
return err
}
return nil
}); err != nil { }); err != nil {
return nil, err return nil, err
} }

@ -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. // Wait until the wallet has finished syncing up to the main chain.
ticker := time.NewTicker(100 * time.Millisecond) ticker := time.NewTicker(100 * time.Millisecond)
expectedBalance := btcutil.Amount(satoshiPerOutput * int64(numOutputs)) expectedBalance := btcutil.Amount(satoshiPerOutput * int64(numOutputs))
out:
for { for range ticker.C {
select { balance, err := w.ConfirmedBalance(1, false)
case <-ticker.C: if err != nil {
balance, err := w.ConfirmedBalance(1, false) return err
if err != nil { }
return err if balance == expectedBalance {
} break
if balance == expectedBalance {
break out
}
} }
} }
ticker.Stop() ticker.Stop()

@ -56,7 +56,7 @@ func (a *ChannelAnnouncement) Validate() error {
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error { func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
err := readElements(r, return readElements(r,
&c.FirstNodeSig, &c.FirstNodeSig,
&c.SecondNodeSig, &c.SecondNodeSig,
&c.ChannelID, &c.ChannelID,
@ -67,11 +67,6 @@ func (c *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
&c.FirstBitcoinKey, &c.FirstBitcoinKey,
&c.SecondBitcoinKey, &c.SecondBitcoinKey,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target ChannelAnnouncement into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error { func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.FirstNodeSig, c.FirstNodeSig,
c.SecondNodeSig, c.SecondNodeSig,
c.ChannelID, c.ChannelID,
@ -90,11 +85,6 @@ func (c *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error {
c.FirstBitcoinKey, c.FirstBitcoinKey,
c.SecondBitcoinKey, c.SecondBitcoinKey,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -72,7 +72,7 @@ func (a *ChannelUpdateAnnouncement) Validate() error {
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error { func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
err := readElements(r, return readElements(r,
&c.Signature, &c.Signature,
&c.ChannelID, &c.ChannelID,
&c.Timestamp, &c.Timestamp,
@ -82,11 +82,6 @@ func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
&c.FeeBaseMsat, &c.FeeBaseMsat,
&c.FeeProportionalMillionths, &c.FeeProportionalMillionths,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target ChannelUpdateAnnouncement into the passed // 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. // This is part of the lnwire.Message interface.
func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error { func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.Signature, c.Signature,
c.ChannelID, c.ChannelID,
c.Timestamp, c.Timestamp,
@ -104,11 +99,6 @@ func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
c.FeeBaseMsat, c.FeeBaseMsat,
c.FeeProportionalMillionths, c.FeeProportionalMillionths,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -43,14 +43,9 @@ var _ Message = (*CloseComplete)(nil)
func (c *CloseComplete) Decode(r io.Reader, pver uint32) error { func (c *CloseComplete) Decode(r io.Reader, pver uint32) error {
// ChannelPoint (8) // ChannelPoint (8)
// ResponderCloseSig (73) // ResponderCloseSig (73)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.ResponderCloseSig) &c.ResponderCloseSig)
if err != nil {
return err
}
return nil
} }
// Encode serializes the target CloseComplete into the passed io.Writer observing // 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 { func (c *CloseComplete) Encode(w io.Writer, pver uint32) error {
// ChannelPoint (8) // ChannelPoint (8)
// ResponderCloseSig (73) // ResponderCloseSig (73)
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.ResponderCloseSig) c.ResponderCloseSig)
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -57,15 +57,10 @@ func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
// RequesterCloseSig (73) // RequesterCloseSig (73)
// First byte length then sig // First byte length then sig
// Fee (8) // Fee (8)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.RequesterCloseSig, &c.RequesterCloseSig,
&c.Fee) &c.Fee)
if err != nil {
return err
}
return nil
} }
// Encode serializes the target CloseRequest into the passed io.Writer observing // 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 // ChannelID
// RequesterCloseSig // RequesterCloseSig
// Fee // Fee
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.RequesterCloseSig, c.RequesterCloseSig,
c.Fee) c.Fee)
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -46,15 +46,10 @@ var _ Message = (*CommitSig)(nil)
func (c *CommitSig) Decode(r io.Reader, pver uint32) error { func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
// ChannelPoint(8) // ChannelPoint(8)
// RequesterCommitSig(73max+2) // RequesterCommitSig(73max+2)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.CommitSig, &c.CommitSig,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target CommitSig into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *CommitSig) Encode(w io.Writer, pver uint32) error { func (c *CommitSig) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.CommitSig, c.CommitSig,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -73,17 +73,12 @@ var _ Message = (*ErrorGeneric)(nil)
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error { func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
// ChannelPoint(8) // ChannelPoint(8)
// Problem // Problem
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.Code, &c.Code,
&c.Problem, &c.Problem,
&c.PendingChannelID, &c.PendingChannelID,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target ErrorGeneric into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error { func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.Code, c.Code,
c.Problem, c.Problem,
c.PendingChannelID, c.PendingChannelID,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying an ErrorGeneric message on // Command returns the integer uniquely identifying an ErrorGeneric message on

@ -197,11 +197,8 @@ func (f *FeatureVector) Encode(w io.Writer) error {
setFlag(data, position, flag) setFlag(data, position, flag)
} }
if _, err := w.Write(data); err != nil { _, err := w.Write(data)
return err return err
}
return nil
} }
// Compare checks that features are compatible and returns the features which // Compare checks that features are compatible and returns the features which

@ -1,8 +1,8 @@
package lnwire package lnwire
import ( import (
"io"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"io"
) )
// Init is the first message reveals the features supported or required by this // 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 { func (msg *Init) Decode(r io.Reader, pver uint32) error {
// LocalFeatures(~) // LocalFeatures(~)
// GlobalFeatures(~) // GlobalFeatures(~)
err := readElements(r, return readElements(r,
&msg.LocalFeatures, &msg.LocalFeatures,
&msg.GlobalFeatures, &msg.GlobalFeatures,
) )
if err != nil {
return err
}
return nil
} }
// A compile time check to ensure Init implements the lnwire.Message // 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. // This is part of the lnwire.Message interface.
func (msg *Init) Encode(w io.Writer, pver uint32) error { func (msg *Init) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
msg.LocalFeatures, msg.LocalFeatures,
msg.GlobalFeatures, msg.GlobalFeatures,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -244,11 +244,7 @@ func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet)
// Write payload the payload itself after the header. // Write payload the payload itself after the header.
n, err = w.Write(payload) n, err = w.Write(payload)
totalBytes += n totalBytes += n
if err != nil { return totalBytes, err
return totalBytes, err
}
return totalBytes, nil
} }
// ReadMessageN reads, validates, and parses the next bitcoin Message from r for // ReadMessageN reads, validates, and parses the next bitcoin Message from r for

@ -128,7 +128,7 @@ func (a *NodeAnnouncement) Validate() error {
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error { func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
err := readElements(r, return readElements(r,
&c.Signature, &c.Signature,
&c.Timestamp, &c.Timestamp,
&c.Address, &c.Address,
@ -137,11 +137,6 @@ func (c *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
&c.pad, &c.pad,
&c.Alias, &c.Alias,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target NodeAnnouncement into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error { func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.Signature, c.Signature,
c.Timestamp, c.Timestamp,
c.Address, c.Address,
@ -158,11 +153,6 @@ func (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
c.pad, c.pad,
c.Alias, c.Alias,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -27,14 +27,9 @@ var _ Message = (*Pong)(nil)
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (p *Pong) Decode(r io.Reader, pver uint32) error { func (p *Pong) Decode(r io.Reader, pver uint32) error {
err := readElements(r, return readElements(r,
&p.Nonce, &p.Nonce,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target Pong into the passed io.Writer observing the // 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. // This is part of the lnwire.Message interface.
func (p *Pong) Encode(w io.Writer, pver uint32) error { func (p *Pong) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
p.Nonce, p.Nonce,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -26,14 +26,9 @@ var _ Message = (*Ping)(nil)
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (p *Ping) Decode(r io.Reader, pver uint32) error { func (p *Ping) Decode(r io.Reader, pver uint32) error {
err := readElements(r, return readElements(r,
&p.Nonce, &p.Nonce,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target Ping into the passed io.Writer observing the // 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. // This is part of the lnwire.Message interface.
func (p *Ping) Encode(w io.Writer, pver uint32) error { func (p *Ping) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
p.Nonce, p.Nonce,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -62,17 +62,12 @@ func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
// Revocation (32) // Revocation (32)
// NextRevocationKey (33) // NextRevocationKey (33)
// NextRevocationHash (32) // NextRevocationHash (32)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
c.Revocation[:], c.Revocation[:],
&c.NextRevocationKey, &c.NextRevocationKey,
c.NextRevocationHash[:], c.NextRevocationHash[:],
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target RevokeAndAck into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error { func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.Revocation[:], c.Revocation[:],
c.NextRevocationKey, c.NextRevocationKey,
c.NextRevocationHash[:], c.NextRevocationHash[:],
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -69,17 +69,12 @@ func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
// FundingOutPoint (36) // FundingOutPoint (36)
// CommitmentSignature (73) // CommitmentSignature (73)
// RevocationKey (33) // RevocationKey (33)
err := readElements(r, return readElements(r,
&s.ChannelID, &s.ChannelID,
&s.FundingOutPoint, &s.FundingOutPoint,
&s.CommitSignature, &s.CommitSignature,
&s.RevocationKey, &s.RevocationKey,
s.StateHintObsfucator[:]) s.StateHintObsfucator[:])
if err != nil {
return err
}
return nil
} }
// Encode serializes the target SingleFundingComplete into the passed io.Writer // 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) // FundingOutPoint (36)
// Commitment Signature (73) // Commitment Signature (73)
// RevocationKey (33) // RevocationKey (33)
err := writeElements(w, return writeElements(w,
s.ChannelID, s.ChannelID,
s.FundingOutPoint, s.FundingOutPoint,
s.CommitSignature, s.CommitSignature,
s.RevocationKey, s.RevocationKey,
s.StateHintObsfucator[:]) s.StateHintObsfucator[:])
if err != nil {
return err
}
return nil
} }
// Command returns the uint32 code which uniquely identifies this message as a // Command returns the uint32 code which uniquely identifies this message as a

@ -40,14 +40,9 @@ func NewSingleFundingSignComplete(chanID uint64,
func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error { func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
// ChannelID (8) // ChannelID (8)
// CommitmentSignature (73) // CommitmentSignature (73)
err := readElements(r, return readElements(r,
&c.ChannelID, &c.ChannelID,
&c.CommitSignature) &c.CommitSignature)
if err != nil {
return err
}
return nil
} }
// Encode serializes the target SingleFundingSignComplete into the passed // 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. // This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error { func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelID, c.ChannelID,
c.CommitSignature) c.CommitSignature)
if err != nil {
return err
}
return nil
} }
// Command returns the uint32 code which uniquely identifies this message as a // Command returns the uint32 code which uniquely identifies this message as a

@ -76,7 +76,7 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
// Amount(8) // Amount(8)
// PaymentHash(32) // PaymentHash(32)
// OnionBlob(1254) // OnionBlob(1254)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.ID, &c.ID,
&c.Expiry, &c.Expiry,
@ -84,11 +84,6 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
c.PaymentHash[:], c.PaymentHash[:],
c.OnionBlob[:], c.OnionBlob[:],
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target UpdateAddHTLC into the passed io.Writer observing // 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. // This is part of the lnwire.Message interface.
func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error { func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.ID, c.ID,
c.Expiry, c.Expiry,
@ -104,11 +99,6 @@ func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
c.PaymentHash[:], c.PaymentHash[:],
c.OnionBlob[:], c.OnionBlob[:],
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -108,16 +108,11 @@ func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
// ChannelPoint(8) // ChannelPoint(8)
// HTLCKey(8) // HTLCKey(8)
// Reason(??) // Reason(??)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.ID, &c.ID,
&c.Reason, &c.Reason,
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target UpdateFailHTLC into the passed io.Writer observing // 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. // This is part of the lnwire.Message interface.
func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error { func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.ID, c.ID,
c.Reason, c.Reason,
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -48,16 +48,11 @@ func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error {
// ChannelPoint(8) // ChannelPoint(8)
// ID(8) // ID(8)
// PaymentPreimage(32) // PaymentPreimage(32)
err := readElements(r, return readElements(r,
&c.ChannelPoint, &c.ChannelPoint,
&c.ID, &c.ID,
c.PaymentPreimage[:], c.PaymentPreimage[:],
) )
if err != nil {
return err
}
return nil
} }
// Encode serializes the target UpdateFufillHTLC into the passed io.Writer // 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. // This is part of the lnwire.Message interface.
func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error { func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error {
err := writeElements(w, return writeElements(w,
c.ChannelPoint, c.ChannelPoint,
c.ID, c.ID,
c.PaymentPreimage[:], c.PaymentPreimage[:],
) )
if err != nil {
return err
}
return nil
} }
// Command returns the integer uniquely identifying this message type on the // Command returns the integer uniquely identifying this message type on the

@ -541,11 +541,8 @@ func (n *networkHarness) ConnectNodes(ctx context.Context, a, b *lightningNode)
Host: b.p2pAddr, Host: b.p2pAddr,
}, },
} }
if _, err := a.ConnectPeer(ctx, req); err != nil { _, err = a.ConnectPeer(ctx, req)
return err return err
}
return nil
} }
// RestartNode attempts to restart a lightning node by shutting it down // RestartNode attempts to restart a lightning node by shutting it down

@ -668,7 +668,7 @@ func createSweepTx(wallet *lnwallet.LightningWallet,
// chain reorganization occurs. This is the final step in the output incubation // chain reorganization occurs. This is the final step in the output incubation
// process. // process.
func deleteGraduatedOutputs(db *channeldb.DB, deleteHeight uint32) error { 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) kgtnBucket := tx.Bucket(kindergartenBucket)
if kgtnBucket == nil { if kgtnBucket == nil {
return nil return nil
@ -695,18 +695,13 @@ func deleteGraduatedOutputs(db *channeldb.DB, deleteHeight uint32) error {
return nil return nil
}) })
if err != nil {
return err
}
return nil
} }
// putLastHeightGraduated persists the most recently processed blockheight // putLastHeightGraduated persists the most recently processed blockheight
// to the database. This blockheight is used during restarts to determine if // to the database. This blockheight is used during restarts to determine if
// blocks were missed while the UTXO Nursery was offline. // blocks were missed while the UTXO Nursery was offline.
func putLastHeightGraduated(db *channeldb.DB, blockheight uint32) error { 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) kgtnBucket, err := tx.CreateBucketIfNotExists(kindergartenBucket)
if err != nil { if err != nil {
return nil return nil
@ -714,17 +709,8 @@ func putLastHeightGraduated(db *channeldb.DB, blockheight uint32) error {
heightBytes := make([]byte, 4) heightBytes := make([]byte, 4)
byteOrder.PutUint32(heightBytes, blockheight) byteOrder.PutUint32(heightBytes, blockheight)
if err := kgtnBucket.Put(lastGraduatedHeightKey, heightBytes); err != nil { return kgtnBucket.Put(lastGraduatedHeightKey, heightBytes)
return err
}
return nil
}) })
if err != nil {
return err
}
return nil
} }
// newSweepPkScript creates a new public key script which should be used to // 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)) byteOrder.PutUint32(scratch[:4], uint32(kid.signDescriptor.HashType))
if _, err := w.Write(scratch[:4]); err != nil { _, err := w.Write(scratch[:4])
return err return err
}
return nil
} }
// deserializeKidOutput takes a byte array representation of a kidOutput // 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) byteOrder.PutUint32(scratch, o.Index)
if _, err := w.Write(scratch); err != nil { _, err := w.Write(scratch)
return err return err
}
return nil
} }
// TODO(bvu): copied from channeldb, remove repetition // TODO(bvu): copied from channeldb, remove repetition