Commit Graph
100 Commits
Author SHA1 Message Date
Eugene 225390ab5b Merge pull request #4487 from Crypt-iQ/cc_pkg_0723
chainreg: new chainreg package
2020-10-30 06:07:26 -04:00
Eugene 9571088756 lnd: log errors for ChainControl when shutting down 2020-10-29 15:24:17 -04:00
Eugene bebe258e2d chainregistry+lnd: moving chainregistry+chainparams to new package 2020-10-29 15:24:14 -04:00
Eugene 46ef212de4 lnd+lncfg: move normalizeNetwork to lncfg 2020-10-29 15:20:00 -04:00
Eugene 4d238cfa2f lnd: export ChainControl, ChainRegistry 2020-10-29 15:20:00 -04:00
Eugene cbdea57d52 chainregistry.go: export default values
This is needed so that git sees a subsequent commit as a code move.
2020-10-29 15:19:58 -04:00
Eugene f4fe76aaf1 chainreg: add Config, move chainparams.go
Creates a Config that initializes the chainregistry struct in the
lnd package. Also moves all of chainparams.go to the chainreg
package.
2020-10-29 15:19:58 -04:00
Eugene 933b959aa8 chainreg: export ChainCode to new pkg
Moves chainCode from the lnd package to the chainreg package,
where it is exported and can be used by other packages.
2020-10-29 15:19:57 -04:00
eugene afb6ad295e lnd: move initNeutrinoBackend to lnd.go 2020-10-29 15:19:56 -04:00
Eugene 426db548dd Merge pull request #4651 from Crypt-iQ/zpay32_fuzz
fuzz/zpay32: add Decode/Encode fuzz tests.
2020-10-22 10:23:24 -04:00
eugene bbe85f3c16 fuzz/zpay32: add Decode/Encode fuzz tests.
These can be expanded on in the future. Encoding is currently done
with a static key for test determinism.
2020-10-21 06:42:54 -04:00
Eugene 9e75c3eade Merge pull request #4682 from Crypt-iQ/fuzz_ret_1009
fuzz: change return values to 1 rather than 0 or -1
2020-10-14 16:07:54 -04:00
eugene f82653cb06 fuzz: change return values to 1 rather than 0 or -1
This allows gofuzz to store the mutating input as coverage if it reaches
any new coverage, even if it didn't make it to the end of the test.
2020-10-13 15:17:57 -04:00
Eugene 10a84f2c75 Merge pull request #4649 from Crypt-iQ/fmgr_abstract
multi: add fmgr.Manager interface, change usage in peer to use Manager
2020-10-02 08:21:15 -04:00
eugene e0859e121f multi: add fmgr.Manager interface, change usage in peer to use Manager
This gets rid of several config functions in the peer and should pave
the way for easier testing of the funding manager and peer.
2020-10-01 10:27:13 -04:00
Eugene 0a8f06651a Merge pull request #4645 from Crypt-iQ/peer_messageconn
peer: abstractions to aid in unit testing
2020-09-25 13:58:02 -04:00
eugene fada3dd871 server.go + peer: use MessageConn interface instead of brontide.Conn 2020-09-25 12:05:36 -04:00
Eugene cc29e1cce8 Merge pull request #4640 from Crypt-iQ/brontide_fuzz_fixups
fuzz/brontide: fix fuzz_utils.go NewBrontideMachine callsites
2020-09-24 00:53:43 -04:00
eugene 6ba35238ef fuzz/brontide: fix fuzz_utils.go NewBrontideMachine callsites 2020-09-22 15:53:49 -04:00
eugene ea467783e9 htlcswitch+peer: remove fwd pkgs once before tick, bump timer to 1hr
This commit changes the logic when garbage collecting forwarding
packages such that they are removed once when the function is called,
and then again upon subsequent ticks. This allows us to bump the
peer timer to 1 hour to limit the number of db transactions happening
in lnd. The forwarding packages need to be removed initially as
otherwise a flappy node will never have them garbage collected.
2020-08-31 20:52:51 -04:00
eugene 62e19185f1 htlcswitch+channeldb: single tx for removing fwdpkgs
This commit changes RemoveFwdPkg to RemoveFwdPkgs so that a single
tx is used instead of N where N is the number of fwd pkgs to remove.
2020-08-31 20:52:51 -04:00
eugene 9ce89c1b46 lnd: delete mock.go, move mockSpendNotifier to lntest/mock 2020-08-31 20:06:11 -04:00
eugene 4ff03afee0 lnd: move fundingBroadcastHeight to fundingmanager_test.go 2020-08-31 19:42:53 -04:00
eugene c7cbacc35b multi: move mockChainIO, mockNotifier to lntest/mock 2020-08-31 19:41:09 -04:00
eugene 3fa5d042c9 multi: move mockWalletController, mockSecretKeyRing to lntest/mock 2020-08-31 18:36:05 -04:00
eugene 49d8f04197 multi: migrate instances of mockSigner to the mock package
This commit moves all localized instances of mock implementations of
the Signer interface to the lntest/mock package. This allows us to
remove a lot of code and have it housed under a single interface in
many cases.
2020-08-28 15:43:51 -04:00
nsa 3791c9efcb lnd: removing activeNetParams global, passed around instead via configs
This commit removes the activeNetParams global in chainparams.go. This
is necessary to isolate code from the lnd package so we can import it
for use in tests, other projects, etc.
2020-08-11 11:41:24 -04:00
nsa c36840c2a5 lnwallet: add regression test TestChannelLocalUnsignedUpdatesFailure
This commit includes a regression test that checks that we remember
to restore updates that we sent to the peer but they haven't sent
us a signature for yet.
2020-07-29 19:03:44 -04:00
nsa e4188ba9c2 channeldb+lnwallet: store updates the peer should sign under new key
This fixes a long-standing force close bug. When we receive a
revocation, store the updates that the remote should sign next under
a new database key. Previously, these were not persisted which would
lead to force closure.
2020-07-29 19:03:44 -04:00
nsa b6eff5b0ec lnwallet: add regression test TestChannelUnsignedAckedFailure
This commit includes a regression test that checks that a force
close won't occur and that unsigned acked updates are properly
restored.
2020-07-27 16:18:11 -04:00
nsa 8c002a08a7 lnwallet: properly restore removeCommitHeightRemote
Previously, we could sign a pending commitment for the remote party,
disconnect, and not restore these signed remote updates as having been
removed at the pending commitment height. This commit fixes that to
look up whether the update under the unsigned acked updates key is
present on the pending commitment or not and appropriately set
the remove commit heights.
2020-07-27 15:41:48 -04:00
nsa 2149157d49 channeldb: filter out unsigned acked updates in AdvanceCommitChainTail
This commit moves the deletion of all updates under the unsigned
acked updates key from AppendRemoteCommitChain to
AdvanceCommitChainTail. This is done because if we went down after
signing for these updates but before receiving a revocation, we would
incorrectly reject their commitment signature:

