multi: fix linting errors

This commit is contained in:
Conner Fromknecht 2018-07-31 01:29:12 -07:00
parent 8beeeb1944
commit cf2c371042
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
18 changed files with 89 additions and 72 deletions

@ -1259,7 +1259,7 @@ func TestBreachSecondLevelTransfer(t *testing.T) {
// output is spent by a second level tx. // output is spent by a second level tx.
secondLvlTx := &wire.MsgTx{ secondLvlTx := &wire.MsgTx{
TxOut: []*wire.TxOut{ TxOut: []*wire.TxOut{
&wire.TxOut{Value: 1}, {Value: 1},
}, },
} }
notifier.Spend(htlcOutpoint, 2, secondLvlTx) notifier.Spend(htlcOutpoint, 2, secondLvlTx)

@ -10,8 +10,8 @@ import (
type unknownAddrType struct{} type unknownAddrType struct{}
func (_ unknownAddrType) Network() string { return "unknown" } func (t unknownAddrType) Network() string { return "unknown" }
func (_ unknownAddrType) String() string { return "unknown" } func (t unknownAddrType) String() string { return "unknown" }
var addrTests = []struct { var addrTests = []struct {
expAddr net.Addr expAddr net.Addr

@ -299,7 +299,7 @@ type ChannelStatus uint8
var ( var (
// Default is the normal state of an open channel. // Default is the normal state of an open channel.
Default ChannelStatus = 0 Default ChannelStatus
// Borked indicates that the channel has entered an irreconcilable // Borked indicates that the channel has entered an irreconcilable
// state, triggered by a state desynchronization or channel breach. // state, triggered by a state desynchronization or channel breach.

@ -613,8 +613,8 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
// pruneLinkNode determines whether we should garbage collect a link node from // pruneLinkNode determines whether we should garbage collect a link node from
// the database due to no longer having any open channels with it. If there are // the database due to no longer having any open channels with it. If there are
// any left, then this acts as a no-op. // any left, then this acts as a no-op.
func (db *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error { func (d *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error {
openChannels, err := db.fetchOpenChannels(tx, remotePub) openChannels, err := d.fetchOpenChannels(tx, remotePub)
if err != nil { if err != nil {
return fmt.Errorf("unable to fetch open channels for peer %x: "+ return fmt.Errorf("unable to fetch open channels for peer %x: "+
"%v", remotePub.SerializeCompressed(), err) "%v", remotePub.SerializeCompressed(), err)
@ -627,20 +627,20 @@ func (db *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error {
log.Infof("Pruning link node %x with zero open channels from database", log.Infof("Pruning link node %x with zero open channels from database",
remotePub.SerializeCompressed()) remotePub.SerializeCompressed())
return db.deleteLinkNode(tx, remotePub) return d.deleteLinkNode(tx, remotePub)
} }
// PruneLinkNodes attempts to prune all link nodes found within the databse with // PruneLinkNodes attempts to prune all link nodes found within the databse with
// whom we no longer have any open channels with. // whom we no longer have any open channels with.
func (db *DB) PruneLinkNodes() error { func (d *DB) PruneLinkNodes() error {
return db.Update(func(tx *bolt.Tx) error { return d.Update(func(tx *bolt.Tx) error {
linkNodes, err := db.fetchAllLinkNodes(tx) linkNodes, err := d.fetchAllLinkNodes(tx)
if err != nil { if err != nil {
return err return err
} }
for _, linkNode := range linkNodes { for _, linkNode := range linkNodes {
err := db.pruneLinkNode(tx, linkNode.IdentityPub) err := d.pruneLinkNode(tx, linkNode.IdentityPub)
if err != nil { if err != nil {
return err return err
} }

@ -809,8 +809,8 @@ func (c *ChannelGraph) pruneGraphNodes(tx *bolt.Tx, nodes *bolt.Bucket,
// With the nodes extracted, we'll increase the ref count of // With the nodes extracted, we'll increase the ref count of
// each of the nodes. // each of the nodes.
nodeRefCounts[node1] += 1 nodeRefCounts[node1]++
nodeRefCounts[node2] += 1 nodeRefCounts[node2]++
return nil return nil
}) })

@ -129,13 +129,13 @@ func putLinkNode(nodeMetaBucket *bolt.Bucket, l *LinkNode) error {
// DeleteLinkNode removes the link node with the given identity from the // DeleteLinkNode removes the link node with the given identity from the
// database. // database.
func (d *DB) DeleteLinkNode(identity *btcec.PublicKey) error { func (db *DB) DeleteLinkNode(identity *btcec.PublicKey) error {
return d.Update(func(tx *bolt.Tx) error { return db.Update(func(tx *bolt.Tx) error {
return d.deleteLinkNode(tx, identity) return db.deleteLinkNode(tx, identity)
}) })
} }
func (d *DB) deleteLinkNode(tx *bolt.Tx, identity *btcec.PublicKey) error { func (db *DB) deleteLinkNode(tx *bolt.Tx, identity *btcec.PublicKey) error {
nodeMetaBucket := tx.Bucket(nodeInfoBucket) nodeMetaBucket := tx.Bucket(nodeInfoBucket)
if nodeMetaBucket == nil { if nodeMetaBucket == nil {
return ErrLinkNodesNotFound return ErrLinkNodesNotFound

@ -27,8 +27,8 @@ import (
const ( const (
defaultTLSCertFilename = "tls.cert" defaultTLSCertFilename = "tls.cert"
defaultMacaroonFilename = "admin.macaroon" defaultMacaroonFilename = "admin.macaroon"
defaultRpcPort = "10009" defaultRPCPort = "10009"
defaultRpcHostPort = "localhost:" + defaultRpcPort defaultRPCHostPort = "localhost:" + defaultRPCPort
) )
var ( var (
@ -150,7 +150,7 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
// and not just TCP addresses. // and not just TCP addresses.
opts = append( opts = append(
opts, grpc.WithDialer( opts, grpc.WithDialer(
lncfg.ClientAddressDialer(defaultRpcPort), lncfg.ClientAddressDialer(defaultRPCPort),
), ),
) )
conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...) conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...)
@ -169,7 +169,7 @@ func main() {
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "rpcserver", Name: "rpcserver",
Value: defaultRpcHostPort, Value: defaultRPCHostPort,
Usage: "host:port of ln daemon", Usage: "host:port of ln daemon",
}, },
cli.StringFlag{ cli.StringFlag{

@ -1225,9 +1225,9 @@ func (d *AuthenticatedGossiper) networkHandler() {
} }
} }
// TODO(roasbeef): d/c peers that send uupdates not on our chain // TODO(roasbeef): d/c peers that send updates not on our chain
// InitPeerSyncState is called by outside sub-systems when a connection is // InitSyncState is called by outside sub-systems when a connection is
// established to a new peer that understands how to perform channel range // established to a new peer that understands how to perform channel range
// queries. We'll allocate a new gossip syncer for it, and start any goroutines // queries. We'll allocate a new gossip syncer for it, and start any goroutines
// needed to handle new queries. The recvUpdates bool indicates if we should // needed to handle new queries. The recvUpdates bool indicates if we should

@ -40,10 +40,12 @@ const (
// and accepting updates. // and accepting updates.
minCommitFeePerKw = 253 minCommitFeePerKw = 253
// DefaultMinLinkFeeUpdateTimeout and DefaultMaxLinkFeeUpdateTimeout // DefaultMinLinkFeeUpdateTimeout represents the minimum interval in
// represent the default timeout bounds in which a link should propose // which a link should propose to update its commitment fee rate.
// to update its commitment fee rate.
DefaultMinLinkFeeUpdateTimeout = 10 * time.Minute DefaultMinLinkFeeUpdateTimeout = 10 * time.Minute
// DefaultMaxLinkFeeUpdateTimeout represents the maximum interval in
// which a link should propose to update its commitment fee rate.
DefaultMaxLinkFeeUpdateTimeout = 60 * time.Minute DefaultMaxLinkFeeUpdateTimeout = 60 * time.Minute
) )

@ -72,8 +72,8 @@ func ListenOnAddress(addr net.Addr) (net.Listener, error) {
return net.Listen(addr.Network(), addr.String()) return net.Listen(addr.Network(), addr.String())
} }
// TlsListenOnAddress creates a TLS listener that listens on the given address. // TLSListenOnAddress creates a TLS listener that listens on the given address.
func TlsListenOnAddress(addr net.Addr, func TLSListenOnAddress(addr net.Addr,
config *tls.Config) (net.Listener, error) { config *tls.Config) (net.Listener, error) {
return tls.Listen(addr.Network(), addr.String(), config) return tls.Listen(addr.Network(), addr.String(), config)
} }

4
lnd.go

@ -360,7 +360,7 @@ func lndMain() error {
return err return err
} }
for _, restEndpoint := range cfg.RESTListeners { for _, restEndpoint := range cfg.RESTListeners {
lis, err := lncfg.TlsListenOnAddress(restEndpoint, tlsConf) lis, err := lncfg.TLSListenOnAddress(restEndpoint, tlsConf)
if err != nil { if err != nil {
ltndLog.Errorf( ltndLog.Errorf(
"gRPC proxy unable to listen on %s", "gRPC proxy unable to listen on %s",
@ -761,7 +761,7 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr,
srv := &http.Server{Handler: mux} srv := &http.Server{Handler: mux}
for _, restEndpoint := range restEndpoints { for _, restEndpoint := range restEndpoints {
lis, err := lncfg.TlsListenOnAddress(restEndpoint, tlsConf) lis, err := lncfg.TLSListenOnAddress(restEndpoint, tlsConf)
if err != nil { if err != nil {
ltndLog.Errorf( ltndLog.Errorf(
"password gRPC proxy unable to listen on %s", "password gRPC proxy unable to listen on %s",

@ -3995,7 +3995,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// We'll decode the invoice's payment request to determine which // We'll decode the invoice's payment request to determine which
// channels were used as routing hints. // channels were used as routing hints.
payReq := &lnrpc.PayReqString{resp.PaymentRequest} payReq := &lnrpc.PayReqString{
PayReq: resp.PaymentRequest,
}
decoded, err = net.Alice.DecodePayReq(ctxb, payReq) decoded, err = net.Alice.DecodePayReq(ctxb, payReq)
if err != nil { if err != nil {
predErr = fmt.Errorf("unable to decode payment "+ predErr = fmt.Errorf("unable to decode payment "+
@ -10784,7 +10786,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
for i, hop := range route.Hops { for i, hop := range route.Hops {
if hop.ChanId != hopChanIDs[i] { if hop.ChanId != hopChanIDs[i] {
t.Fatalf("expected chan id %d, got %d", t.Fatalf("expected chan id %d, got %d",
hop.ChanId) hopChanIDs[i], hop.ChanId)
} }
} }
} }

@ -302,8 +302,10 @@ func (hn *HarnessNode) start(lndError chan<- error) error {
hex.EncodeToString(hn.PubKey[:logPubKeyBytes])) hex.EncodeToString(hn.PubKey[:logPubKeyBytes]))
err := os.Rename(fileName, newFileName) err := os.Rename(fileName, newFileName)
if err != nil { if err != nil {
fmt.Errorf("could not rename %s to %s: %v", fmt.Printf("could not rename "+
fileName, newFileName, err) "%s to %s: %v\n",
fileName, newFileName,
err)
} }
} }
} }
@ -481,7 +483,7 @@ func (hn *HarnessNode) writePidFile() error {
return nil return nil
} }
// connectRPC uses the TLS certificate and admin macaroon files written by the // ConnectRPC uses the TLS certificate and admin macaroon files written by the
// lnd node to create a gRPC client connection. // lnd node to create a gRPC client connection.
func (hn *HarnessNode) ConnectRPC(useMacs bool) (*grpc.ClientConn, error) { func (hn *HarnessNode) ConnectRPC(useMacs bool) (*grpc.ClientConn, error) {
// Wait until TLS certificate and admin macaroon are created before // Wait until TLS certificate and admin macaroon are created before

@ -3924,7 +3924,7 @@ func (i *InvalidCommitSigError) Error() string {
// error interface. // error interface.
var _ error = (*InvalidCommitSigError)(nil) var _ error = (*InvalidCommitSigError)(nil)
// InvalidCommitSigError is a struc that implements the error interface to // InvalidHtlcSigError is a struct that implements the error interface to
// report a failure to validate an htlc signature from a remote peer. We'll use // report a failure to validate an htlc signature from a remote peer. We'll use
// the items in this struct to generate a rich error message for the remote // the items in this struct to generate a rich error message for the remote
// peer when we receive an invalid signature from it. Doing so can greatly aide // peer when we receive an invalid signature from it. Doing so can greatly aide

@ -2190,7 +2190,6 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
t.Fatalf("couldn't start bob client: %v", err) t.Fatalf("couldn't start bob client: %v", err)
} }
default: default:
return
t.Fatalf("unknown chain driver: %v", backEnd) t.Fatalf("unknown chain driver: %v", backEnd)
} }

@ -72,7 +72,7 @@ func (g *GossipTimestampRange) MsgType() MessageType {
// version. // version.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *GossipTimestampRange) MaxPayloadLength(uint32) uint32 { func (g *GossipTimestampRange) MaxPayloadLength(uint32) uint32 {
// 32 + 4 + 4 // 32 + 4 + 4
// //
// TODO(roasbeef): update to 8 byte timestmaps? // TODO(roasbeef): update to 8 byte timestmaps?

@ -2101,12 +2101,20 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
return payIntent, nil return payIntent, nil
} }
type paymentIntentResponse struct {
Route *routing.Route
Preimage [32]byte
Err error
}
// dispatchPaymentIntent attempts to fully dispatch an RPC payment intent. // dispatchPaymentIntent attempts to fully dispatch an RPC payment intent.
// We'll either pass the payment as a whole to the channel router, or give it a // We'll either pass the payment as a whole to the channel router, or give it a
// pre-built route. The first error this method returns denotes if we were // pre-built route. The first error this method returns denotes if we were
// unable to save the payment. The second error returned denotes if the payment // unable to save the payment. The second error returned denotes if the payment
// didn't succeed. // didn't succeed.
func (r *rpcServer) dispatchPaymentIntent(payIntent *rpcPaymentIntent) (*routing.Route, [32]byte, error, error) { func (r *rpcServer) dispatchPaymentIntent(
payIntent *rpcPaymentIntent) (*paymentIntentResponse, error) {
// Construct a payment request to send to the channel router. If the // Construct a payment request to send to the channel router. If the
// payment is successful, the route chosen will be returned. Otherwise, // payment is successful, the route chosen will be returned. Otherwise,
// we'll get a non-nil error. // we'll get a non-nil error.
@ -2149,7 +2157,9 @@ func (r *rpcServer) dispatchPaymentIntent(payIntent *rpcPaymentIntent) (*routing
// If the route failed, then we'll return a nil save err, but a non-nil // If the route failed, then we'll return a nil save err, but a non-nil
// routing err. // routing err.
if routerErr != nil { if routerErr != nil {
return nil, preImage, nil, routerErr return &paymentIntentResponse{
Err: routerErr,
}, nil
} }
// If a route was used to complete this payment, then we'll need to // If a route was used to complete this payment, then we'll need to
@ -2167,10 +2177,13 @@ func (r *rpcServer) dispatchPaymentIntent(payIntent *rpcPaymentIntent) (*routing
if err != nil { if err != nil {
// We weren't able to save the payment, so we return the save // We weren't able to save the payment, so we return the save
// err, but a nil routing err. // err, but a nil routing err.
return nil, preImage, err, nil return nil, err
} }
return route, preImage, nil, nil return &paymentIntentResponse{
Route: route,
Preimage: preImage,
}, nil
} }
// sendPayment takes a paymentStream (a source of pre-built routes or payment // sendPayment takes a paymentStream (a source of pre-built routes or payment
@ -2283,34 +2296,35 @@ func (r *rpcServer) sendPayment(stream *paymentStream) error {
htlcSema <- struct{}{} htlcSema <- struct{}{}
}() }()
route, preImage, saveErr, routeErr := r.dispatchPaymentIntent( resp, saveErr := r.dispatchPaymentIntent(
payIntent, payIntent,
) )
switch { switch {
// If we receive payment error than, instead of
// terminating the stream, send error response
// to the user.
case routeErr != nil:
err := stream.send(&lnrpc.SendResponse{
PaymentError: routeErr.Error(),
})
if err != nil {
errChan <- err
}
return
// If we were unable to save the state of the // If we were unable to save the state of the
// payment, then we'll return the error to the // payment, then we'll return the error to the
// user, and terminate. // user, and terminate.
case saveErr != nil: case saveErr != nil:
errChan <- saveErr errChan <- saveErr
return return
// If we receive payment error than, instead of
// terminating the stream, send error response
// to the user.
case resp.Err != nil:
err := stream.send(&lnrpc.SendResponse{
PaymentError: resp.Err.Error(),
})
if err != nil {
errChan <- err
}
return
} }
marshalledRouted := marshallRoute(resp.Route)
err := stream.send(&lnrpc.SendResponse{ err := stream.send(&lnrpc.SendResponse{
PaymentPreimage: preImage[:], PaymentPreimage: resp.Preimage[:],
PaymentRoute: marshallRoute(route), PaymentRoute: marshalledRouted,
}) })
if err != nil { if err != nil {
errChan <- err errChan <- err
@ -2385,20 +2399,20 @@ func (r *rpcServer) sendPaymentSync(ctx context.Context,
// With the payment validated, we'll now attempt to dispatch the // With the payment validated, we'll now attempt to dispatch the
// payment. // payment.
route, preImage, saveErr, routeErr := r.dispatchPaymentIntent(&payIntent) resp, saveErr := r.dispatchPaymentIntent(&payIntent)
switch { switch {
case routeErr != nil:
return &lnrpc.SendResponse{
PaymentError: routeErr.Error(),
}, nil
case saveErr != nil: case saveErr != nil:
return nil, err return nil, saveErr
case resp.Err != nil:
return &lnrpc.SendResponse{
PaymentError: resp.Err.Error(),
}, nil
} }
return &lnrpc.SendResponse{ return &lnrpc.SendResponse{
PaymentPreimage: preImage[:], PaymentPreimage: resp.Preimage[:],
PaymentRoute: marshallRoute(route), PaymentRoute: marshallRoute(resp.Route),
}, nil }, nil
} }

@ -366,9 +366,9 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
// If we were requested to automatically configure port forwarding, // If we were requested to automatically configure port forwarding,
// we'll use the ports that the server will be listening on. // we'll use the ports that the server will be listening on.
externalIpStrings := make([]string, len(cfg.ExternalIPs)) externalIPStrings := make([]string, len(cfg.ExternalIPs))
for idx, ip := range cfg.ExternalIPs { for idx, ip := range cfg.ExternalIPs {
externalIpStrings[idx] = ip.String() externalIPStrings[idx] = ip.String()
} }
if s.natTraversal != nil { if s.natTraversal != nil {
listenPorts := make([]uint16, 0, len(listenAddrs)) listenPorts := make([]uint16, 0, len(listenAddrs))
@ -391,14 +391,14 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
srvrLog.Infof("Automatically set up port forwarding "+ srvrLog.Infof("Automatically set up port forwarding "+
"using %s to advertise external IP", "using %s to advertise external IP",
s.natTraversal.Name()) s.natTraversal.Name())
externalIpStrings = append(externalIpStrings, ips...) externalIPStrings = append(externalIPStrings, ips...)
} }
} }
// If external IP addresses have been specified, add those to the list // If external IP addresses have been specified, add those to the list
// of this server's addresses. // of this server's addresses.
externalIPs, err := lncfg.NormalizeAddresses( externalIPs, err := lncfg.NormalizeAddresses(
externalIpStrings, strconv.Itoa(defaultPeerPort), externalIPStrings, strconv.Itoa(defaultPeerPort),
cfg.net.ResolveTCPAddr, cfg.net.ResolveTCPAddr,
) )
if err != nil { if err != nil {
@ -2593,8 +2593,6 @@ func (s *server) ConnectToPeer(addr *lnwire.NetAddress, perm bool) error {
case <-s.quit: case <-s.quit:
return ErrServerShuttingDown return ErrServerShuttingDown
} }
return nil
} }
// connectToPeer establishes a connection to a remote peer. errChan is used to // connectToPeer establishes a connection to a remote peer. errChan is used to