lnd: fix golint warning which requires to add additional comments

This commit is contained in:
Andrey Samokhvalov 2017-02-24 16:32:33 +03:00 committed by Olaoluwa Osuntokun
parent 0074643c10
commit ee2379775c
9 changed files with 135 additions and 70 deletions

View File

@ -37,6 +37,8 @@ const (
) )
var ( var (
// ErrMaxMessageLengthExceeded is returned a message to be written to
// the cipher session exceeds the maximum allowed message payload.
ErrMaxMessageLengthExceeded = errors.New("the generated payload exceeds " + ErrMaxMessageLengthExceeded = errors.New("the generated payload exceeds " +
"the max allowed message length of (2^16)-1") "the max allowed message length of (2^16)-1")
) )

View File

@ -23,6 +23,8 @@ const (
) )
var ( var (
// ErrChainNotifierShuttingDown is used when we are trying to
// measure a spend notification when notifier is already stopped.
ErrChainNotifierShuttingDown = errors.New("chainntnfs: system interrupt " + ErrChainNotifierShuttingDown = errors.New("chainntnfs: system interrupt " +
"while attempting to register for spend notification.") "while attempting to register for spend notification.")
) )

View File

@ -3,31 +3,74 @@ package channeldb
import "fmt" import "fmt"
var ( var (
ErrNoChanDBExists = fmt.Errorf("channel db has not yet been created") // ErrNoChanDBExists is returned when a channel bucket hasn't been
// created.
ErrNoChanDBExists = fmt.Errorf("channel db has not yet been created")
// ErrLinkNodesNotFound is returned when node info bucket hasn't been
// created.
ErrLinkNodesNotFound = fmt.Errorf("no link nodes exist") ErrLinkNodesNotFound = fmt.Errorf("no link nodes exist")
// ErrNoActiveChannels is returned when there is no active (open)
// channels within the database.
ErrNoActiveChannels = fmt.Errorf("no active channels exist") ErrNoActiveChannels = fmt.Errorf("no active channels exist")
ErrChannelNoExist = fmt.Errorf("this channel does not exist")
ErrNoPastDeltas = fmt.Errorf("channel has no recorded deltas")
ErrInvoiceNotFound = fmt.Errorf("unable to locate invoice") // ErrNoPastDeltas is returned when the channel delta bucket hasn't been
// created.
ErrNoPastDeltas = fmt.Errorf("channel has no recorded deltas")
// ErrInvoiceNotFound is returned when a targeted invoice can't be
// found.
ErrInvoiceNotFound = fmt.Errorf("unable to locate invoice")
// ErrNoInvoicesCreated is returned when we don't have invoices in
// our database to return.
ErrNoInvoicesCreated = fmt.Errorf("there are no existing invoices") ErrNoInvoicesCreated = fmt.Errorf("there are no existing invoices")
ErrDuplicateInvoice = fmt.Errorf("invoice with payment hash already exists")
// ErrDuplicateInvoice is returned when an invoice with the target
// payment hash already exists.
ErrDuplicateInvoice = fmt.Errorf("invoice with payment hash already exists")
// ErrNoPaymentsCreated is returned when bucket of payments hasn't been
// created.
ErrNoPaymentsCreated = fmt.Errorf("there are no existing payments") ErrNoPaymentsCreated = fmt.Errorf("there are no existing payments")
// ErrNodeNotFound is returned when node bucket exists, but node with
// specific identity can't be found.
ErrNodeNotFound = fmt.Errorf("link node with target identity not found") ErrNodeNotFound = fmt.Errorf("link node with target identity not found")
// ErrMetaNotFound is returned when meta bucket hasn't been
// created.
ErrMetaNotFound = fmt.Errorf("unable to locate meta information") ErrMetaNotFound = fmt.Errorf("unable to locate meta information")
ErrGraphNotFound = fmt.Errorf("graph bucket not initialized") // ErrGraphNotFound is returned when at least one of the components of
ErrGraphNodesNotFound = fmt.Errorf("no graph nodes exist") // graph doesn't exist.
ErrGraphNoEdgesFound = fmt.Errorf("no graph edges exist") ErrGraphNotFound = fmt.Errorf("graph bucket not initialized")
ErrGraphNodeNotFound = fmt.Errorf("unable to find node")
ErrGraphNeverPruned = fmt.Errorf("graph never pruned")
// ErrGraphNeverPruned is returned when graph was never pruned.
ErrGraphNeverPruned = fmt.Errorf("graph never pruned")
// ErrSourceNodeNotSet is returned if the the source node of the graph
// hasn't been added The source node is the center node within a
// star-graph.
ErrSourceNodeNotSet = fmt.Errorf("source node does not exist")
// ErrGraphNodesNotFound is returned in case none of the nodes has
// been added in graph node bucket.
ErrGraphNodesNotFound = fmt.Errorf("no graph nodes exist")
// ErrGraphNoEdgesFound is returned in case of none of the channel/edges
// has been added in graph edge bucket.
ErrGraphNoEdgesFound = fmt.Errorf("no graph edges exist")
// ErrGraphNodeNotFound is returned when we're unable to find the target
// node.
ErrGraphNodeNotFound = fmt.Errorf("unable to find node")
// ErrEdgeNotFound is returned when an edge for the target chanID
// can't be found.
ErrEdgeNotFound = fmt.Errorf("edge for chanID not found") ErrEdgeNotFound = fmt.Errorf("edge for chanID not found")
// ErrNodeAliasNotFound is returned when alias for node can't be found.
ErrNodeAliasNotFound = fmt.Errorf("alias for node not found") ErrNodeAliasNotFound = fmt.Errorf("alias for node not found")
ErrSourceNodeNotSet = fmt.Errorf("source node does not exist")
) )

