lnd: fix issues reported by golint+govet

github.com/lightningnetwork/lnd  master ✗

                                           0m ◒
▶ golint
htlcswitch.go:292:4: should replace numUpdates += 1 with numUpdates++
htlcswitch.go:554:6: var onionId should be onionID
htlcswitch.go:629:7: var onionId should be onionID
lnd_test.go:133:1: context.Context should be the first parameter of a
function
lnd_test.go:177:1: context.Context should be the first parameter of a
function
networktest.go:84:2: struct field nodeId should be nodeID
peer.go:1704:16: should omit 2nd value from range; this loop is
equivalent to `for invoice := range ...`
rpcserver.go:57:6: func newRpcServer should be newRPCServer

github.com/lightningnetwork/lnd  master ✗

                                        9m ⚑ ◒  ⍉
▶ go vet
features.go:12: github.com/lightningnetwork/lnd/lnwire.Feature
composite literal uses unkeyed fields
fundingmanager.go:380: no formatting directive in Errorf call
exit status 1
This commit is contained in:
Olaoluwa Osuntokun 2017-02-22 14:49:04 -08:00
parent 6c81dfad61
commit e910b12d33
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
8 changed files with 50 additions and 49 deletions

@ -9,5 +9,5 @@ var globalFeatures = lnwire.NewFeatureVector([]lnwire.Feature{})
// localFeatures is an feature vector which represent the features which
// only affect the protocol between these two nodes.
var localFeatures = lnwire.NewFeatureVector([]lnwire.Feature{
{"lcp-stop-and-wait", lnwire.RequiredFlag},
{Name: "lcp-stop-and-wait", Flag: lnwire.RequiredFlag},
})

@ -377,7 +377,8 @@ func (f *fundingManager) handleFundingRequest(fmsg *fundingRequestMsg) {
PendingChannelID: fmsg.msg.ChannelID,
}
if err := f.cfg.SendToPeer(fmsg.peerAddress.IdentityKey, errMsg); err != nil {
fndgLog.Errorf("unable to send max pending channels message to peer", err)
fndgLog.Errorf("unable to send max pending channels "+
"message to peer: %v", err)
return
}
}