Alice                Bob
      -----add----->
      -----sig----->
      <----rev------
      <----sig------
      -----rev----->
      <----fail-----
      <----sig------
      -----rev----->
      -----sig----->
      *reconnect*
      <----rev------
      <----add------
      x----sig------

It is also important to note that filtering is required when we
receive a revocation to ensure that we aren't erroneously deleting
remote updates. Take the following state transitions:

 Alice                Bob
       -----add----->
       -----sig----->
       <----rev------
       <----sig------
       -----rev----->
       -----add----->
       -----sig----->
       <----fail-----
       <----sig------
       -----rev-----> (alice stores updates here)
       <----rev------

In the above case, if Alice deleted all updates rather than filtering
when receiving the final revocation from Bob, then Alice would have
to force close the channel due to missing updates. Since Alice hasn't
signed for any of the unsigned acked updates, she should not filter any
of them out.
2020-07-27 15:41:48 -04:00
nsa 3ec081af84 lnwallet: correct fetchParent godoc 2020-07-21 10:45:57 -04:00
nsa 73757eb84d lnwallet: properly set addCommitHeightLocal in restoreStateLogs
The `restoreStateLogs` function now properly restores the
`addCommitHeightLocal` field of a settle or fail's parent add.
Previously, any updates' parent in unsignedAckedUpdates would have
the field set to the default value of 0. This would cause a force
closure when receiving a commitment due to our belt-and-suspenders
checks for update logs during commitment validation.

