Commit Graph

12159 Commits

Author SHA1 Message Date
Wilmer Paulino
e7885f2bde
funding: add explicit commitment type negotiation support
This commit adds the ability for a channel initiator/responder to
determine whether the channel to be opened can use a specific commitment
type through explicit negotiation. It also includes the existing
implicit negotiation logic to fall back on if explicit negotiation is
not supported.
2021-08-30 19:17:34 -07:00
Wilmer Paulino
031d7b1d55
lnwire: extend RawFeatureVector with helper methods 2021-08-30 19:17:31 -07:00
Olaoluwa Osuntokun
5a9f499dd5
rpc: add new commitment_type field to OpenChannelRequest
This field will be examined later down the stack along with the set of
feature bits to determine if explicit channel commitment type
negotiation is possible or not.
2021-08-30 19:17:28 -07:00
Olaoluwa Osuntokun
d0779e2ec2
lnwire: add new feature bits for explicit channel type negotiation
If these bits are present, then both sides can examine the new
CommitmentType TLV field that's present and use this in place of the
existing implicit commiment type negotiation. With this change, it's now
possible to actually deprecate old unsupported commitment types
properly.
2021-08-30 19:17:24 -07:00
Olaoluwa Osuntokun
57b7a668c0
lnwire: add new ChannelType field as TLV record to Open/AcceptChannel
In this commit, we add a new ChannelType field as a new TLV record to
the OpenChannel message. During this change, we make a few tweaks to the
generic TLV encode/decode methods for the ExtraOpaqueData struct to have
it work on the level of tlv.RecordProducer instead of tlv.Record, as
this reduces line noise a bit.

We also partially undo existing logic that would attempt to "prepend"
any new TLV records to the end of the ExtraOpaqueData if one was already
present within the struct. This is based on the assumption that if we've
read a message from disk to order to re-send/transmit it, then the
ExtraOpaqueData is fully populated so we'll write that as is. Otherwise,
a message is being encoded for the first time, and we expect all fields
that are known TLV fields to be specified within the struct itself.

This change required the unit tests to be modified slightly, as we'll
always encode a fresh set of TLV records if none was already specified
within the struct.
2021-08-30 19:17:21 -07:00
Olaoluwa Osuntokun
988d01de0d
lnwire: introduce new explicit ChannelType TLV record
In this commit, we add a new TLV record that's intended to be used as an
explicit channel commitment type for a new form of funding negotiation,
and later on a dynamic commitment upgrade protocol. As defined, we have
3 channel types: base (the OG), tweakless, and anchors w/ zero fee
HTLCs. We omit the original variant of anchors as it was never truly
deployed from the PoV of lnd.
2021-08-30 19:17:19 -07:00
Olaoluwa Osuntokun
3b026c401c
chainntnfs/neutrinonotify: fix rebase Conflict compilation issue 2021-08-30 19:16:33 -07:00
Olaoluwa Osuntokun
844874252f
Merge pull request #5676 from ErikEk/chainnotifier-remove-error-log
chainnotifier: remove error logs
2021-08-30 18:35:12 -07:00
Olaoluwa Osuntokun
480a111c54
Merge pull request #5453 from Crypt-iQ/neutrino_conf_0629
chainntnfs: neutrinonotify patches
2021-08-30 16:04:57 -07:00
Olaoluwa Osuntokun
b9231ced2b
Merge pull request #5622 from Roasbeef/wire-serdes-optimization
peer+brontide: when decrypting re-use the allocated ciphertext buf & ensure buf pool buf doesn't escape
2021-08-30 11:45:57 -07:00
Olaoluwa Osuntokun
8339b285e7
docs/release-notes: add new brontide optimization to 0.14 notes 2021-08-27 16:57:21 -07:00
Olaoluwa Osuntokun
3e1558b616
peer: re-use buf from bufpool when decoding messages
In this commit, which builds on top of the prior commit, rather than
using the returned buffer outside of the closure (which means it'll be
copied), we instead use it within the `Submit` closure instead. With the
recent changes to the `brontide` package, we won't allocate any new
buffer when we decrypt, as a result, the `rawMsg` byte slice actually
just slices into the passed `buf` slice (obtained from the pool)`.

With this change, we ensure that the buffer pool can release the slice
back to the pool and eliminate any extra allocations along the way.
2021-08-27 16:57:15 -07:00
Olaoluwa Osuntokun
8c6dbc9ffa
brontide: when decrypting re-use the allocated ciphertext buf
In this commit, we implement a simple optimization that dramatically
reduces the number of allocations we need to make when we decrypt a new
message. Before this commit, we would pass in a `nil` value to the
`Decrypt` method which meant that it would always allocate a new
buffers.

Rather than force this behavior, in this commit, we pass in the
ciphertext buffer (with a length of zero), such that the decryption
operation will simply copy the plaintext bytes over the cipher text in
place. This works as the cipher text is always larger than the
plaintext, since the plaintext doesn't have a MAC attached.

The amount the perf increase, amount of allocations, and amount of bytes
allocated are pretty nice:
```
benchmark                        old ns/op     new ns/op     delta
BenchmarkReadHeaderAndBody-8     88652         75896         -14.39%