@ -289,7 +289,7 @@ out:
htlcPkt.err <- fmt.Errorf("Insufficient capacity")
case pkt := <-h.htlcPlex:
// TODO(roasbeef): properly account with cleared vs settled
numUpdates += 1
numUpdates++
hswcLog.Tracef("plex packet: %v", newLogClosure(func() string {
return spew.Sdump(pkt)
@ -551,15 +551,15 @@ func (h *htlcSwitch) handleRegisterLink(req *registerLinkMsg) {
// Next, update the onion index which is used to look up the
// settle/clear links during multi-hop payments and to dispatch
// outgoing payments initiated by a local subsystem.
var onionId [ripemd160.Size]byte
copy(onionId[:], btcutil.Hash160(req.peer.addr.IdentityKey.SerializeCompressed()))
var onionID [ripemd160.Size]byte
copy(onionID[:], btcutil.Hash160(req.peer.addr.IdentityKey.SerializeCompressed()))
h.onionMtx.Lock()
h.onionIndex[onionId] = h.interfaces[interfaceID]
h.onionIndex[onionID] = h.interfaces[interfaceID]
h.onionMtx.Unlock()
hswcLog.Infof("registering new link, interface=%x, onion_link=%x, "+
"chan_point=%v, capacity=%v", interfaceID[:], onionId,
"chan_point=%v, capacity=%v", interfaceID[:], onionID,
chanPoint, newLink.capacity)
if req.done != nil {
@ -626,9 +626,9 @@ func (h *htlcSwitch) handleUnregisterLink(req *unregisterLinkMsg) {
// Delete the peer from the onion index so that the
// htlcForwarder knows not to attempt to forward any further
// HTLCs in this direction.
var onionId [ripemd160.Size]byte
copy(onionId[:], btcutil.Hash160(req.remoteID))
delete(h.onionIndex, onionId)
var onionID [ripemd160.Size]byte
copy(onionID[:], btcutil.Hash160(req.remoteID))
delete(h.onionIndex, onionID)
// Finally, delete the interface itself so that outgoing
// payments don't select this path.

@ -130,7 +130,7 @@ func mineBlocks(t *harnessTest, net *networkHarness, num uint32) []*wire.MsgBloc
// after the channel is considered open: the funding transaction should be
// found within a block, and that Alice can report the status of the new
// channel.
func openChannelAndAssert(t *harnessTest, net *networkHarness, ctx context.Context,
func openChannelAndAssert(ctx context.Context, t *harnessTest, net *networkHarness,
alice, bob *lightningNode, fundingAmt btcutil.Amount,
pushAmt btcutil.Amount) *lnrpc.ChannelPoint {
@ -174,7 +174,7 @@ func openChannelAndAssert(t *harnessTest, net *networkHarness, ctx context.Conte
// via timeout from a base parent. Additionally, once the channel has been
// detected as closed, an assertion checks that the transaction is found within
// a block.
func closeChannelAndAssert(t *harnessTest, net *networkHarness, ctx context.Context,
func closeChannelAndAssert(ctx context.Context, t *harnessTest, net *networkHarness,
node *lightningNode, fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash {
closeUpdates, _, err := net.CloseChannel(ctx, node, fundingChanPoint, force)
@ -216,7 +216,7 @@ func testBasicChannelFunding(net *networkHarness, t *harnessTest) {
// assertions will be executed to ensure the funding process completed
// successfully.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPoint := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, pushAmt)
// With then channel open, ensure that the amount specified above has
@ -243,7 +243,7 @@ func testBasicChannelFunding(net *networkHarness, t *harnessTest) {
// block until the channel is closed and will additionally assert the
// relevant channel closing post conditions.
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPoint, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}
// testChannelBalance creates a new channel between Alice and Bob, then
@ -273,7 +273,7 @@ func testChannelBalance(net *networkHarness, t *harnessTest) {
}
}
chanPoint := openChannelAndAssert(t, net, ctx, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctx, t, net, net.Alice, net.Bob,
amount, 0)
// As this is a single funder channel, Alice's balance should be
@ -294,7 +294,7 @@ func testChannelBalance(net *networkHarness, t *harnessTest) {
// Finally close the channel between Alice and Bob, asserting that the
// channel has been properly closed on-chain.
ctx, _ = context.WithTimeout(context.Background(), timeout)
closeChannelAndAssert(t, net, ctx, net.Alice, chanPoint, false)
closeChannelAndAssert(ctx, t, net, net.Alice, chanPoint, false)
}
// testChannelForceClosure performs a test to exercise the behavior of "force"
@ -493,7 +493,7 @@ func testSingleHopInvoice(net *networkHarness, t *harnessTest) {
// the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanAmt := btcutil.Amount(100000)
chanPoint := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, 0)
assertPaymentBalance := func(amt btcutil.Amount) {
@ -629,7 +629,7 @@ func testSingleHopInvoice(net *networkHarness, t *harnessTest) {
assertPaymentBalance(paymentAmt * 2)
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPoint, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}
func testListPayments(net *networkHarness, t *harnessTest) {
@ -658,7 +658,7 @@ func testListPayments(net *networkHarness, t *harnessTest) {
// being the sole funder of the channel.
chanAmt := btcutil.Amount(100000)
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPoint := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, 0)
// Now that the channel is open, create an invoice for Bob which
@ -757,7 +757,7 @@ func testListPayments(net *networkHarness, t *harnessTest) {
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPoint, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}
func testMultiHopPayments(net *networkHarness, t *harnessTest) {
@ -768,7 +768,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPointAlice := openChannelAndAssert(t, net, ctxt, net.Alice,
chanPointAlice := openChannelAndAssert(ctxt, t, net, net.Alice,
net.Bob, chanAmt, 0)
aliceChanTXID, err := chainhash.NewHash(chanPointAlice.FundingTxid)
@ -797,7 +797,7 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) {
t.Fatalf("unable to send coins to carol: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
chanPointCarol := openChannelAndAssert(t, net, ctxt, carol,
chanPointCarol := openChannelAndAssert(ctxt, t, net, carol,
net.Alice, chanAmt, 0)
carolChanTXID, err := chainhash.NewHash(chanPointCarol.FundingTxid)
@ -988,9 +988,9 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) {
assertAsymmetricBalance(carol, carolFundPoint, sourceBal, sinkBal)
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPointAlice, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPointAlice, false)
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, carol, chanPointCarol, false)
closeChannelAndAssert(ctxt, t, net, carol, chanPointCarol, false)
// Finally, shutdown the node we created for the duration of the tests,
// only leaving the two seed nodes (Alice and Bob) within our test
@ -1008,7 +1008,7 @@ func testInvoiceSubscriptions(net *networkHarness, t *harnessTest) {
// Open a channel with 500k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPoint := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, 0)
// Next create a new invoice for Bob requesting 1k satoshis.
@ -1080,7 +1080,7 @@ func testInvoiceSubscriptions(net *networkHarness, t *harnessTest) {
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPoint, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}
// testBasicChannelCreation test multiple channel opening and closing.
@ -1096,7 +1096,7 @@ func testBasicChannelCreation(net *networkHarness, t *harnessTest) {
chanPoints := make([]*lnrpc.ChannelPoint, numChannels)
for i := 0; i < numChannels; i++ {
ctx, _ := context.WithTimeout(context.Background(), timeout)
chanPoints[i] = openChannelAndAssert(t, net, ctx, net.Alice,
chanPoints[i] = openChannelAndAssert(ctx, t, net, net.Alice,
net.Bob, amount, 0)
}
@ -1104,7 +1104,7 @@ func testBasicChannelCreation(net *networkHarness, t *harnessTest) {
// channel has been properly closed on-chain.
for _, chanPoint := range chanPoints {
ctx, _ := context.WithTimeout(context.Background(), timeout)
closeChannelAndAssert(t, net, ctx, net.Alice, chanPoint, false)
closeChannelAndAssert(ctx, t, net, net.Alice, chanPoint, false)
}
}
@ -1206,7 +1206,7 @@ func testMaxPendingChannels(net *networkHarness, t *harnessTest) {
// channel has been properly closed on-chain.
for _, chanPoint := range chanPoints {
ctxt, _ := context.WithTimeout(context.Background(), timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPoint, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
}
// Finally, shutdown the node we created for the duration of the tests,
@ -1251,7 +1251,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) {
// closure by Bob, we'll first open up a channel between them with a
// 0.5 BTC value.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPoint := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, 0)
// With the channel open, we'll create a few invoices for Bob that
@ -1386,7 +1386,7 @@ func testRevokedCloseRetribution(net *networkHarness, t *harnessTest) {
// broadcasting his current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so he'll soon
// feel the wrath of Alice's retribution.
breachTXID := closeChannelAndAssert(t, net, ctxb, net.Bob, chanPoint,
breachTXID := closeChannelAndAssert(ctxb, t, net, net.Bob, chanPoint,
true)
// Query the mempool for Alice's justice transaction, this should be
@ -1470,7 +1470,7 @@ func testHtlcErrorPropagation(net *networkHarness, t *harnessTest) {
// First establish a channel with a capacity of 0.5 BTC between Alice
// and Bob.
ctxt, _ := context.WithTimeout(ctxb, timeout)
chanPointAlice := openChannelAndAssert(t, net, ctxt, net.Alice, net.Bob,
chanPointAlice := openChannelAndAssert(ctxt, t, net, net.Alice, net.Bob,
chanAmt, 0)
assertBaseBalance := func() {
@ -1509,7 +1509,7 @@ func testHtlcErrorPropagation(net *networkHarness, t *harnessTest) {
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
const bobChanAmt = btcutil.Amount(btcutil.SatoshiPerBitcoin / 2)
chanPointBob := openChannelAndAssert(t, net, ctxt, net.Bob, carol,
chanPointBob := openChannelAndAssert(ctxt, t, net, net.Bob, carol,
chanAmt, 0)
// Ensure that Alice has Carol in her routing table before proceeding.
@ -1703,13 +1703,13 @@ out:
// block until the channel is closed and will additionally assert the
// relevant channel closing post conditions.
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Alice, chanPointAlice, false)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPointAlice, false)
// Force close Bob's final channel, also mining enough blocks to
// trigger a sweep of the funds by the utxoNursery.
// TODO(roasbeef): use config value for default CSV here.
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(t, net, ctxt, net.Bob, chanPointBob, true)
closeChannelAndAssert(ctxt, t, net, net.Bob, chanPointBob, true)
if _, err := net.Miner.Node.Generate(5); err != nil {
t.Fatalf("unable to generate blocks: %v", err)
}

@ -81,7 +81,7 @@ type lightningNode struct {
p2pAddr string
rpcCert []byte
nodeId int
nodeID int
// PubKey is the serialized compressed identity public key of the node.
// This field will only be populated once the node itself has been
@ -131,7 +131,7 @@ func newLightningNode(rpcConfig *btcrpcclient.ConnConfig, lndArgs []string) (*li
p2pAddr: net.JoinHostPort("127.0.0.1", strconv.Itoa(cfg.PeerPort)),
rpcAddr: net.JoinHostPort("127.0.0.1", strconv.Itoa(cfg.RPCPort)),
rpcCert: rpcConfig.Certificates,
nodeId: nodeNum,
nodeID: nodeNum,
processExit: make(chan struct{}),
extraArgs: lndArgs,
}, nil
@ -188,7 +188,7 @@ func (l *lightningNode) start(lndError chan error) error {
}()
pid, err := os.Create(filepath.Join(l.cfg.DataDir,
fmt.Sprintf("%v.pid", l.nodeId)))
fmt.Sprintf("%v.pid", l.nodeID)))
if err != nil {
return err
}
@ -358,8 +358,8 @@ func (n *networkHarness) InitializeSeedNodes(r *rpctest.Harness, lndArgs []strin
return err
}
n.activeNodes[n.Alice.nodeId] = n.Alice
n.activeNodes[n.Bob.nodeId] = n.Bob
n.activeNodes[n.Alice.nodeID] = n.Alice
n.activeNodes[n.Bob.nodeID] = n.Bob
return err
}
@ -522,7 +522,7 @@ func (n *networkHarness) NewNode(extraArgs []string) (*lightningNode, error) {
return nil, err
}
n.activeNodes[node.nodeId] = node
n.activeNodes[node.nodeID] = node
return node, nil
}

10
peer.go

@ -13,6 +13,7 @@ import (
"github.com/btcsuite/fastsha256"
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnrpc"
@ -24,7 +25,6 @@ import (
"github.com/roasbeef/btcd/txscript"
"github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil"
"github.com/go-errors/errors"
)
var (
@ -154,7 +154,7 @@ type peer struct {
// localSharedFeatures is a product of comparison of our and their
// local features vectors which consist of features which are present
// on both sides.
localSharedFeatures *lnwire.SharedFeatures
localSharedFeatures *lnwire.SharedFeatures
// globalSharedFeatures is a product of comparison of our and their
// global features vectors which consist of features which are present
@ -1252,7 +1252,7 @@ out:
func (p *peer) handleInitMsg(msg *lnwire.Init) error {
localSharedFeatures, err := p.server.localFeatures.Compare(msg.LocalFeatures)
if err != nil {
err := errors.Errorf("can compare remote and local feature " +
err := errors.Errorf("can compare remote and local feature "+
"vectors: %v", err)
peerLog.Error(err)
return err
@ -1261,7 +1261,7 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
globalSharedFeatures, err := p.server.globalFeatures.Compare(msg.GlobalFeatures)
if err != nil {
err := errors.Errorf("can compare remote and global feature " +
err := errors.Errorf("can compare remote and global feature "+
"vectors: %v", err)
peerLog.Error(err)
return err
@ -1702,7 +1702,7 @@ func (p *peer) handleUpstreamMsg(state *commitmentState, msg lnwire.Message) {
// Notify the invoiceRegistry of the invoices we just settled
// with this latest commitment update.
// TODO(roasbeef): wait until next transition?
for invoice, _ := range settledPayments {
for invoice := range settledPayments {
err := p.server.invoices.SettleInvoice(chainhash.Hash(invoice))
if err != nil {
peerLog.Errorf("unable to settle invoice: %v", err)

@ -53,8 +53,8 @@ type rpcServer struct {
// LightningServer gRPC service.
var _ lnrpc.LightningServer = (*rpcServer)(nil)
// newRpcServer creates and returns a new instance of the rpcServer.
func newRpcServer(s *server) *rpcServer {
// newRPCServer creates and returns a new instance of the rpcServer.
func newRPCServer(s *server) *rpcServer {
return &rpcServer{server: s, quit: make(chan struct{}, 1)}
}

@ -194,7 +194,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
return nil, err
}
s.rpcServer = newRpcServer(s)
s.rpcServer = newRPCServer(s)
s.breachArbiter = newBreachArbiter(wallet, chanDB, notifier, s.htlcSwitch)
s.fundingMgr, err = newFundingManager(fundingConfig{