The bug in question occurs because the `addCommitHeightLocal` field
is only populated for a restored add if the add is on the local
commitment. `TestChannelRestoreCommitHeight` is expanded in
`lnwallet/channel_test.go` to demonstrate restoration now works.

The faulty state transition:
```
<----fail----
<----sig-----
-----rev----> (add no longer on Alice's commitment)
*Alice restores* (addCommitHeightLocal of failed htlc is 0)
```

NOTE: Alice dies after sending a revocation but before signing a
commitment. This is possible because there is a select block in the link
that can potentially exit after sending over the revocation but before
signing the next commitment state for the counterparty.
2020-07-21 10:45:57 -04:00
nsa cbd54101f8 multi: remove peer.go, change all references to point to peer pkg 2020-07-06 19:16:07 -04:00
nsa 9be9d69349 multi: initialize peer with peer.Config 2020-07-06 19:16:07 -04:00
nsa bf161c9835 peer+server: add HandleLocalCloseChanReqs to peer, call from server 2020-07-06 19:16:07 -04:00
nsa e1632dd172 peer.go: handleCloseMsg function for channelManager goroutine 2020-07-06 19:16:07 -04:00
nsa 1a91013c14 peer_test+test_utils: remove duplicate *LightningChannel return param
It was already present in the peer object that was returned.
2020-07-06 19:16:07 -04:00
nsa 02fd905f61 peer.go: moving the apply function outside of the constructor
This is mainly for readability so that the function isn't indented.
2020-07-06 19:16:07 -04:00
nsa 4ee4a1a24e peer.go: remove height argument to addLink function
Best height is not needed to create a link.
2020-07-06 19:16:07 -04:00
nsa 328094d8fb peer.go: replace switch statements with if statements 2020-07-06 19:16:06 -04:00
nsa 0dda9e06ce multi: exporting PendingUpdate, ChannelCloseUpdate, ErrorBufferSize 2020-07-06 19:16:06 -04:00
nsa ac3d416b04 peer_test.go: fixes to coop close tests, modifying variable names
to either be alice or bob-prefixed. This helps an observer understand
what the test is actually doing.
2020-07-06 19:16:06 -04:00
nsa ac72479b10 server.go: log DisconnectPeer errors, use public functions to access
peer internals.
2020-07-06 19:16:06 -04:00
nsa bfaef46579 peer_test.go: comment clarifications 2020-07-06 19:16:06 -04:00
nsa d23b30d889 peer.go: comment clarifications, improved formatting 2020-07-06 19:16:06 -04:00
nsa 01415f4a5f peer: define Config and LinkUpdater interface
This commit defines a Config for initializing a peer and the
LinkUpdater interface.
2020-07-06 19:16:06 -04:00
nsa 50186ba834 lnpeer/peer.go: modifying interface comment 2020-07-06 19:16:06 -04:00
nsa 2d68a64a5b chancloser: new package for cooperative channel closure
Introduces a new chancloser package which exposes a ChanCloser
struct that handles the cooperative channel closure negotiation
and is meant to replace chancloser.go in the lnd package. Updates
all references to chancloser.go to instead use chancloser package.
2020-06-16 20:34:44 -04:00
nsa 8528ec4568 lnd: modifying comments in chancloser.go 2020-06-16 20:34:44 -04:00
nsa ec2d999371 chancloser+peer: export negotiationHeight, channel, and error 2020-06-11 15:49:23 -04:00
nsa 85852733af Makefile: add -w to -ldflags to strip DWARF symbols
Compiling with this flag cuts down on the binary size by several
megabytes.
2020-06-09 14:40:48 -04:00
nsa 2848eb1d53 docs: detail watchtower tor hidden service configuration 2020-03-30 11:54:48 -04:00
nsa ada0b78dfc lnd+server+watchtower: allow Standalone access to the tor controller
This commit lets the watchtower automatically create hidden services
by giving it a pointer to a TorController. The server was also slightly
refactored so that it was not the sole owner of the TorController.
2020-03-29 12:36:54 -04:00
nsaandTurtle f1fd5e86c0 config: add WatchtowerKeyPath Tor option
Co-authored-by: Turtle <orbitalturtle@protonmail.com>
2020-03-29 11:54:59 -04:00
nsa f00159f64c peer: no pending channels in switch, buffer msgs until link active 2020-03-27 08:49:46 -04:00
nsa 966cd2112c multi: link notifies subscribers of ActiveLinkEvent, rpc ignores 2020-03-27 08:49:46 -04:00
nsa f5237589ea channelnotifier: new ActiveLinkEvent for link startup notification 2020-03-27 08:49:46 -04:00
nsa 8c0c53eac3 htlcswitch: only error in closeCircuit if the htlc was failed
This commit changes the switch to only log an error if update_fail_htlc
comes in and closeCircuit returns ErrUnknownCircuit. Rationale
being that only settles should hit this code path, anything else
is a result of a link flap and should be treated as an error.
2020-03-25 11:53:46 -04:00
nsa 4fe174ba4e htlcswitch: switch ackDownStreamPackets order with contract update call
This commit modifies updateCommitTx to error with ErrLinkShuttingDown
when we try to send a ContractUpdate on the htlcUpdates chan and the
link has closed the quit chan. It also changes the order of the call
to ackDownStreamPackets and contract update call for consistency since
the packets should be acknowledged before the link goes down.
2020-03-25 11:53:21 -04:00
nsa f757bf48bd channeldb: use RemoteCommitment in NextLocalHtlcIndex
This commit changes the fallback in NextLocalHtlcIndex to
RemoteCommitment since the LocalHtlcIndex field lags behind
on the LocalCommitment. Without this bug fix, open circuits
would get prematurely trimmed, resulting in more erroneous
logs. A test case is included to check that the fix works.
2020-03-25 11:49:16 -04:00
nsa 363bdc42b0 fuzz/lnwire: adding fuzz harnesses for all lnwire messages + zlib 2020-03-03 13:58:25 -05:00
nsa 5a03fe572f lnwire: move zero-length queryBody check to zlib case 2020-03-03 13:58:25 -05:00
nsa 7b9e0c889e docs: add fuzz.md 2020-03-03 13:58:07 -05:00
nsa 5a5e095684 lnwallet: adding TestMaxAsynchronousHtlcs unit test
Adds a new test which asserts that the new ReceiveHTLC logic can
handle proper commitment overflow calculation in the face of
asynchronous updates.
2020-02-15 09:59:50 -05:00
nsa 4af00c6b25 lnwallet: fixing unit tests to properly handle new receive validation
This commit fixes the TestMaxAcceptedHTLCs, TestMaxPendingAmount,
TestMinHTLC, & TestChanReserve unit tests to pass with the new
ReceiveHTLC logic. Instead of asserting specific failures upon
receiving a new commitment signature, the various assertions were
moved to assert on the error returned from ReceiveHTLC.
2020-02-15 09:59:50 -05:00
nsa 56c07a52d8 lnwallet: call valdiateCommitmentSanity in ReceiveHTLC
This commit checks the commitment sanity when receiving an HTLC so
that if a commitment transaction will overflow from an ADD, it is
caught earlier rather than in ReceiveNewCommitment.
2020-02-15 09:59:49 -05:00
nsa 0d42da0cb3 fuzz/brontide: random+static round-trip encrypt+decrypt harnesses 2020-01-30 16:46:02 -05:00
nsa 0be5660a2a fuzz/brontide: random+static encrypt harnesses 2020-01-30 16:46:02 -05:00
nsa 468e5c03e9 fuzz/brontide: random+static decrypt harnesses 2020-01-30 16:46:01 -05:00
nsa 116c5469bc fuzz/brontide: random+static harnesses for acts 1-3 2020-01-30 16:46:01 -05:00
nsa 511fdb2520 fuzz/brontide: add fuzzing helper utilities 2020-01-30 16:46:01 -05:00
nsa 7c316b9194 brontide: add SetCurveToNil function 2020-01-30 16:45:59 -05:00
nsa bdb20d0053 fuzz/wtwire: adding wtwire fuzzers 2020-01-28 20:20:35 -05:00
nsa 929167b9af routing: fix race condition when resuming payments 2019-11-15 14:44:05 -05:00
nsa 1018df991f macaroons: add encKeyMtx to prevent race condition 2019-11-09 21:12:11 -05:00
nsa b392dd1b95 routing: move statTicker to prevent race condition 2019-11-02 13:55:41 -04:00
nsa 423887d3d8 chanacceptor: adding tests for the RPCAcceptor
This commit adds the TestRPCMultipleAcceptClients test which asserts
that the RPCAcceptor correctly handles multiple Accept callers.
2019-09-25 12:07:31 -04:00
nsa 4d02100e12 fundingmanager+server: adding ChannelAcceptor to the fundingmanager 2019-09-25 12:07:30 -04:00
nsa c2a6c86e6b rpcserver: adding ChannelAcceptor bidirectional streaming 2019-09-25 12:07:30 -04:00
nsa 2bd2e2e5ce chanacceptor: Adding Chained and RPC acceptors
This commit introduces the chanacceptor package which is used
to determine, by a set of heuristics, which open channel messages
to accept and reject. Currently, two acceptors are implemented
via the ChannelAcceptor interface: ChainedAcceptor and RPCAcceptor.
The RPCAcceptor allows the RPC client to respond to the open channel
request, and the ChainedAcceptor allows a conjunction of acceptors
to be used.
2019-09-25 12:07:30 -04:00
nsa 7c6cee7c4f lnrpc: updating protos to include ChannelAcceptor 2019-09-25 12:07:28 -04:00
nsa 0f6e11c35f zpay32: check invoice length while decoding
This commit checks that the size of the bech32 encoded invoice is not
greater than 7092 bytes, which is the maximum number of bytes that can
fit into a QR code. This mitigates a potential DoS vector where an attacker
could craft a very large bech32 invoice string containing an absurd amount
of route and/or hop hints. If sent to an application that processes
payment requests, this would allocate a burdensome amount of memory
due to the public key parsing for each route/hop hint.