benchmark                        old allocs     new allocs     delta
BenchmarkReadHeaderAndBody-8     6              4              -33.33%

benchmark                        old bytes     new bytes     delta
BenchmarkReadHeaderAndBody-8     65664         128           -99.81%
```

Here old is without this change, and new with it.
2021-08-27 16:57:12 -07:00
Olaoluwa Osuntokun
02509025d5
brontide: add new benchmark to measure allocs for header+body decrypt 2021-08-27 16:57:09 -07:00
Olaoluwa Osuntokun
c93824ec9a
Merge pull request #5621 from Roasbeef/ping-pong-headers
peer: always send latest block header as part of ping messages
2021-08-27 16:55:46 -07:00
Olaoluwa Osuntokun
d9644eba84
Merge pull request #5629 from Roasbeef/priv-key-caching
keychain+lnwallet: when fetching priv keys or signing try to use cache
2021-08-27 16:51:24 -07:00
ErikEk
c68a508535 chainnotifier: remove error log 2021-08-28 00:13:37 +02:00
eugene
9f6f5e963a
docs: update release notes for 0.14 2021-08-27 14:12:02 -04:00
eugene
de71195bcb
chainntnfs/neutrinonotify: update EndHeight after filter update
After the error is received on the filter update errChan, update the
EndHeight if we're performing a historical scan. If a block was mined
after the call to RegisterConf/RegisterSpend but before the filter was
updated, then the block would not have the filter applied. This means
that a block containing the desired conf/spend parameters would be
undetected. Fix this by ensuring the historical scan also includes this
height, as it would previously not be included.
2021-08-27 14:12:02 -04:00
eugene
0d39c0799a
chainntnfs/neutrinonotify: call drainChainUpdates when updating filter
Moves filter handling logic for connecting blocks to the
connectFilteredBlock method. The disconnect logic now lives in
disconnectFilteredBlock. After updating the filter, drainChainUpdates
is called which will drain everything from the chainUpdates chan and
apply all updates by calling either connectFilteredBlock or
disconnectFilteredBlock. This will allow callers to update their
EndHeight if performing a historical dispatch, as blocks up to this
height may not have had the filter applied.
2021-08-27 14:12:01 -04:00
eugene
b7de0eae93
chainntnfs/neutrinonotify: make chainUpdates a buffered chan
ConcurrentQueue has internal structures so if a filterUpdate exists
in it, the idea of draining the queue may not work reliably. The
update may exist in the ConcurrentQueue but may not be available via
ChanOut() when we're ready to drain the ConcurrentQueue. Fix this by
using a regular buffered chan, which will either have the update or
not have the update. Its size is set to 100 as our tests may generate
quite a bit of updates.
2021-08-27 14:12:01 -04:00
eugene
86f28cdc1d
chainntnfs: skip conf dispatch if ntfn already dispatched
This mirrors the logic for the spend case. This prevents a double
dispatch scenario when combined with a later commit. Otherwise, the
confirmation would linger in the buffer which is not ideal.
2021-08-27 14:11:55 -04:00
Olaoluwa Osuntokun
abb2448718
docs/release-notes: add section w/ priv key caching in 0.14 2021-08-25 18:55:27 -07:00
Olaoluwa Osuntokun
d6524ea517
keychain+lnwallet: when fetching priv keys or signing try to use cache
In this commit, we start to optimistically use the new private key cache
that was added to btcwallet. As is, btcwallet will cache the decrypted
account keys for each scope in memory. However, the existing methods
to derive a child key from those account keys requires a write database
transaction, and will re-derive the private key using BIP-32 each time.

The newly added `DeriveFromKeyPathCache` lets us skip all this and
directly use a cache assuming the account info is already cached. The
new logic will try to use this method, but if it fails fall back to the
existing `DeriveFromKeyPath` method. All calls after this will use this
new cached key.

Fixes https://github.com/lightningnetwork/lnd/issues/5125.

Basic benchmark before the btcwallet change and after:
```
benchmark                    old ns/op     new ns/op     delta
BenchmarkDerivePrivKey-8     22840583      125           -100.00%

benchmark                    old allocs     new allocs     delta
BenchmarkDerivePrivKey-8     89             2              -97.75%

