diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 45dc93f5..03de6b16 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1259,7 +1259,7 @@ func TestBreachSecondLevelTransfer(t *testing.T) { // output is spent by a second level tx. secondLvlTx := &wire.MsgTx{ TxOut: []*wire.TxOut{ - &wire.TxOut{Value: 1}, + {Value: 1}, }, } notifier.Spend(htlcOutpoint, 2, secondLvlTx) diff --git a/channeldb/addr_test.go b/channeldb/addr_test.go index d093bb3d..c4bc4e8e 100644 --- a/channeldb/addr_test.go +++ b/channeldb/addr_test.go @@ -10,8 +10,8 @@ import ( type unknownAddrType struct{} -func (_ unknownAddrType) Network() string { return "unknown" } -func (_ unknownAddrType) String() string { return "unknown" } +func (t unknownAddrType) Network() string { return "unknown" } +func (t unknownAddrType) String() string { return "unknown" } var addrTests = []struct { expAddr net.Addr diff --git a/channeldb/channel.go b/channeldb/channel.go index 4810b5e6..740d23ea 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -299,7 +299,7 @@ type ChannelStatus uint8 var ( // Default is the normal state of an open channel. - Default ChannelStatus = 0 + Default ChannelStatus // Borked indicates that the channel has entered an irreconcilable // state, triggered by a state desynchronization or channel breach. diff --git a/channeldb/db.go b/channeldb/db.go index f3b6ede1..3b50d718 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -613,8 +613,8 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error { // 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 // any left, then this acts as a no-op. -func (db *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error { - openChannels, err := db.fetchOpenChannels(tx, remotePub) +func (d *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error { + openChannels, err := d.fetchOpenChannels(tx, remotePub) if err != nil { return fmt.Errorf("unable to fetch open channels for peer %x: "+ "%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", remotePub.SerializeCompressed()) - return db.deleteLinkNode(tx, remotePub) + return d.deleteLinkNode(tx, remotePub) } // PruneLinkNodes attempts to prune all link nodes found within the databse with // whom we no longer have any open channels with. -func (db *DB) PruneLinkNodes() error { - return db.Update(func(tx *bolt.Tx) error { - linkNodes, err := db.fetchAllLinkNodes(tx) +func (d *DB) PruneLinkNodes() error { + return d.Update(func(tx *bolt.Tx) error { + linkNodes, err := d.fetchAllLinkNodes(tx) if err != nil { return err } for _, linkNode := range linkNodes { - err := db.pruneLinkNode(tx, linkNode.IdentityPub) + err := d.pruneLinkNode(tx, linkNode.IdentityPub) if err != nil { return err } diff --git a/channeldb/graph.go b/channeldb/graph.go index d716ead2..5d96949f 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -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 // each of the nodes. - nodeRefCounts[node1] += 1 - nodeRefCounts[node2] += 1 + nodeRefCounts[node1]++ + nodeRefCounts[node2]++ return nil }) diff --git a/channeldb/nodes.go b/channeldb/nodes.go index 59c67d41..054e88e6 100644 --- a/channeldb/nodes.go +++ b/channeldb/nodes.go @@ -129,13 +129,13 @@ func putLinkNode(nodeMetaBucket *bolt.Bucket, l *LinkNode) error { // DeleteLinkNode removes the link node with the given identity from the // database. -func (d *DB) DeleteLinkNode(identity *btcec.PublicKey) error { - return d.Update(func(tx *bolt.Tx) error { - return d.deleteLinkNode(tx, identity) +func (db *DB) DeleteLinkNode(identity *btcec.PublicKey) error { + return db.Update(func(tx *bolt.Tx) error { + 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) if nodeMetaBucket == nil { return ErrLinkNodesNotFound diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 608023ab..4600c8ff 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -27,8 +27,8 @@ import ( const ( defaultTLSCertFilename = "tls.cert" defaultMacaroonFilename = "admin.macaroon" - defaultRpcPort = "10009" - defaultRpcHostPort = "localhost:" + defaultRpcPort + defaultRPCPort = "10009" + defaultRPCHostPort = "localhost:" + defaultRPCPort ) var ( @@ -150,7 +150,7 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn { // and not just TCP addresses. opts = append( opts, grpc.WithDialer( - lncfg.ClientAddressDialer(defaultRpcPort), + lncfg.ClientAddressDialer(defaultRPCPort), ), ) conn, err := grpc.Dial(ctx.GlobalString("rpcserver"), opts...) @@ -169,7 +169,7 @@ func main() { app.Flags = []cli.Flag{ cli.StringFlag{ Name: "rpcserver", - Value: defaultRpcHostPort, + Value: defaultRPCHostPort, Usage: "host:port of ln daemon", }, cli.StringFlag{ diff --git a/discovery/gossiper.go b/discovery/gossiper.go index faaf1123..f9166683 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -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 // 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 diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 4742def8..b75f3af5 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -40,10 +40,12 @@ const ( // and accepting updates. minCommitFeePerKw = 253 - // DefaultMinLinkFeeUpdateTimeout and DefaultMaxLinkFeeUpdateTimeout - // represent the default timeout bounds in which a link should propose - // to update its commitment fee rate. + // DefaultMinLinkFeeUpdateTimeout represents the minimum interval in + // which a link should propose to update its commitment fee rate. 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 ) diff --git a/lncfg/address.go b/lncfg/address.go index fb4deb77..0dfd6169 100644 --- a/lncfg/address.go +++ b/lncfg/address.go @@ -72,8 +72,8 @@ func ListenOnAddress(addr net.Addr) (net.Listener, error) { return net.Listen(addr.Network(), addr.String()) } -// TlsListenOnAddress creates a TLS listener that listens on the given address. -func TlsListenOnAddress(addr net.Addr, +// TLSListenOnAddress creates a TLS listener that listens on the given address. +func TLSListenOnAddress(addr net.Addr, config *tls.Config) (net.Listener, error) { return tls.Listen(addr.Network(), addr.String(), config) } diff --git a/lnd.go b/lnd.go index 120163af..ac3df4bf 100644 --- a/lnd.go +++ b/lnd.go @@ -360,7 +360,7 @@ func lndMain() error { return err } for _, restEndpoint := range cfg.RESTListeners { - lis, err := lncfg.TlsListenOnAddress(restEndpoint, tlsConf) + lis, err := lncfg.TLSListenOnAddress(restEndpoint, tlsConf) if err != nil { ltndLog.Errorf( "gRPC proxy unable to listen on %s", @@ -761,7 +761,7 @@ func waitForWalletPassword(grpcEndpoints, restEndpoints []net.Addr, srv := &http.Server{Handler: mux} for _, restEndpoint := range restEndpoints { - lis, err := lncfg.TlsListenOnAddress(restEndpoint, tlsConf) + lis, err := lncfg.TLSListenOnAddress(restEndpoint, tlsConf) if err != nil { ltndLog.Errorf( "password gRPC proxy unable to listen on %s", diff --git a/lnd_test.go b/lnd_test.go index 592cd1cd..f70f1b2d 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -3995,7 +3995,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // We'll decode the invoice's payment request to determine which // channels were used as routing hints. - payReq := &lnrpc.PayReqString{resp.PaymentRequest} + payReq := &lnrpc.PayReqString{ + PayReq: resp.PaymentRequest, + } decoded, err = net.Alice.DecodePayReq(ctxb, payReq) if err != nil { predErr = fmt.Errorf("unable to decode payment "+ @@ -10784,7 +10786,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { for i, hop := range route.Hops { if hop.ChanId != hopChanIDs[i] { t.Fatalf("expected chan id %d, got %d", - hop.ChanId) + hopChanIDs[i], hop.ChanId) } } } diff --git a/lntest/node.go b/lntest/node.go index 0deae50d..c3c44590 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -302,8 +302,10 @@ func (hn *HarnessNode) start(lndError chan<- error) error { hex.EncodeToString(hn.PubKey[:logPubKeyBytes])) err := os.Rename(fileName, newFileName) if err != nil { - fmt.Errorf("could not rename %s to %s: %v", - fileName, newFileName, err) + fmt.Printf("could not rename "+ + "%s to %s: %v\n", + fileName, newFileName, + err) } } } @@ -481,7 +483,7 @@ func (hn *HarnessNode) writePidFile() error { 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. func (hn *HarnessNode) ConnectRPC(useMacs bool) (*grpc.ClientConn, error) { // Wait until TLS certificate and admin macaroon are created before diff --git a/lnwallet/channel.go b/lnwallet/channel.go index fc80fd42..4c4cf97e 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -3924,7 +3924,7 @@ func (i *InvalidCommitSigError) Error() string { // error interface. 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 // 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 diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 2aa37c8b..372c96fb 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -2190,7 +2190,6 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver, t.Fatalf("couldn't start bob client: %v", err) } default: - return t.Fatalf("unknown chain driver: %v", backEnd) } diff --git a/lnwire/gossip_timestamp_range.go b/lnwire/gossip_timestamp_range.go index 7aa28532..43c630e6 100644 --- a/lnwire/gossip_timestamp_range.go +++ b/lnwire/gossip_timestamp_range.go @@ -72,7 +72,7 @@ func (g *GossipTimestampRange) MsgType() MessageType { // version. // // This is part of the lnwire.Message interface. -func (c *GossipTimestampRange) MaxPayloadLength(uint32) uint32 { +func (g *GossipTimestampRange) MaxPayloadLength(uint32) uint32 { // 32 + 4 + 4 // // TODO(roasbeef): update to 8 byte timestmaps? diff --git a/rpcserver.go b/rpcserver.go index 698586ed..74ee8275 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2101,12 +2101,20 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error return payIntent, nil } +type paymentIntentResponse struct { + Route *routing.Route + Preimage [32]byte + Err error +} + // 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 // 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 // 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 // payment is successful, the route chosen will be returned. Otherwise, // 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 // routing err. 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 @@ -2167,10 +2177,13 @@ func (r *rpcServer) dispatchPaymentIntent(payIntent *rpcPaymentIntent) (*routing if err != nil { // We weren't able to save the payment, so we return the save // 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 @@ -2283,34 +2296,35 @@ func (r *rpcServer) sendPayment(stream *paymentStream) error { htlcSema <- struct{}{} }() - route, preImage, saveErr, routeErr := r.dispatchPaymentIntent( + resp, saveErr := r.dispatchPaymentIntent( payIntent, ) 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 // payment, then we'll return the error to the // user, and terminate. case saveErr != nil: errChan <- saveErr 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{ - PaymentPreimage: preImage[:], - PaymentRoute: marshallRoute(route), + PaymentPreimage: resp.Preimage[:], + PaymentRoute: marshalledRouted, }) if err != nil { errChan <- err @@ -2385,20 +2399,20 @@ func (r *rpcServer) sendPaymentSync(ctx context.Context, // With the payment validated, we'll now attempt to dispatch the // payment. - route, preImage, saveErr, routeErr := r.dispatchPaymentIntent(&payIntent) + resp, saveErr := r.dispatchPaymentIntent(&payIntent) switch { - case routeErr != nil: - return &lnrpc.SendResponse{ - PaymentError: routeErr.Error(), - }, 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{ - PaymentPreimage: preImage[:], - PaymentRoute: marshallRoute(route), + PaymentPreimage: resp.Preimage[:], + PaymentRoute: marshallRoute(resp.Route), }, nil } diff --git a/server.go b/server.go index 572667ee..f8e5664a 100644 --- a/server.go +++ b/server.go @@ -366,9 +366,9 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, // If we were requested to automatically configure port forwarding, // 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 { - externalIpStrings[idx] = ip.String() + externalIPStrings[idx] = ip.String() } if s.natTraversal != nil { 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 "+ "using %s to advertise external IP", s.natTraversal.Name()) - externalIpStrings = append(externalIpStrings, ips...) + externalIPStrings = append(externalIPStrings, ips...) } } // If external IP addresses have been specified, add those to the list // of this server's addresses. externalIPs, err := lncfg.NormalizeAddresses( - externalIpStrings, strconv.Itoa(defaultPeerPort), + externalIPStrings, strconv.Itoa(defaultPeerPort), cfg.net.ResolveTCPAddr, ) if err != nil { @@ -2593,8 +2593,6 @@ func (s *server) ConnectToPeer(addr *lnwire.NetAddress, perm bool) error { case <-s.quit: return ErrServerShuttingDown } - - return nil } // connectToPeer establishes a connection to a remote peer. errChan is used to