For a 1.7MB payment request, this yielded about 38MB in allocations
from just parsing public keys:

```
   45.51MB  7.31% 92.07%    45.51MB  7.31%  math/big.nat.make
   25.50MB  4.09% 96.16%    25.50MB  4.09%  github.com/lightningnetwork/lnd/zpay32.bech32VerifyChecksum
       1MB  0.16% 96.32%    39.50MB  6.34%  github.com/lightningnetwork/lnd/zpay32.parseRouteHint
       1MB  0.16% 96.48%    33.50MB  5.38%  github.com/btcsuite/btcd/btcec.decompressPoint
    0.50MB  0.08% 96.56%     7.50MB  1.20%  crypto/elliptic.(*CurveParams).doubleJacobian
    0.50MB  0.08% 96.64%       38MB  6.10%  github.com/btcsuite/btcd/btcec.ParsePubKey
         0     0% 96.64%       12MB  1.93%  crypto/ecdsa.Verify
         0     0% 96.64%        8MB  1.28%  crypto/elliptic.(*CurveParams).ScalarBaseMult
         0     0% 96.64%       12MB  1.93%  crypto/elliptic.(*CurveParams).ScalarMult
```

With this change, memory usage will be far lower as decoding will exit
early with an error if the invoice is too large.
2019-09-24 06:21:27 -04:00
nsa dfd1b38648 tlv: fix panic with large length
This commit fixes a panic where a large length in a record could
cause the DVarBytes function to fail to allocate a byte slice.
2019-08-21 16:48:23 -07:00
nsa 7762d55e80 itest+routing: updating tests to account for BlockPadding 2019-07-23 21:03:30 -04:00
nsa 3dde7bc4e2 routing: adding the BlockPadding value to sendpayment
This commit adds the BlockPadding value (currently 3) to sendpayment
calls so that if some blocks are mined while the htlc is in-flight, the
exit hop won't reject it.
2019-07-23 21:03:11 -04:00
nsa 00814dc7c1 htlcswitch: pipeline settles to switch
This commit makes the outgoing link pipeline the settle to the
switch as soon as it receives it. Previously, it would wait for a
revocation before sending it, which caused increased latency on
payments as well as possibly never settling on the incoming link.
A duplicate settle is still sent to the switch, but it is handled
gracefully. A new AckEventTicker was added to the switch which
acknowledges any pending settle / fail entries in an outgoing
link's fwd pkgs in batch. This was needed in order to reduce the
number of db txn's which would have been incurred by acking whenever
we receive a duplicate settle without batching.
2019-07-18 17:20:40 -04:00
nsa 7e6a34532e routing: add index map to distanceHeap
This commit adds the pubkeyIndices map to the distanceHeap to avoid
duplicate entries on the heap. This happened in the earlier iteration
of the findPath algorithm and would cause the driving loop to
evaluate already evaluated entries when there was no need.
2019-07-12 06:08:01 -04:00
nsa 61a1ab08fb routing+channeldb: findPath uses Vertex instead of LightningNode
This commit modifies the nodeWithDist struct to use a route.Vertex
instead of a *channeldb.LightningNode. This change, coupled with
the new ForEachNodeChannel function, allows the findPath Djikstra's
algorithm to cut down on database lookups since we no longer need
to call the FetchOtherNode function.
2019-07-12 06:08:01 -04:00
nsa 66d15c8e76 channeldb + wtdb: specify freelist bbolt options by default
This commit specifies two bbolt options when opening the underlying
channel and watchtower databases so that there is reduced heap
pressure in case the bbolt database has a lot of free pages in the
B+ tree.
2019-07-08 18:41:25 -04:00
nsa 4fd78926d4 build: update bbolt to v1.3.3 with panic rollback fix
This commit updates the bbolt dependency to v1.3.3 so that we
can use the NoFreelistSync option without triggering a panic
in case a rollback occurs.
2019-07-08 18:35:43 -04:00
nsa 678fb674eb routing: move call to PruneGraph outside of the collating loop
This commit moves the call to PruneGraph outside of the loop
that collates all of the spentOutputs. With this change, if
a node has been offline for a long period of time, resyncing
with the chain no longer takes up as much memory (1MB vs 200MB
in some cases) or time. Previously, PruneGraph was called
for every block and allocated a very large map further down
in the pruneGraphNodes function. Now, pruneGraphNodes is only
called once.
2019-07-02 21:21:28 -04:00
nsa 9804caca6d chanrestore: return error instead of nil if failed derivation
This commit fixes a bug in the openChannelShell function where,
instead of properly returning an error when failing to derive
the shachain root's private key, nil was returned instead. This
would lead to a panic as the channel shell was then referenced
further down in the callstack. An error is now properly returned.
2019-06-30 12:42:36 -04:00
nsa d09d514858 lnwire: include init prefix in MaxPayloadLength calculation 2019-02-07 13:19:54 -05:00
nsa a460fa92b8 lnwire: change error's MaxPayloadLength to 65535 2019-02-06 20:46:38 -05:00
nsa 7a65be7f14 lnwire: features "maxAllowedSize" fix 2019-02-06 07:02:10 -05:00
nsa d924fcfdf4 funding test: add default constraints to wallet config 2018-02-08 18:35:23 -05:00
nsa 7e84892c21 htlcswitch: account for channel reserve in Bandwidth 2018-02-08 18:35:23 -05:00
nsa 7e7516137d lnwallet: validate commited channel constraints 2018-02-08 18:35:23 -05:00