benchmark                    old bytes     new bytes     delta
BenchmarkDerivePrivKey-8     10225         24            -99.77%
```
2021-08-25 18:55:22 -07:00
Olaoluwa Osuntokun
2206eba91a
build: point to latest btcwallet w/ new cached privkey method 2021-08-25 18:55:19 -07:00
Olaoluwa Osuntokun
df11b0fed0
keychain: add basic benchmark for privkey derivation 2021-08-25 18:55:16 -07:00
Olaoluwa Osuntokun
8fd14bc458
docs/release-notes: add notes for new ping header in 0.14 2021-08-25 16:47:23 -07:00
Olaoluwa Osuntokun
00d275d9f0
lnrpc+rpc: expose last ping message received by peer over ListPeers resp 2021-08-25 16:47:17 -07:00
Olaoluwa Osuntokun
2947076607
peer: store the last ping payload received by a remote peer in an atomic var 2021-08-25 16:47:13 -07:00
Olaoluwa Osuntokun
4287e25494
peer: add message summaries for ping+pong 2021-08-25 16:47:10 -07:00
Olaoluwa Osuntokun
d566e51a52
peer: always send latest block header as part of ping messages
In this commit, we implement a long discussed mechanism to use the
Lightning Network as a redundant block header source. By sending our
latest block header with each ping message, we give peers another source
(outside of the Bitcoin P2P network) they can use to spot check their
chain state. Peers can also use this information to detect if they've
been eclipsed from the traditional Bitcoin P2P network itself.

As is, we only send this data in Ping messages (which are periodically
sent), in the future we could also move to send them as the partial
payload for our pong messages, and also randomize the payload size
requested as well.
2021-08-25 16:47:07 -07:00
Olaoluwa Osuntokun
0d8ffd95dd
chainntnfs/test: add new test assertion to ensure block epoch headers set 2021-08-25 16:47:04 -07:00
Olaoluwa Osuntokun
67aa7a0df7
chainntnfs/bitcoindnotify: always populate block headers for block epochs 2021-08-25 16:47:01 -07:00
Olaoluwa Osuntokun
b2cc4cf088
chainntnfs/btcdnotify: always populate block headers for block epochs 2021-08-25 16:46:59 -07:00
Olaoluwa Osuntokun
99afad1105
chainntnfs/neutrinonotify: always populate block headers for block epochs 2021-08-25 16:46:56 -07:00
Olaoluwa Osuntokun
4eac8577cd
chainntnfs: update impl independent functions to populate new block header 2021-08-25 16:46:53 -07:00
Olaoluwa Osuntokun
4fc6d15075
chainntnfs: add the current block header to the block epoch struct 2021-08-25 16:46:51 -07:00
Oliver Gugger
93d12cd9fc
Merge pull request #5643 from bottlepay/updatepolicy-nested-tx
routing/localchans: fix nested db tx
2021-08-24 17:42:39 +02:00
Oliver Gugger
ed5a3416bc
Merge pull request #5623 from yyforyongyu/update-contrib-guide
docs: explicitly set line wrap rules for error messages [skip ci]
2021-08-24 17:29:18 +02:00
Oliver Gugger
2835cebe90
Merge pull request #5659 from guggero/unit-test-race-fix
multi: fix unit test for high CPU load envs
2021-08-24 15:16:28 +02:00
Oliver Gugger
998abd1886
Merge pull request #5657 from ErikEk/releasedoc-fix
docs: release note fix
2021-08-24 14:00:45 +02:00
Joost Jager
bd07b5f49e
routing/localchans: fix nested db tx
This commit fixes a bug where a db tx is opened within another db tx.
2021-08-24 13:43:26 +02:00
Joost Jager
3f775778c3
channeldb+routing: add tx parameter
Adds an optional tx parameter to ForAllOutgoingChannels and FetchChannel
so that data can be queried within the context of an existing database
transaction.
2021-08-24 13:43:24 +02:00
Oliver Gugger
1f3a6e101d
multi: fix unit test for high CPU load envs
It seems that the GitHub CI runners share a CPU and therefore only have
very few ressources available. This causes the wallet unlocker and breach
arbiter tests to fail if we don't give them enough time to complete.
2021-08-24 13:03:21 +02:00
Oliver Gugger
23cd231483
Merge pull request #4717 from guggero/xprv-wallet-init
walletunlocker: Allow wallet to be created from extended master root key (xprv)
2021-08-24 13:01:41 +02:00
Oliver Gugger
c74c46147f
Merge pull request #5646 from yyforyongyu/fix-context-leak
itest: properly handle the creation of timeout context
2021-08-24 10:44:36 +02:00
Oliver Gugger
648374ec2a
Merge pull request #5354 from ErikEk/itest-include-btcd-backend-rotation-logs
itest: include compressed btcd backend logs from logrotate
2021-08-24 10:40:01 +02:00
Oliver Gugger
8632fc9233
docs: update release notes 2021-08-24 10:37:34 +02:00
Oliver Gugger
0822573743
itest: test wallet recovery from extended master root key
We add an additional test case to the on-chain fund recovery test that
tries restoring the same wallet from the extended master root key
instead of the seed.
2021-08-24 10:37:34 +02:00
Oliver Gugger
3fd944e7e4
lntest: allow node restore by extended root key
To allow testing restoring a node from an extended master root key, we
add an extra argument to the RestoreNodeWithSeed function.
2021-08-24 10:37:33 +02:00