View File

@ -166,11 +166,11 @@ func (d *DB) LookupInvoice(paymentHash [32]byte) (*Invoice, error) {
err := d.View(func(tx *bolt.Tx) error { err := d.View(func(tx *bolt.Tx) error {
invoices := tx.Bucket(invoiceBucket) invoices := tx.Bucket(invoiceBucket)
if invoices == nil { if invoices == nil {
return ErrInvoiceNotFound return ErrNoInvoicesCreated
} }
invoiceIndex := invoices.Bucket(invoiceIndexBucket) invoiceIndex := invoices.Bucket(invoiceIndexBucket)
if invoiceIndex == nil { if invoiceIndex == nil {
return ErrInvoiceNotFound return ErrNoInvoicesCreated
} }
// Check the invoice index to see if an invoice paying to this // Check the invoice index to see if an invoice paying to this

View File

@ -52,7 +52,7 @@ func printRespJSON(resp proto.Message) {
fmt.Println(jsonStr) fmt.Println(jsonStr)
} }
var NewAddressCommand = cli.Command{ var newAddressCommand = cli.Command{
Name: "newaddress", Name: "newaddress",
Usage: "generates a new address.", Usage: "generates a new address.",
ArgsUsage: "address-type", ArgsUsage: "address-type",
@ -96,7 +96,7 @@ func newAddress(ctx *cli.Context) error {
return nil return nil
} }
var SendCoinsCommand = cli.Command{ var sendCoinsCommand = cli.Command{
Name: "sendcoins", Name: "sendcoins",
Usage: "send bitcoin on-chain to an address", Usage: "send bitcoin on-chain to an address",
ArgsUsage: "addr amt", ArgsUsage: "addr amt",
@ -169,7 +169,7 @@ func sendCoins(ctx *cli.Context) error {
return nil return nil
} }
var SendManyCommand = cli.Command{ var sendManyCommand = cli.Command{
Name: "sendmany", Name: "sendmany",
Usage: "send bitcoin on-chain to multiple addresses.", Usage: "send bitcoin on-chain to multiple addresses.",
ArgsUsage: "send-json-string", ArgsUsage: "send-json-string",
@ -204,7 +204,7 @@ func sendMany(ctx *cli.Context) error {
return nil return nil
} }
var ConnectCommand = cli.Command{ var connectCommand = cli.Command{
Name: "connect", Name: "connect",
Usage: "connect to a remote lnd peer", Usage: "connect to a remote lnd peer",
ArgsUsage: "<pubkey>@host", ArgsUsage: "<pubkey>@host",
@ -250,7 +250,7 @@ func connectPeer(ctx *cli.Context) error {
} }
// TODO(roasbeef): change default number of confirmations // TODO(roasbeef): change default number of confirmations
var OpenChannelCommand = cli.Command{ var openChannelCommand = cli.Command{
Name: "openchannel", Name: "openchannel",
Usage: "Open a channel to an existing peer.", Usage: "Open a channel to an existing peer.",
Description: "Attempt to open a new channel to an existing peer with the key node-key, " + Description: "Attempt to open a new channel to an existing peer with the key node-key, " +
@ -411,7 +411,7 @@ func openChannel(ctx *cli.Context) error {
// TODO(roasbeef): also allow short relative channel ID. // TODO(roasbeef): also allow short relative channel ID.
var CloseChannelCommand = cli.Command{ var closeChannelCommand = cli.Command{
Name: "closechannel", Name: "closechannel",
Usage: "Close an existing channel.", Usage: "Close an existing channel.",
Description: "Close an existing channel. The channel can be closed either " + Description: "Close an existing channel. The channel can be closed either " +
@ -544,7 +544,7 @@ func closeChannel(ctx *cli.Context) error {
} }
} }
var ListPeersCommand = cli.Command{ var listPeersCommand = cli.Command{
Name: "listpeers", Name: "listpeers",
Usage: "List all active, currently connected peers.", Usage: "List all active, currently connected peers.",
Action: listPeers, Action: listPeers,
@ -565,7 +565,7 @@ func listPeers(ctx *cli.Context) error {
return nil return nil
} }
var WalletBalanceCommand = cli.Command{ var walletBalanceCommand = cli.Command{
Name: "walletbalance", Name: "walletbalance",
Usage: "compute and display the wallet's current balance", Usage: "compute and display the wallet's current balance",
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -595,7 +595,7 @@ func walletBalance(ctx *cli.Context) error {
return nil return nil
} }
var ChannelBalanceCommand = cli.Command{ var channelBalanceCommand = cli.Command{
Name: "channelbalance", Name: "channelbalance",
Usage: "returns the sum of the total available channel balance across all open channels", Usage: "returns the sum of the total available channel balance across all open channels",
Action: channelBalance, Action: channelBalance,
@ -616,7 +616,7 @@ func channelBalance(ctx *cli.Context) error {
return nil return nil
} }
var GetInfoCommand = cli.Command{ var getInfoCommand = cli.Command{
Name: "getinfo", Name: "getinfo",
Usage: "returns basic information related to the active daemon", Usage: "returns basic information related to the active daemon",
Action: getInfo, Action: getInfo,
@ -637,7 +637,7 @@ func getInfo(ctx *cli.Context) error {
return nil return nil
} }
var PendingChannelsCommand = cli.Command{ var pendingChannelsCommand = cli.Command{
Name: "pendingchannels", Name: "pendingchannels",
Usage: "display information pertaining to pending channels", Usage: "display information pertaining to pending channels",
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -686,7 +686,7 @@ func pendingChannels(ctx *cli.Context) error {
return nil return nil
} }
var ListChannelsCommand = cli.Command{ var listChannelsCommand = cli.Command{
Name: "listchannels", Name: "listchannels",
Usage: "list all open channels", Usage: "list all open channels",
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -716,7 +716,7 @@ func listChannels(ctx *cli.Context) error {
return nil return nil
} }
var SendPaymentCommand = cli.Command{ var sendPaymentCommand = cli.Command{
Name: "sendpayment", Name: "sendpayment",
Usage: "send a payment over lightning", Usage: "send a payment over lightning",
ArgsUsage: "(destination amount payment_hash " + ArgsUsage: "(destination amount payment_hash " +
@ -744,10 +744,10 @@ var SendPaymentCommand = cli.Command{
Usage: "a zbase32-check encoded payment request to fulfill", Usage: "a zbase32-check encoded payment request to fulfill",
}, },
}, },
Action: sendPaymentCommand, Action: sendPayment,
} }
func sendPaymentCommand(ctx *cli.Context) error { func sendPayment(ctx *cli.Context) error {
client, cleanUp := getClient(ctx) client, cleanUp := getClient(ctx)
defer cleanUp() defer cleanUp()
@ -856,7 +856,7 @@ func sendPaymentCommand(ctx *cli.Context) error {
return nil return nil
} }
var AddInvoiceCommand = cli.Command{ var addInvoiceCommand = cli.Command{
Name: "addinvoice", Name: "addinvoice",
Usage: "add a new invoice.", Usage: "add a new invoice.",
Description: "Add a new invoice, expressing intent for a future payment. " + Description: "Add a new invoice, expressing intent for a future payment. " +
@ -948,7 +948,7 @@ func addInvoice(ctx *cli.Context) error {
return nil return nil
} }
var LookupInvoiceCommand = cli.Command{ var lookupInvoiceCommand = cli.Command{
Name: "lookupinvoice", Name: "lookupinvoice",
Usage: "Lookup an existing invoice by its payment hash.", Usage: "Lookup an existing invoice by its payment hash.",
ArgsUsage: "rhash", ArgsUsage: "rhash",
@ -998,7 +998,7 @@ func lookupInvoice(ctx *cli.Context) error {
return nil return nil
} }
var ListInvoicesCommand = cli.Command{ var listInvoicesCommand = cli.Command{
Name: "listinvoices", Name: "listinvoices",
Usage: "List all invoices currently stored.", Usage: "List all invoices currently stored.",
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -1034,7 +1034,7 @@ func listInvoices(ctx *cli.Context) error {
return nil return nil
} }
var DescribeGraphCommand = cli.Command{ var describeGraphCommand = cli.Command{
Name: "describegraph", Name: "describegraph",
Description: "prints a human readable version of the known channel " + Description: "prints a human readable version of the known channel " +
"graph from the PoV of the node", "graph from the PoV of the node",
@ -1217,7 +1217,7 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error {
return nil return nil
} }
var ListPaymentsCommand = cli.Command{ var listPaymentsCommand = cli.Command{
Name: "listpayments", Name: "listpayments",
Usage: "list all outgoing payments", Usage: "list all outgoing payments",
Action: listPayments, Action: listPayments,
@ -1238,7 +1238,7 @@ func listPayments(ctx *cli.Context) error {
return nil return nil
} }
var GetChanInfoCommand = cli.Command{ var getChanInfoCommand = cli.Command{
Name: "getchaninfo", Name: "getchaninfo",
Usage: "get the state of a channel", Usage: "get the state of a channel",
Description: "prints out the latest authenticated state for a " + Description: "prints out the latest authenticated state for a " +
@ -1285,7 +1285,7 @@ func getChanInfo(ctx *cli.Context) error {
return nil return nil
} }
var GetNodeInfoCommand = cli.Command{ var getNodeInfoCommand = cli.Command{
Name: "getnodeinfo", Name: "getnodeinfo",
Usage: "Get information on a specific node.", Usage: "Get information on a specific node.",
Description: "prints out the latest authenticated node state for an " + Description: "prints out the latest authenticated node state for an " +
@ -1322,7 +1322,7 @@ func getNodeInfo(ctx *cli.Context) error {
return nil return nil
} }
var QueryRouteCommand = cli.Command{ var queryRouteCommand = cli.Command{
Name: "queryroute", Name: "queryroute",
Usage: "Query a route to a destination.", Usage: "Query a route to a destination.",
Description: "Queries the channel router for a potential path to the destination that has sufficient flow for the amount including fees", Description: "Queries the channel router for a potential path to the destination that has sufficient flow for the amount including fees",
@ -1390,7 +1390,7 @@ func queryRoute(ctx *cli.Context) error {
return nil return nil
} }
var GetNetworkInfoCommand = cli.Command{ var getNetworkInfoCommand = cli.Command{
Name: "getnetworkinfo", Name: "getnetworkinfo",
Usage: "getnetworkinfo", Usage: "getnetworkinfo",
Description: "returns a set of statistics pertaining to the known channel " + Description: "returns a set of statistics pertaining to the known channel " +
@ -1414,7 +1414,7 @@ func getNetworkInfo(ctx *cli.Context) error {
return nil return nil
} }
var DebugLevel = cli.Command{ var debugLevelCommand = cli.Command{
Name: "debuglevel", Name: "debuglevel",
Usage: "Set the debug level.", Usage: "Set the debug level.",
Description: "Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems", Description: "Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems",
@ -1450,7 +1450,7 @@ func debugLevel(ctx *cli.Context) error {
return nil return nil
} }
var DecodePayReq = cli.Command{ var decodePayReqComamnd = cli.Command{
Name: "decodepayreq", Name: "decodepayreq",
Usage: "Decode a payment request.", Usage: "Decode a payment request.",
Description: "Decode the passed payment request revealing the destination, payment hash and value of the payment request", Description: "Decode the passed payment request revealing the destination, payment hash and value of the payment request",

View File

@ -53,30 +53,30 @@ func main() {
}, },
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
NewAddressCommand, newAddressCommand,
SendManyCommand, sendManyCommand,
SendCoinsCommand, sendCoinsCommand,
ConnectCommand, connectCommand,
OpenChannelCommand, openChannelCommand,
CloseChannelCommand, closeChannelCommand,
ListPeersCommand, listPeersCommand,
WalletBalanceCommand, walletBalanceCommand,
ChannelBalanceCommand, channelBalanceCommand,
GetInfoCommand, getInfoCommand,
PendingChannelsCommand, pendingChannelsCommand,
SendPaymentCommand, sendPaymentCommand,
AddInvoiceCommand, addInvoiceCommand,
LookupInvoiceCommand, lookupInvoiceCommand,
ListInvoicesCommand, listInvoicesCommand,
ListChannelsCommand, listChannelsCommand,
ListPaymentsCommand, listPaymentsCommand,
DescribeGraphCommand, describeGraphCommand,
GetChanInfoCommand, getChanInfoCommand,
GetNodeInfoCommand, getNodeInfoCommand,
QueryRouteCommand, queryRouteCommand,
GetNetworkInfoCommand, getNetworkInfoCommand,
DebugLevel, debugLevelCommand,
DecodePayReq, decodePayReqComamnd,
ListChainTxns, ListChainTxns,
} }

View File

@ -7,7 +7,10 @@ import (
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
// TODO(roasbeef) add comment which justifying this import. // This is required to register bdb as a valid walletdb driver. In the
// init function of the package, it registers itself. The import is used
// to activate the side effects w/o actually binding the package name to
// a file-level variable.
_ "github.com/roasbeef/btcwallet/walletdb/bdb" _ "github.com/roasbeef/btcwallet/walletdb/bdb"
) )

View File

@ -25,11 +25,23 @@ import (
var zeroHash chainhash.Hash var zeroHash chainhash.Hash
var ( var (
// ErrChanClosing is returned when a caller attempts to close a channel
// that has already been closed or is in the process of being closed.
ErrChanClosing = fmt.Errorf("channel is being closed, operation disallowed") ErrChanClosing = fmt.Errorf("channel is being closed, operation disallowed")
ErrNoWindow = fmt.Errorf("unable to sign new commitment, the current" +
// ErrNoWindow is returned when revocation window is exausted.
ErrNoWindow = fmt.Errorf("unable to sign new commitment, the current" +
" revocation window is exhausted") " revocation window is exhausted")
// ErrMaxWeightCost is returned when the cost/weight (see segwit)
// exceeds the widely used maximum allowed policy weight limit. In this
// case the commitment transaction can't be propagated through the
// network.
ErrMaxWeightCost = fmt.Errorf("commitment transaction exceed max " + ErrMaxWeightCost = fmt.Errorf("commitment transaction exceed max " +
"available weight") "available cost")
// ErrMaxHTLCNumber is returned when a proposed HTLC would exceed the
// maximum number of allowed HTLC's if committed in a state transition
ErrMaxHTLCNumber = fmt.Errorf("commitment transaction exceed max " + ErrMaxHTLCNumber = fmt.Errorf("commitment transaction exceed max " +
"htlc number") "htlc number")
) )
@ -1793,7 +1805,7 @@ func (lc *LightningChannel) ExtendRevocationWindow() (*lnwire.RevokeAndAck, erro
return revMsg, nil return revMsg, nil
} }
// NextRevocationKey returns the revocation key for the _next_ commitment // NextRevocationkey returns the revocation key for the _next_ commitment
// height. The pubkey returned by this function is required by the remote party // height. The pubkey returned by this function is required by the remote party
// to extend our commitment chain with a new commitment. // to extend our commitment chain with a new commitment.
// //

View File

@ -21,8 +21,11 @@ var (
// TODO(roasbeef): remove these and use the one's defined in txscript // TODO(roasbeef): remove these and use the one's defined in txscript
// within testnet-L. // within testnet-L.
SequenceLockTimeSeconds = uint32(1 << 22) // SequenceLockTimeSeconds is the 22nd bit which indicates the lock
OP_CHECKSEQUENCEVERIFY byte = txscript.OP_NOP3 // time is in seconds.
SequenceLockTimeSeconds = uint32(1 << 22)
OP_CHECKSEQUENCEVERIFY byte = txscript.OP_NOP3
// TimelockShift is used to make sure the commitment transaction is // TimelockShift is used to make sure the commitment transaction is
// spendable by setting the locktime with it so that it is larger than // spendable by setting the locktime with it so that it is larger than