diff --git a/features.go b/features.go index 3e61d3d5..5d0c27fe 100644 --- a/features.go +++ b/features.go @@ -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}, }) diff --git a/fundingmanager.go b/fundingmanager.go index 0e75fab8..0a37056b 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -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 } } diff --git a/htlcswitch.go b/htlcswitch.go index 5520a120..2b1db562 100644 --- a/htlcswitch.go +++ b/htlcswitch.go @@ -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. diff --git a/lnd_test.go b/lnd_test.go index cae397c0..c1335c3a 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -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) } diff --git a/networktest.go b/networktest.go index d831dc07..442f976b 100644 --- a/networktest.go +++ b/networktest.go @@ -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 } diff --git a/peer.go b/peer.go index e43fdfec..85336a48 100644 --- a/peer.go +++ b/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) diff --git a/rpcserver.go b/rpcserver.go index 1f4d4266..5001cec3 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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)} } diff --git a/server.go b/server.go index f12542c5..9c670559 100644 --- a/server.go +++ b/server.go @@ -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{