diff --git a/aezeed/cipherseed.go b/aezeed/cipherseed.go index 15356722..5898eadd 100644 --- a/aezeed/cipherseed.go +++ b/aezeed/cipherseed.go @@ -102,10 +102,6 @@ const ( // checkSumSize is the index within an enciphered cipher seed that // marks the start of the checksum. checkSumOffset = EncipheredCipherSeedSize - checkSumSize - - // encipheredSeedSize is the size of the cipherseed before applying the - // external version, salt, and checksum for the final encoding. - encipheredSeedSize = DecipheredCipherSeedSize + CipherTextExpansion ) var ( diff --git a/autopilot/choice_test.go b/autopilot/choice_test.go index d984d1b4..850b4440 100644 --- a/autopilot/choice_test.go +++ b/autopilot/choice_test.go @@ -8,13 +8,6 @@ import ( "testing/quick" ) -var ( - nID1 = NodeID([33]byte{1}) - nID2 = NodeID([33]byte{2}) - nID3 = NodeID([33]byte{3}) - nID4 = NodeID([33]byte{4}) -) - // TestWeightedChoiceEmptyMap tests that passing in an empty slice of weights // returns an error. func TestWeightedChoiceEmptyMap(t *testing.T) { @@ -95,7 +88,6 @@ type nonNegative []float64 // Generate generates a value of type nonNegative to be used during // QuickTests. func (nonNegative) Generate(rand *rand.Rand, size int) reflect.Value { - const precision = 100 w := make([]float64, size) for i := range w { diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index f987d70e..a680fffa 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -74,10 +74,6 @@ var chanGraphs = []struct { // TestPrefAttachmentSelectEmptyGraph ensures that when passed an // empty graph, the NodeSores function always returns a score of 0. func TestPrefAttachmentSelectEmptyGraph(t *testing.T) { - const ( - maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin) - ) - prefAttach := NewPrefAttachment() // Create a random public key, which we will query to get a score for. @@ -123,47 +119,6 @@ func TestPrefAttachmentSelectEmptyGraph(t *testing.T) { } } -// completeGraph is a helper method that adds numNodes fully connected nodes to -// the graph. -func completeGraph(t *testing.T, g testGraph, numNodes int) { - const chanCapacity = btcutil.SatoshiPerBitcoin - nodes := make(map[int]*btcec.PublicKey) - for i := 0; i < numNodes; i++ { - for j := i + 1; j < numNodes; j++ { - - node1 := nodes[i] - node2 := nodes[j] - edge1, edge2, err := g.addRandChannel( - node1, node2, chanCapacity) - if err != nil { - t.Fatalf("unable to generate channel: %v", err) - } - - if node1 == nil { - pubKeyBytes := edge1.Peer.PubKey() - nodes[i], err = btcec.ParsePubKey( - pubKeyBytes[:], btcec.S256(), - ) - if err != nil { - t.Fatalf("unable to parse pubkey: %v", - err) - } - } - - if node2 == nil { - pubKeyBytes := edge2.Peer.PubKey() - nodes[j], err = btcec.ParsePubKey( - pubKeyBytes[:], btcec.S256(), - ) - if err != nil { - t.Fatalf("unable to parse pubkey: %v", - err) - } - } - } - } -} - // TestPrefAttachmentSelectTwoVertexes ensures that when passed a // graph with only two eligible vertexes, then both are given the same score, // and the funds are appropriately allocated across each peer. diff --git a/breacharbiter_test.go b/breacharbiter_test.go index d9738409..ac538672 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1982,19 +1982,3 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error { return nil } - -// calcStaticFee calculates appropriate fees for commitment transactions. This -// function provides a simple way to allow test balance assertions to take fee -// calculations into account. -// -// TODO(bvu): Refactor when dynamic fee estimation is added. -// TODO(conner) remove code duplication -func calcStaticFee(numHTLCs int) btcutil.Amount { - const ( - commitWeight = btcutil.Amount(724) - htlcWeight = 172 - feePerKw = btcutil.Amount(24/4) * 1000 - ) - return feePerKw * (commitWeight + - btcutil.Amount(htlcWeight*numHTLCs)) / 1000 -} diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index f9fbfaf6..b353688f 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -23,14 +23,6 @@ const ( notifierType = "bitcoind" ) -// chainUpdate encapsulates an update to the current main chain. This struct is -// used as an element within an unbounded queue in order to avoid blocking the -// main rpc dispatch rule. -type chainUpdate struct { - blockHash *chainhash.Hash - blockHeight int32 -} - // TODO(roasbeef): generalize struct below: // * move chans to config // * extract common code @@ -166,13 +158,6 @@ func (b *BitcoindNotifier) Stop() error { return nil } -// blockNtfn packages a notification of a connected/disconnected block along -// with its height at the time. -type blockNtfn struct { - sha *chainhash.Hash - height int32 -} - // notificationDispatcher is the primary goroutine which handles client // notification registrations, as well as notification dispatches. func (b *BitcoindNotifier) notificationDispatcher() { diff --git a/chainntnfs/height_hint_cache.go b/chainntnfs/height_hint_cache.go index bfd0b574..25a92479 100644 --- a/chainntnfs/height_hint_cache.go +++ b/chainntnfs/height_hint_cache.go @@ -8,15 +8,6 @@ import ( "github.com/lightningnetwork/lnd/channeldb" ) -const ( - // dbName is the default name of the database storing the height hints. - dbName = "heighthint.db" - - // dbFilePermission is the default permission of the database file - // storing the height hints. - dbFilePermission = 0600 -) - var ( // spendHintBucket is the name of the bucket which houses the height // hint for outpoints. Each height hint represents the earliest height diff --git a/chainntnfs/txnotifier_test.go b/chainntnfs/txnotifier_test.go index 79dc735a..e7f9664d 100644 --- a/chainntnfs/txnotifier_test.go +++ b/chainntnfs/txnotifier_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/lightningnetwork/lnd/chainntnfs" @@ -33,7 +32,6 @@ var ( 0x86, 0xf4, 0xcb, 0xf9, 0x8e, 0xae, 0xd2, 0x21, 0xb3, 0x0b, 0xd9, 0xa0, 0xb9, 0x28, } - testScript, _ = txscript.ParsePkScript(testRawScript) ) type mockHintCache struct { diff --git a/channeldb/channel.go b/channeldb/channel.go index 77bcebba..2b1ec949 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -2298,23 +2298,6 @@ func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error { return nil } -func fetchChannelCloseSummary(tx *bbolt.Tx, - chanID []byte) (*ChannelCloseSummary, error) { - - closedChanBucket, err := tx.CreateBucketIfNotExists(closedChannelBucket) - if err != nil { - return nil, err - } - - summaryBytes := closedChanBucket.Get(chanID) - if summaryBytes == nil { - return nil, fmt.Errorf("closed channel summary not found") - } - - summaryReader := bytes.NewReader(summaryBytes) - return deserializeCloseChannelSummary(summaryReader) -} - func deserializeCloseChannelSummary(r io.Reader) (*ChannelCloseSummary, error) { c := &ChannelCloseSummary{} @@ -2679,13 +2662,6 @@ func makeLogKey(updateNum uint64) [8]byte { return key } -// readLogKey parse the first 8- bytes of a byte slice into a uint64. -// -// NOTE: The slice must be at least 8 bytes long. -func readLogKey(b []byte) uint64 { - return byteOrder.Uint64(b) -} - func appendChannelLogEntry(log *bbolt.Bucket, commit *ChannelCommitment) error { diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 4bc11624..770f6f35 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" @@ -23,23 +22,12 @@ import ( ) var ( - netParams = &chaincfg.TestNet3Params - key = [chainhash.HashSize]byte{ 0x81, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, 0x68, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, 0xd, 0xe7, 0x93, 0xe4, 0xb7, 0x25, 0xb8, 0x4d, 0x1e, 0xb, 0x4c, 0xf9, 0x9e, 0xc5, 0x8c, 0xe9, } - id = &wire.OutPoint{ - Hash: [chainhash.HashSize]byte{ - 0x51, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, - 0x48, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, - 0x2d, 0xe7, 0x93, 0xe4, 0xb7, 0x25, 0xb8, 0x4d, - 0x1f, 0xb, 0x4c, 0xf9, 0x9e, 0xc5, 0x8c, 0xe9, - }, - Index: 9, - } rev = [chainhash.HashSize]byte{ 0x51, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, 0x48, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, @@ -77,10 +65,6 @@ var ( }, LockTime: 5, } - testOutpoint = &wire.OutPoint{ - Hash: key, - Index: 0, - } privKey, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), key[:]) wireSig, _ = lnwire.NewSigFromSignature(testSig) diff --git a/channeldb/codec.go b/channeldb/codec.go index 50887933..e693739b 100644 --- a/channeldb/codec.go +++ b/channeldb/codec.go @@ -15,9 +15,6 @@ import ( "github.com/lightningnetwork/lnd/shachain" ) -// outPointSize is the size of a serialized outpoint on disk. -const outPointSize = 36 - // writeOutpoint writes an outpoint to the passed writer using the minimal // amount of bytes possible. func writeOutpoint(w io.Writer, o *wire.OutPoint) error { diff --git a/channeldb/forwarding_package.go b/channeldb/forwarding_package.go index a4de4e26..4808c55c 100644 --- a/channeldb/forwarding_package.go +++ b/channeldb/forwarding_package.go @@ -919,11 +919,6 @@ func uint16Key(i uint16) []byte { return key } -// uint16FromKey reconstructs a 16-bit unsigned integer from a 2-byte slice. -func uint16FromKey(key []byte) uint16 { - return byteOrder.Uint16(key) -} - // Compile-time constraint to ensure that ChannelPackager implements the public // FwdPackager interface. var _ FwdPackager = (*ChannelPackager)(nil) diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index 237f32fb..5068228f 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -29,9 +29,7 @@ var ( "[2001:db8:85a3:0:0:8a2e:370:7334]:80") testAddrs = []net.Addr{testAddr, anotherAddr} - randSource = prand.NewSource(time.Now().Unix()) - randInts = prand.New(randSource) - testSig = &btcec.Signature{ + testSig = &btcec.Signature{ R: new(big.Int), S: new(big.Int), } diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 01a31b9d..4106fced 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -101,14 +101,6 @@ func makeFakeInfo() (*PaymentCreationInfo, *PaymentAttemptInfo) { return c, a } -func makeFakePaymentHash() [32]byte { - var paymentHash [32]byte - rBytes, _ := randomBytes(0, 32) - copy(paymentHash[:], rBytes) - - return paymentHash -} - // randomBytes creates random []byte with length in range [minLen, maxLen) func randomBytes(minLen, maxLen int) ([]byte, error) { randBuf := make([]byte, minLen+rand.Intn(maxLen-minLen)) diff --git a/channelnotifier/log.go b/channelnotifier/log.go index f44bb9b2..009129ab 100644 --- a/channelnotifier/log.go +++ b/channelnotifier/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 22d0e35b..bb8b362a 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -2818,37 +2818,6 @@ func describeGraph(ctx *cli.Context) error { return nil } -// normalizeFunc is a factory function which returns a function that normalizes -// the capacity of edges within the graph. The value of the returned -// function can be used to either plot the capacities, or to use a weight in a -// rendering of the graph. -func normalizeFunc(edges []*lnrpc.ChannelEdge, scaleFactor float64) func(int64) float64 { - var ( - min float64 = math.MaxInt64 - max float64 - ) - - for _, edge := range edges { - // In order to obtain saner values, we reduce the capacity of a - // channel to its base 2 logarithm. - z := math.Log2(float64(edge.Capacity)) - - if z < min { - min = z - } - if z > max { - max = z - } - } - - return func(x int64) float64 { - y := math.Log2(float64(x)) - - // TODO(roasbeef): results in min being zero - return (y - min) / (max - min) * scaleFactor - } -} - var listPaymentsCommand = cli.Command{ Name: "listpayments", Category: "Payments", diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 8468e53d..65bfde65 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -23,7 +23,6 @@ type mockArbitratorLog struct { failCommit bool failCommitState ArbitratorState resolutions *ContractResolutions - chainActions ChainActionMap resolvers map[ContractResolver]struct{} commitSet *CommitSet diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go index 4c98366e..2a92c26e 100644 --- a/discovery/gossiper_test.go +++ b/discovery/gossiper_test.go @@ -43,10 +43,6 @@ var ( _, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10) _, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10) - inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" - sha, _ = chainhash.NewHashFromStr(inputStr) - outpoint = wire.NewOutPoint(sha, 0) - bitcoinKeyPriv1, _ = btcec.NewPrivateKey(btcec.S256()) bitcoinKeyPub1 = bitcoinKeyPriv1.PubKey() @@ -59,10 +55,9 @@ var ( nodeKeyPriv2, _ = btcec.NewPrivateKey(btcec.S256()) nodeKeyPub2 = nodeKeyPriv2.PubKey() - trickleDelay = time.Millisecond * 100 - retransmitDelay = time.Hour * 1 - proofMatureDelta uint32 - maxBtcFundingAmount = btcutil.Amount(1<<62) - 1 + trickleDelay = time.Millisecond * 100 + retransmitDelay = time.Hour * 1 + proofMatureDelta uint32 ) // makeTestDB creates a new instance of the ChannelDB for testing purposes. A diff --git a/discovery/sync_manager.go b/discovery/sync_manager.go index 059e415d..daebcc35 100644 --- a/discovery/sync_manager.go +++ b/discovery/sync_manager.go @@ -116,10 +116,6 @@ type SyncManager struct { cfg SyncManagerCfg - // historicalSync allows us to perform an initial historical sync only - // _once_ with a peer during the SyncManager's startup. - historicalSync sync.Once - // newSyncers is a channel we'll use to process requests to create // GossipSyncers for newly connected peers. newSyncers chan *newSyncer diff --git a/discovery/syncer.go b/discovery/syncer.go index 571e2d69..65a1b8f3 100644 --- a/discovery/syncer.go +++ b/discovery/syncer.go @@ -187,10 +187,6 @@ type gossipSyncerCfg struct { // in compressed format. peerPub [33]byte - // syncChanUpdates is a bool that indicates if we should request a - // continual channel update stream or not. - syncChanUpdates bool - // channelSeries is the primary interface that we'll use to generate // our queries and respond to the queries of the remote peer. channelSeries ChannelGraphTimeSeries diff --git a/discovery/syncer_test.go b/discovery/syncer_test.go index 7c114754..2568ee19 100644 --- a/discovery/syncer_test.go +++ b/discovery/syncer_test.go @@ -17,7 +17,6 @@ import ( const ( defaultEncoding = lnwire.EncodingSortedPlain latestKnownHeight = 1337 - startHeight = latestKnownHeight - chanRangeQueryBuffer ) var ( diff --git a/discovery/utils.go b/discovery/utils.go index 148e667b..ce211493 100644 --- a/discovery/utils.go +++ b/discovery/utils.go @@ -109,16 +109,6 @@ func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof, return chanAnn, edge1Ann, edge2Ann, nil } -// copyPubKey performs a copy of the target public key, setting a fresh curve -// parameter during the process. -func copyPubKey(pub *btcec.PublicKey) *btcec.PublicKey { - return &btcec.PublicKey{ - Curve: btcec.S256(), - X: pub.X, - Y: pub.Y, - } -} - // SignAnnouncement is a helper function which is used to sign any outgoing // channel node node announcement messages. func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey, diff --git a/fundingmanager.go b/fundingmanager.go index 0ede9720..855df1b8 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -123,15 +123,6 @@ func (r *reservationWithCtx) isLocked() bool { return r.lastUpdated.IsZero() } -// lock locks the reservation from zombie pruning by setting its timestamp to the -// zero value. -func (r *reservationWithCtx) lock() { - r.updateMtx.Lock() - defer r.updateMtx.Unlock() - - r.lastUpdated = time.Time{} -} - // updateTimestamp updates the reservation's timestamp with the current time. func (r *reservationWithCtx) updateTimestamp() { r.updateMtx.Lock() @@ -2506,14 +2497,6 @@ func (f *fundingManager) handleFundingLocked(fmsg *fundingLockedMsg) { } } -// channelProof is one half of the proof necessary to create an authenticated -// announcement on the network. The two signatures individually sign a -// statement of the existence of a channel. -type channelProof struct { - nodeSig *btcec.Signature - bitcoinSig *btcec.Signature -} - // chanAnnouncement encapsulates the two authenticated announcements that we // send out to the network after a new channel has been created locally. type chanAnnouncement struct { diff --git a/fundingmanager_test.go b/fundingmanager_test.go index d90f691c..e53ed045 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -49,8 +49,6 @@ const ( ) var ( - privPass = []byte("dummy-pass") - // Use hard-coded keys for Alice and Bob, the two FundingManagers that // we will test the interaction between. alicePrivKeyBytes = [32]byte{ diff --git a/htlcswitch/circuit_test.go b/htlcswitch/circuit_test.go index 8640fd29..3dc0f470 100644 --- a/htlcswitch/circuit_test.go +++ b/htlcswitch/circuit_test.go @@ -550,18 +550,6 @@ func assertHasKeystone(t *testing.T, cm htlcswitch.CircuitMap, } } -// assertDoesNotHaveKeystone tests that the circuit map does not contain a -// circuit for the provided outgoing circuit key. -func assertDoesNotHaveKeystone(t *testing.T, cm htlcswitch.CircuitMap, - outKey htlcswitch.CircuitKey) { - - circuit := cm.LookupOpenCircuit(outKey) - if circuit != nil { - t.Fatalf("expected no circuit for keystone %s, found %v", - outKey, circuit) - } -} - // assertHasCircuitForHash tests that the provided circuit appears in the list // of circuits for the given hash. func assertHasCircuitForHash(t *testing.T, cm htlcswitch.CircuitMap, hash [32]byte, @@ -619,17 +607,6 @@ func equalIgnoreLFD(c, c2 *htlcswitch.PaymentCircuit) bool { return isEqual } -// assertDoesNotHaveCircuit queries the circuit map using the circuit's -// incoming circuit key, and fails if it is found. -func assertDoesNotHaveCircuit(t *testing.T, cm htlcswitch.CircuitMap, - c *htlcswitch.PaymentCircuit) { - - c2 := cm.LookupCircuit(c.Incoming) - if c2 != nil { - t.Fatalf("expected no circuit for %v, got %v", c, c2) - } -} - // makeCircuitDB initializes a new test channeldb for testing the persistence of // the circuit map. If an empty string is provided as a path, a temp directory // will be created. diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 3c396814..1c462577 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -321,10 +321,6 @@ type channelLink struct { // been processed because of the commitment transaction overflow. overflowQueue *packetQueue - // startMailBox directs whether or not to start the mailbox when - // starting the link. It may have already been started by the switch. - startMailBox bool - // mailBox is the main interface between the outside world and the // link. All incoming messages will be sent over this mailBox. Messages // include new updates from our connected peer, and new packets to be diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 2fcfa2c6..722c785c 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1690,7 +1690,6 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) ( MaxFeeAllocation: DefaultMaxLinkFeeAllocation, } - const startingHeight = 100 aliceLink := NewChannelLink(aliceCfg, aliceLc.channel) start := func() error { return aliceSwitch.AddLink(aliceLink) @@ -4035,10 +4034,6 @@ func TestChannelLinkAcceptOverpay(t *testing.T) { } } -// chanRestoreFunc is a method signature for functions that can reload both -// endpoints of a link from their persistent storage engines. -type chanRestoreFunc func() (*lnwallet.LightningChannel, *lnwallet.LightningChannel, error) - // persistentLinkHarness is used to control the lifecylce of a link and the // switch that operates it. It supports the ability to restart either the link // or both the link and the switch. @@ -4256,7 +4251,6 @@ func (h *persistentLinkHarness) restartLink( MaxFeeAllocation: DefaultMaxLinkFeeAllocation, } - const startingHeight = 100 aliceLink := NewChannelLink(aliceCfg, aliceChannel) if err := aliceSwitch.AddLink(aliceLink); err != nil { return nil, nil, nil, err @@ -5394,7 +5388,6 @@ func TestChannelLinkFail(t *testing.T) { } const chanAmt = btcutil.SatoshiPerBitcoin * 5 - const chanReserve = 0 // Execute each test case. for i, test := range testCases { diff --git a/htlcswitch/mailbox.go b/htlcswitch/mailbox.go index 99ec9e1e..633232b9 100644 --- a/htlcswitch/mailbox.go +++ b/htlcswitch/mailbox.go @@ -63,7 +63,6 @@ type memoryMailBox struct { stopped sync.Once wireMessages *list.List - wireHead *list.Element wireMtx sync.Mutex wireCond *sync.Cond diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 0e739068..98f3596e 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -128,8 +128,6 @@ type mockServer struct { name string messages chan lnwire.Message - errChan chan error - id [33]byte htlcSwitch *Switch @@ -625,8 +623,6 @@ type mockChannelLink struct { peer lnpeer.Peer - startMailBox bool - mailBox MailBox packets chan *htlcPacket diff --git a/htlcswitch/packet.go b/htlcswitch/packet.go index 7ddc3050..3e0816e6 100644 --- a/htlcswitch/packet.go +++ b/htlcswitch/packet.go @@ -21,14 +21,6 @@ type htlcPacket struct { // on the incoming channel. incomingHTLCID uint64 - // incomingHtlcAmt is the value of the *incoming* HTLC. This will be - // set by the link when it receives an incoming HTLC to be forwarded - // through the switch. Then the outgoing link will use this once it - // creates a full circuit add. This allows us to properly populate the - // forwarding event for this circuit/packet in the case the payment - // circuit is successful. - incomingHtlcAmt lnwire.MilliSatoshi - // outgoingHTLCID is the ID of the HTLC that we offered to the peer on the // outgoing channel. outgoingHTLCID uint64 diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index b241d76e..c11c707e 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -2,7 +2,6 @@ package htlcswitch import ( "bytes" - "crypto/sha256" "errors" "fmt" "sync" @@ -66,10 +65,6 @@ var ( // ErrUnreadableFailureMessage is returned when the failure message // cannot be decrypted. ErrUnreadableFailureMessage = errors.New("unreadable failure message") - - // zeroPreimage is the empty preimage which is returned when we have - // some errors. - zeroPreimage [sha256.Size]byte ) // plexPacket encapsulates switch packet and adds error channel to receive @@ -258,10 +253,6 @@ type Switch struct { // messages will be sent over. resolutionMsgs chan *resolutionMsg - // linkControl is a channel used to propagate add/remove/get htlc - // switch handler commands. - linkControl chan interface{} - // pendingFwdingEvents is the set of forwarding events which have been // collected during the current interval, but hasn't yet been written // to the forwarding log. @@ -2225,18 +2216,6 @@ func (s *Switch) deleteCircuits(inKeys ...CircuitKey) error { return s.circuits.DeleteCircuits(inKeys...) } -// lookupCircuit queries the in memory representation of the circuit map to -// retrieve a particular circuit. -func (s *Switch) lookupCircuit(inKey CircuitKey) *PaymentCircuit { - return s.circuits.LookupCircuit(inKey) -} - -// lookupOpenCircuit queries the in-memory representation of the circuit map for a -// circuit whose outgoing circuit key matches outKey. -func (s *Switch) lookupOpenCircuit(outKey CircuitKey) *PaymentCircuit { - return s.circuits.LookupOpenCircuit(outKey) -} - // FlushForwardingEvents flushes out the set of pending forwarding events to // the persistent log. This will be used by the switch to periodically flush // out the set of forwarding events to disk. External callers can also use this diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index f69fb8c0..c8842a52 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -41,15 +41,7 @@ var ( bobPrivKey = []byte("bob priv key") carolPrivKey = []byte("carol priv key") - testPrivKey = []byte{ - 0x81, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, - 0x63, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, - 0xd, 0xe7, 0x95, 0xe4, 0xb7, 0x25, 0xb8, 0x4d, - 0x1e, 0xb, 0x4c, 0xfd, 0x9e, 0xc5, 0x8c, 0xe9, - } - - _, testPubKey = btcec.PrivKeyFromBytes(btcec.S256(), testPrivKey) - testSig = &btcec.Signature{ + testSig = &btcec.Signature{ R: new(big.Int), S: new(big.Int), } diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index b1dc4b4d..602014d4 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -27,10 +27,6 @@ var ( // errNoUpdate is returned when no invoice updated is required. errNoUpdate = errors.New("no update needed") - - // errReplayedHtlc is returned if the htlc is already recorded on the - // invoice. - errReplayedHtlc = errors.New("replayed htlc") ) // HodlEvent describes how an htlc should be resolved. If HodlEvent.Preimage is diff --git a/invoices/invoiceregistry_test.go b/invoices/invoiceregistry_test.go index c8ae8e0e..62c05b01 100644 --- a/invoices/invoiceregistry_test.go +++ b/invoices/invoiceregistry_test.go @@ -23,8 +23,6 @@ var ( testHtlcExpiry = uint32(5) - testInvoiceCltvDelta = uint32(4) - testFinalCltvRejectDelta = int32(4) testCurrentHeight = int32(1) diff --git a/lnrpc/autopilotrpc/log.go b/lnrpc/autopilotrpc/log.go index caf38119..e844bcab 100644 --- a/lnrpc/autopilotrpc/log.go +++ b/lnrpc/autopilotrpc/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/chainrpc/log.go b/lnrpc/chainrpc/log.go index 4671cabc..0d47ea97 100644 --- a/lnrpc/chainrpc/log.go +++ b/lnrpc/chainrpc/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/invoicesrpc/invoices_server.go b/lnrpc/invoicesrpc/invoices_server.go index df038b18..f7293efa 100644 --- a/lnrpc/invoicesrpc/invoices_server.go +++ b/lnrpc/invoicesrpc/invoices_server.go @@ -69,9 +69,6 @@ var ( // RPC server allows external callers to access the status of the invoices // currently active within lnd, as well as configuring it at runtime. type Server struct { - started int32 // To be used atomically. - shutdown int32 // To be used atomically. - quit chan struct{} cfg *Config diff --git a/lnrpc/routerrpc/log.go b/lnrpc/routerrpc/log.go index 4d896fdf..6cbd8bea 100644 --- a/lnrpc/routerrpc/log.go +++ b/lnrpc/routerrpc/log.go @@ -33,7 +33,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -43,6 +43,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/signrpc/log.go b/lnrpc/signrpc/log.go index bb9fc94d..b5ff742a 100644 --- a/lnrpc/signrpc/log.go +++ b/lnrpc/signrpc/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/walletrpc/log.go b/lnrpc/walletrpc/log.go index 6a0a5048..5c14879f 100644 --- a/lnrpc/walletrpc/log.go +++ b/lnrpc/walletrpc/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/watchtowerrpc/log.go b/lnrpc/watchtowerrpc/log.go index af2bc640..0ff4e680 100644 --- a/lnrpc/watchtowerrpc/log.go +++ b/lnrpc/watchtowerrpc/log.go @@ -32,7 +32,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -42,6 +42,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnrpc/wtclientrpc/log.go b/lnrpc/wtclientrpc/log.go index 7387e4f4..eaa847d6 100644 --- a/lnrpc/wtclientrpc/log.go +++ b/lnrpc/wtclientrpc/log.go @@ -33,7 +33,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -43,6 +43,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/lnwallet/btcwallet/config.go b/lnwallet/btcwallet/config.go index ea948e8a..3516d5cb 100644 --- a/lnwallet/btcwallet/config.go +++ b/lnwallet/btcwallet/config.go @@ -6,7 +6,6 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/wallet" @@ -19,25 +18,11 @@ import ( ) var ( - lnwalletHomeDir = btcutil.AppDataDir("lnwallet", false) - defaultDataDir = lnwalletHomeDir - - defaultLogFilename = "lnwallet.log" - defaultLogDirname = "logs" - defaultLogDir = filepath.Join(lnwalletHomeDir, defaultLogDirname) - - btcdHomeDir = btcutil.AppDataDir("btcd", false) - btcdHomedirCAFile = filepath.Join(btcdHomeDir, "rpc.cert") - defaultRPCKeyFile = filepath.Join(lnwalletHomeDir, "rpc.key") - defaultRPCCertFile = filepath.Join(lnwalletHomeDir, "rpc.cert") - // defaultPubPassphrase is the default public wallet passphrase which is // used when the user indicates they do not want additional protection // provided by having all public data in the wallet encrypted by a // passphrase only known to them. defaultPubPassphrase = []byte("public") - - walletDbName = "lnwallet.db" ) // Config is a struct which houses configuration parameters which modify the diff --git a/lnwallet/channel.go b/lnwallet/channel.go index dd718271..b6e6edff 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -109,7 +109,7 @@ type channelState uint8 const ( // channelPending indicates this channel is still going through the // funding workflow, and isn't yet open. - channelPending channelState = iota + channelPending channelState = iota // nolint: unused // channelOpen represents an open, active channel capable of // sending/receiving HTLCs. @@ -130,7 +130,7 @@ const ( // channelPendingPayment indicates that there a currently outstanding // HTLCs within the channel. - channelPendingPayment + channelPendingPayment // nolint:unused ) // PaymentHash represents the sha256 of a random value. This hash is used to @@ -1031,10 +1031,6 @@ type commitmentChain struct { // Once a commitment transaction is revoked, the tail is incremented, // freeing up the revocation window for new commitments. commitments *list.List - - // startingHeight is the starting height of this commitment chain on a - // session basis. - startingHeight uint64 } // newCommitmentChain creates a new commitment chain. @@ -1296,8 +1292,6 @@ type LightningChannel struct { // the commitment transaction that spends the multi-sig output. signDesc *input.SignDescriptor - channelEvents chainntnfs.ChainNotifier - status channelState // ChanPoint is the funding outpoint of this channel. diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index cdea5644..69702091 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1311,7 +1311,6 @@ func TestStateUpdatePersistence(t *testing.T) { } defer cleanUp() - const numHtlcs = 4 htlcAmt := lnwire.NewMSatFromSatoshis(5000) var fakeOnionBlob [lnwire.OnionPacketSize]byte diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index bfed469e..e7f53d1d 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -43,16 +43,6 @@ import ( ) var ( - privPass = []byte("private-test") - - // For simplicity a single priv key controls all of our test outputs. - testWalletPrivKey = []byte{ - 0x2b, 0xd8, 0x06, 0xc9, 0x7f, 0x0e, 0x00, 0xaf, - 0x1a, 0x1f, 0xc3, 0x32, 0x8f, 0xa7, 0x63, 0xa9, - 0x26, 0x97, 0x23, 0xc8, 0xdb, 0x8f, 0xac, 0x4f, - 0x93, 0xaf, 0x71, 0xdb, 0x18, 0x6d, 0x6e, 0x90, - } - bobsPrivKey = []byte{ 0x81, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, 0x63, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, @@ -113,22 +103,6 @@ func assertProperBalance(t *testing.T, lw *lnwallet.LightningWallet, } } -func assertChannelOpen(t *testing.T, miner *rpctest.Harness, numConfs uint32, - c <-chan *lnwallet.LightningChannel) *lnwallet.LightningChannel { - // Mine a single block. After this block is mined, the channel should - // be considered fully open. - if _, err := miner.Node.Generate(1); err != nil { - t.Fatalf("unable to generate block: %v", err) - } - select { - case lnc := <-c: - return lnc - case <-time.After(time.Second * 5): - t.Fatalf("channel never opened") - return nil - } -} - func assertReservationDeleted(res *lnwallet.ChannelReservation, t *testing.T) { if err := res.Cancel(); err == nil { t.Fatalf("reservation wasn't deleted from wallet") @@ -253,20 +227,6 @@ func assertTxInWallet(t *testing.T, w *lnwallet.LightningWallet, t.Fatalf("transaction %v not found", txHash) } -// calcStaticFee calculates appropriate fees for commitment transactions. This -// function provides a simple way to allow test balance assertions to take fee -// calculations into account. -// TODO(bvu): Refactor when dynamic fee estimation is added. -func calcStaticFee(numHTLCs int) btcutil.Amount { - const ( - commitWeight = btcutil.Amount(724) - htlcWeight = 172 - feePerKw = btcutil.Amount(250/4) * 1000 - ) - return feePerKw * (commitWeight + - btcutil.Amount(htlcWeight*numHTLCs)) / 1000 -} - func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet, numOutputs int, btcPerOutput float64) error { diff --git a/lnwallet/test_utils.go b/lnwallet/test_utils.go index 92010e9d..a229bda5 100644 --- a/lnwallet/test_utils.go +++ b/lnwallet/test_utils.go @@ -8,7 +8,6 @@ import ( "io" "io/ioutil" "os" - "sync" "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -17,14 +16,11 @@ import ( "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" - "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/shachain" ) var ( - privPass = []byte("private-test") - // For simplicity a single priv key controls all of our test outputs. testWalletPrivKey = []byte{ 0x2b, 0xd8, 0x06, 0xc9, 0x7f, 0x0e, 0x00, 0xaf, @@ -49,10 +45,6 @@ var ( 0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53, } - // The number of confirmations required to consider any created channel - // open. - numReqConfs = uint16(1) - // A serializable txn for testing funding txn. testTx = &wire.MsgTx{ Version: 1, @@ -382,43 +374,6 @@ func initRevocationWindows(chanA, chanB *LightningChannel) error { return nil } -type mockPreimageCache struct { - sync.Mutex - preimageMap map[lntypes.Hash]lntypes.Preimage -} - -func newMockPreimageCache() *mockPreimageCache { - return &mockPreimageCache{ - preimageMap: make(map[lntypes.Hash]lntypes.Preimage), - } -} - -func (m *mockPreimageCache) LookupPreimage( - hash lntypes.Hash) (lntypes.Preimage, bool) { - - m.Lock() - defer m.Unlock() - - p, ok := m.preimageMap[hash] - return p, ok -} - -func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error { - preimageCopies := make([]lntypes.Preimage, 0, len(preimages)) - for _, preimage := range preimages { - preimageCopies = append(preimageCopies, preimage) - } - - m.Lock() - defer m.Unlock() - - for _, preimage := range preimageCopies { - m.preimageMap[preimage.Hash()] = preimage - } - - return nil -} - // pubkeyFromHex parses a Bitcoin public key from a hex encoded string. func pubkeyFromHex(keyHex string) (*btcec.PublicKey, error) { bytes, err := hex.DecodeString(keyHex) @@ -439,25 +394,6 @@ func privkeyFromHex(keyHex string) (*btcec.PrivateKey, error) { } -// pubkeyToHex serializes a Bitcoin public key to a hex encoded string. -func pubkeyToHex(key *btcec.PublicKey) string { - return hex.EncodeToString(key.SerializeCompressed()) -} - -// privkeyFromHex serializes a Bitcoin private key to a hex encoded string. -func privkeyToHex(key *btcec.PrivateKey) string { - return hex.EncodeToString(key.Serialize()) -} - -// signatureFromHex parses a Bitcoin signature from a hex encoded string. -func signatureFromHex(sigHex string) (*btcec.Signature, error) { - bytes, err := hex.DecodeString(sigHex) - if err != nil { - return nil, err - } - return btcec.ParseSignature(bytes, btcec.S256()) -} - // blockFromHex parses a full Bitcoin block from a hex encoded string. func blockFromHex(blockHex string) (*btcutil.Block, error) { bytes, err := hex.DecodeString(blockHex) diff --git a/lnwallet/transactions_test.go b/lnwallet/transactions_test.go index 27d6c2f2..50a3bdf4 100644 --- a/lnwallet/transactions_test.go +++ b/lnwallet/transactions_test.go @@ -222,11 +222,10 @@ func newTestContext() (tc *testContext, err error) { } htlcData := []struct { - incoming bool - amount lnwire.MilliSatoshi - expiry uint32 - preimage string - paymentHash PaymentHash + incoming bool + amount lnwire.MilliSatoshi + expiry uint32 + preimage string }{ { incoming: true, diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 13c73851..c3ac2638 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -253,10 +253,6 @@ type LightningWallet struct { // keys, revocation keys, etc. keychain.SecretKeyRing - // This mutex is to be held when generating external keys to be used as - // multi-sig, and commitment keys within the channel. - keyGenMtx sync.RWMutex - // This mutex MUST be held when performing coin selection in order to // avoid inadvertently creating multiple funding transaction which // double spend inputs across each other. @@ -956,9 +952,6 @@ func (l *LightningWallet) handleSingleContribution(req *addSingleContributionMsg // pertaining to the exact location in the main chain in-which the transaction // was confirmed. type openChanDetails struct { - channel *LightningChannel - blockHeight uint32 - txIndex uint32 } // handleFundingCounterPartySigs is the final step in the channel reservation diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 3046c2f3..b7604f5d 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -23,13 +23,6 @@ import ( ) var ( - revHash = [32]byte{ - 0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab, - 0x4d, 0x92, 0x73, 0xd1, 0x90, 0x63, 0x81, 0xb4, - 0x4f, 0x2f, 0x6f, 0x25, 0x88, 0xa3, 0xef, 0xb9, - 0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53, - } - shaHash1Bytes, _ = hex.DecodeString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") shaHash1, _ = chainhash.NewHash(shaHash1Bytes) outpoint1 = wire.NewOutPoint(shaHash1, 0) diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index 42c1d5e1..4ea64fa6 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -10,11 +10,6 @@ import ( "unicode/utf8" ) -var ( - startPort uint16 = 1024 - endPort uint16 = 49151 -) - // ErrUnknownAddrType is an error returned if we encounter an unknown address type // when parsing addresses. type ErrUnknownAddrType struct { diff --git a/mock.go b/mock.go index 0b41bf83..cbcba646 100644 --- a/mock.go +++ b/mock.go @@ -16,7 +16,6 @@ import ( "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" - "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwallet" ) @@ -228,7 +227,6 @@ func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) // interaction with the bitcoin network. type mockWalletController struct { rootKey *btcec.PrivateKey - prevAddres btcutil.Address publishedTransactions chan *wire.MsgTx index uint32 utxos []*lnwallet.Utxo @@ -355,33 +353,3 @@ func (m *mockSecretKeyRing) ScalarMult(keyDesc keychain.KeyDescriptor, pubKey *btcec.PublicKey) ([]byte, error) { return nil, nil } - -type mockPreimageCache struct { - sync.Mutex - preimageMap map[lntypes.Hash]lntypes.Preimage -} - -func newMockPreimageCache() *mockPreimageCache { - return &mockPreimageCache{ - preimageMap: make(map[lntypes.Hash]lntypes.Preimage), - } -} - -func (m *mockPreimageCache) LookupPreimage(hash lntypes.Hash) (lntypes.Preimage, bool) { - m.Lock() - defer m.Unlock() - - p, ok := m.preimageMap[hash] - return p, ok -} - -func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error { - m.Lock() - defer m.Unlock() - - for _, preimage := range preimages { - m.preimageMap[preimage.Hash()] = preimage - } - - return nil -} diff --git a/monitoring/log.go b/monitoring/log.go index 2d3f1d61..4781f625 100644 --- a/monitoring/log.go +++ b/monitoring/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/netann/chan_status_manager_test.go b/netann/chan_status_manager_test.go index 60c86636..da42bc68 100644 --- a/netann/chan_status_manager_test.go +++ b/netann/chan_status_manager_test.go @@ -111,7 +111,6 @@ func createEdgePolicies(t *testing.T, channel *channeldb.OpenChannel, } type mockGraph struct { - pubKey *btcec.PublicKey mu sync.Mutex channels []*channeldb.OpenChannel chanInfos map[wire.OutPoint]*channeldb.ChannelEdgeInfo diff --git a/netann/log.go b/netann/log.go index f19e212c..32d9aae3 100644 --- a/netann/log.go +++ b/netann/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/peer.go b/peer.go index c57f23a4..77161ce6 100644 --- a/peer.go +++ b/peer.go @@ -30,10 +30,6 @@ import ( "github.com/lightningnetwork/lnd/ticker" ) -var ( - numNodes int32 -) - const ( // pingInterval is the interval at which ping messages are sent. pingInterval = 1 * time.Minute @@ -82,12 +78,6 @@ type closeMsg struct { msg lnwire.Message } -// chanSnapshotReq is a message sent by outside subsystems to a peer in order -// to gain a snapshot of the peer's currently active channels. -type chanSnapshotReq struct { - resp chan []*channeldb.ChannelSnapshot -} - // pendingUpdate describes the pending state of a closing channel. type pendingUpdate struct { Txid []byte @@ -717,7 +707,6 @@ type msgStream struct { mtx sync.Mutex - bufSize uint32 producerSema chan struct{} wg sync.WaitGroup diff --git a/routing/chainview/btcd.go b/routing/chainview/btcd.go index 87243b2e..c4d9c022 100644 --- a/routing/chainview/btcd.go +++ b/routing/chainview/btcd.go @@ -437,7 +437,6 @@ func (b *BtcdFilteredChainView) chainFilterer() { type filterUpdate struct { newUtxos []wire.OutPoint updateHeight uint32 - done chan struct{} } // UpdateFilter updates the UTXO filter which is to be consulted when creating diff --git a/routing/heap.go b/routing/heap.go index 294e3306..1cbbc5e5 100644 --- a/routing/heap.go +++ b/routing/heap.go @@ -3,7 +3,6 @@ package routing import ( "container/heap" - "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" ) @@ -120,62 +119,3 @@ func (d *distanceHeap) PushOrFix(dist nodeWithDist) { // Call heap.Fix to reorder the heap. heap.Fix(d, index) } - -// path represents an ordered set of edges which forms an available path from a -// given source node to our destination. During the process of computing the -// KSP's from a source to destination, several path swill be considered in the -// process. -type path struct { - // dist is the distance from the source node to the destination node - // that the path requires. - dist int - - // hops is an ordered list of edges that comprises a potential payment - // path. - hops []*channeldb.ChannelEdgePolicy -} - -// pathHeap is a min-heap that stores potential paths to be considered within -// our KSP implementation. The heap sorts paths according to their cumulative -// distance from a given source. -type pathHeap struct { - paths []path -} - -// Len returns the number of nodes in the priority queue. -// -// NOTE: This is part of the heap.Interface implementation. -func (p *pathHeap) Len() int { return len(p.paths) } - -// Less returns whether the item in the priority queue with index i should sort -// before the item with index j. -// -// NOTE: This is part of the heap.Interface implementation. -func (p *pathHeap) Less(i, j int) bool { - return p.paths[i].dist < p.paths[j].dist -} - -// Swap swaps the nodes at the passed indices in the priority queue. -// -// NOTE: This is part of the heap.Interface implementation. -func (p *pathHeap) Swap(i, j int) { - p.paths[i], p.paths[j] = p.paths[j], p.paths[i] -} - -// Push pushes the passed item onto the priority queue. -// -// NOTE: This is part of the heap.Interface implementation. -func (p *pathHeap) Push(x interface{}) { - p.paths = append(p.paths, x.(path)) -} - -// Pop removes the highest priority item (according to Less) from the priority -// queue and returns it. -// -// NOTE: This is part of the heap.Interface implementation. -func (p *pathHeap) Pop() interface{} { - n := len(p.paths) - x := p.paths[n-1] - p.paths = p.paths[0 : n-1] - return x -} diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 1e934c83..435758c8 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -125,7 +125,6 @@ type mockChain struct { utxos map[wire.OutPoint]wire.TxOut bestHeight int32 - bestHash *chainhash.Hash sync.RWMutex } diff --git a/routing/pathfind.go b/routing/pathfind.go index 4578f350..a38267ff 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -75,22 +75,6 @@ func computeFee(amt lnwire.MilliSatoshi, return edge.FeeBaseMSat + (amt*edge.FeeProportionalMillionths)/1000000 } -// isSamePath returns true if path1 and path2 travel through the exact same -// edges, and false otherwise. -func isSamePath(path1, path2 []*channeldb.ChannelEdgePolicy) bool { - if len(path1) != len(path2) { - return false - } - - for i := 0; i < len(path1); i++ { - if path1[i].ChannelID != path2[i].ChannelID { - return false - } - } - - return true -} - // newRoute returns a fully valid route between the source and target that's // capable of supporting a payment of `amtToSend` after fees are fully // computed. If the route is too long, or the selected path cannot support the diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 3151220a..31e69d57 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -324,21 +324,6 @@ type testChannelEnd struct { *testChannelPolicy } -func defaultTestChannelEnd(alias string, capacity btcutil.Amount) *testChannelEnd { - return &testChannelEnd{ - Alias: alias, - testChannelPolicy: &testChannelPolicy{ - Expiry: 144, - MinHTLC: lnwire.MilliSatoshi(1000), - MaxHTLC: lnwire.NewMSatFromSatoshis(capacity), - FeeBaseMsat: lnwire.MilliSatoshi(1000), - FeeRate: lnwire.MilliSatoshi(1), - LastUpdate: testTime, - Disabled: false, - }, - } -} - func symmetricTestChannel(alias1 string, alias2 string, capacity btcutil.Amount, policy *testChannelPolicy, chanID ...uint64) *testChannel { @@ -1675,13 +1660,6 @@ func TestPathFindSpecExample(t *testing.T) { } defer cleanUp() - const ( - aliceFinalCLTV = 10 - bobFinalCLTV = 20 - carolFinalCLTV = 30 - daveFinalCLTV = 40 - ) - // We'll first exercise the scenario of a direct payment from Bob to // Carol, so we set "B" as the source node so path finding starts from // Bob. diff --git a/routing/payment_session.go b/routing/payment_session.go index 16baa0f4..95197d48 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -137,9 +137,3 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment, return route, err } - -// nodeChannel is a combination of the node pubkey and one of its channels. -type nodeChannel struct { - node route.Vertex - channel uint64 -} diff --git a/routing/router.go b/routing/router.go index 7f99c99a..b3403dfd 100644 --- a/routing/router.go +++ b/routing/router.go @@ -295,25 +295,6 @@ type Config struct { PathFindingConfig PathFindingConfig } -// routeTuple is an entry within the ChannelRouter's route cache. We cache -// prospective routes based on first the destination, and then the target -// amount. We required the target amount as that will influence the available -// set of paths for a payment. -type routeTuple struct { - amt lnwire.MilliSatoshi - dest [33]byte -} - -// newRouteTuple creates a new route tuple from the target and amount. -func newRouteTuple(amt lnwire.MilliSatoshi, dest []byte) routeTuple { - r := routeTuple{ - amt: amt, - } - copy(r.dest[:], dest) - - return r -} - // EdgeLocator is a struct used to identify a specific edge. type EdgeLocator struct { // ChannelID is the channel of this edge. @@ -325,31 +306,6 @@ type EdgeLocator struct { Direction uint8 } -// newEdgeLocatorByPubkeys returns an edgeLocator based on its end point -// pubkeys. -func newEdgeLocatorByPubkeys(channelID uint64, fromNode, toNode *route.Vertex) *EdgeLocator { - // Determine direction based on lexicographical ordering of both - // pubkeys. - var direction uint8 - if bytes.Compare(fromNode[:], toNode[:]) == 1 { - direction = 1 - } - - return &EdgeLocator{ - ChannelID: channelID, - Direction: direction, - } -} - -// newEdgeLocator extracts an edgeLocator based for a full edge policy -// structure. -func newEdgeLocator(edge *channeldb.ChannelEdgePolicy) *EdgeLocator { - return &EdgeLocator{ - ChannelID: edge.ChannelID, - Direction: uint8(edge.ChannelFlags & lnwire.ChanUpdateDirection), - } -} - // String returns a human readable version of the edgeLocator values. func (e *EdgeLocator) String() string { return fmt.Sprintf("%v:%v", e.ChannelID, e.Direction) diff --git a/routing/router_test.go b/routing/router_test.go index 9ade7cf0..a90b5e5d 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -67,14 +67,6 @@ func (c *testCtx) RestartRouter() error { return nil } -func copyPubKey(pub *btcec.PublicKey) *btcec.PublicKey { - return &btcec.PublicKey{ - Curve: btcec.S256(), - X: pub.X, - Y: pub.Y, - } -} - func createTestCtxFromGraphInstance(startingHeight uint32, graphInstance *testGraphInstance) ( *testCtx, func(), error) { diff --git a/rpcserver.go b/rpcserver.go index e187169f..d030c790 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -27,7 +27,6 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/wallet/txauthor" "github.com/coreos/bbolt" "github.com/davecgh/go-spew/spew" @@ -77,8 +76,6 @@ var ( // It is set to the value under the Bitcoin chain as default. MaxPaymentMSat = maxBtcPaymentMSat - defaultAccount uint32 = waddrmgr.DefaultAccountNum - // readPermissions is a slice of all entities that allow read // permissions for authorization purposes, all lowercase. readPermissions = []bakery.Op{ @@ -396,8 +393,6 @@ type rpcServer struct { server *server - wg sync.WaitGroup - // subServers are a set of sub-RPC servers that use the same gRPC and // listening sockets as the main RPC server, but which maintain their // own independent service. This allows us to expose a set of diff --git a/shachain/utils.go b/shachain/utils.go index 2f61f247..aeb3bd59 100644 --- a/shachain/utils.go +++ b/shachain/utils.go @@ -6,25 +6,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" ) -// changeBit is a functio that function that flips a bit of the hash at a -// particular bit-index. You should be aware that the bit flipping in this -// function a bit strange, example: -// hash: [0b00000000, 0b00000000, ... 0b00000000] -// 0 1 ... 31 -// -// byte: 0 0 0 0 0 0 0 0 -// 7 6 5 4 3 2 1 0 -// -// By flipping the bit at 7 position you will flip the first bit in hash and by -// flipping the bit at 8 position you will flip the 16 bit in hash. -func changeBit(hash []byte, position uint8) []byte { - byteNumber := position / 8 - bitNumber := position % 8 - - hash[byteNumber] ^= (1 << bitNumber) - return hash -} - // getBit return bit on index at position. func getBit(index index, position uint8) uint8 { return uint8((uint64(index) >> position) & 1) diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 8f72a7ab..b4139fba 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -286,25 +286,6 @@ func (ctx *sweeperTestContext) assertPendingInputs(inputs ...input.Input) { } } -// receiveSpendTx receives the transaction sent through the given resultChan. -func receiveSpendTx(t *testing.T, resultChan chan Result) *wire.MsgTx { - t.Helper() - - var result Result - select { - case result = <-resultChan: - case <-time.After(5 * time.Second): - t.Fatal("no sweep result received") - } - - if result.Err != nil { - t.Fatalf("expected successful spend, but received error "+ - "\"%v\" instead", result.Err) - } - - return result.Tx -} - // assertTxSweepsInputs ensures that the transaction returned within the value // received from resultChan spends the given inputs. func assertTxSweepsInputs(t *testing.T, sweepTx *wire.MsgTx, diff --git a/utxonursery_test.go b/utxonursery_test.go index 8ad1c31f..6671c070 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -1019,21 +1019,6 @@ func (i *nurseryStoreInterceptor) RemoveChannel(chanPoint *wire.OutPoint) error return i.ns.RemoveChannel(chanPoint) } -type nurseryMockSigner struct { -} - -func (m *nurseryMockSigner) SignOutputRaw(tx *wire.MsgTx, - signDesc *input.SignDescriptor) ([]byte, error) { - - return []byte{}, nil -} - -func (m *nurseryMockSigner) ComputeInputScript(tx *wire.MsgTx, - signDesc *input.SignDescriptor) (*input.Script, error) { - - return &input.Script{}, nil -} - type mockSweeper struct { lock sync.Mutex diff --git a/walletunlocker/service_test.go b/walletunlocker/service_test.go index 330ab7ab..525a2bdc 100644 --- a/walletunlocker/service_test.go +++ b/walletunlocker/service_test.go @@ -18,10 +18,6 @@ import ( "golang.org/x/net/context" ) -const ( - walletDbName = "wallet.db" -) - var ( testPassword = []byte("test-password") testSeed = []byte("test-seed-123456789") diff --git a/watchtower/log.go b/watchtower/log.go index f2fb5fc1..7aebd7e7 100644 --- a/watchtower/log.go +++ b/watchtower/log.go @@ -34,7 +34,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -44,6 +44,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) } diff --git a/watchtower/wtclient/session_queue.go b/watchtower/wtclient/session_queue.go index 9d145662..87834815 100644 --- a/watchtower/wtclient/session_queue.go +++ b/watchtower/wtclient/session_queue.go @@ -15,10 +15,6 @@ import ( "github.com/lightningnetwork/lnd/watchtower/wtwire" ) -// retryInterval is the default duration we will wait between attempting to -// connect back out to a tower if the prior state update failed. -const retryInterval = 2 * time.Second - // reserveStatus is an enum that signals how full a particular session is. type reserveStatus uint8 diff --git a/watchtower/wtdb/log.go b/watchtower/wtdb/log.go index b4b30f45..0e14ea99 100644 --- a/watchtower/wtdb/log.go +++ b/watchtower/wtdb/log.go @@ -30,7 +30,7 @@ func UseLogger(logger btclog.Logger) { // logClosure is used to provide a closure over expensive logging operations so // don't have to be performed when the logging level doesn't warrant it. -type logClosure func() string +type logClosure func() string // nolint:unused // String invokes the underlying function and returns the result. func (c logClosure) String() string { @@ -40,6 +40,6 @@ func (c logClosure) String() string { // newLogClosure returns a new closure over a function that returns a string // which itself provides a Stringer interface so that it can be used with the // logging system. -func newLogClosure(c func() string) logClosure { +func newLogClosure(c func() string) logClosure { // nolint:unused return logClosure(c) }