Commit Graph

177 Commits

Author SHA1 Message Date
eugene
d807ff23d2
channeldb: fix DisconnectBlockAtHeight bug for zero-conf channels
When a block is disconnected due to a reorg, DisconnectBlockAtHeight
is called for the block height. Prior to this patch, it would delete
every SCID in the graph with a block height greater than the
disconnected height. This meant that a reorg would delete every
zero-conf channel edge from the graph. The fix simply iterates up
until the StartingAlias and deletes every SCID between the
disconnected height and the StartingAlias height.
2023-01-25 12:03:21 -05:00
eugene
1aa9626606
server+funding: allow scid-alias, zero-conf chantypes, scid-alias
feature-bit channels

This allows opening zero-conf chan-type, scid-alias chan-type, and
scid-alias feature-bit channels. scid-alias chan-type channels are
required to be private. Two paths are available for opening a zero-conf
channel:

* explicit chan-type negotiation
* LDK carve-out where chan-types are not used, LND is on the
  receiving end, and a ChannelAcceptor is used to enable zero-conf

When a zero-conf channel is negotiated, the funding manager:
* sends a FundingLocked with an alias
* waits for a FundingLocked from the remote peer
* calls addToRouterGraph to persist the channel using our alias in
  the graph. The peer's alias is used to send them a ChannelUpdate.
* wait for six confirmations. If public, the alias edge in the
  graph is deleted and replaced (not atomically) with the confirmed
  edge. Our policy is also read-and-replaced, but the counterparty's
  policy won't exist until they send it to us.

When a scid-alias-feature channel is negotiated, the funding manager:
* sends a FundingLocked with an alias:
* calls addToRouterGraph, sends ChannelUpdate with the confirmed SCID
  since it exists.
* when six confirmations occurs, the edge is deleted and re-inserted
  since the peer may have sent us an alias ChannelUpdate that we are
  storing in the graph.

Since it is possible for a user to toggle the scid-alias-feature-bit
to on while channels exist in the funding manager, care has been taken
to ensure that an alias is ALWAYS sent in the funding_locked message
if this happens.
2022-07-07 17:10:28 -04:00
eugene
01f28ba540
server+discovery: alias-handling in gossiper
An OptionalMsgField has been added that allows outside subsystems
to provide a short channel id we should insert into a ChannelUpdate
that we then sign and send to our peer.

When the gossiper receives a ChannelUpdate, it will query the
alias manager by the passed-in FindBaseByAlias function to determine
if the short channel id in the ChannelUpdate points to a known
channel. If this lookup returns an error, we'll fallback to using
the original id in the ChannelUpdate when querying the router.
The lookup and potential fallback must occur in order to properly
lock the multimutex, query the correct router channels, and rate
limit the correct short channel id. An unfortunate side effect of
receiving ChannelUpdates from our peer that reference on of our
aliases rather than the real SCID is that we must store this policy.
Yet it is not broadcast-able. Care has been taken to ensure the
gossiper does not broadcast *any* ChannelUpdate with an alias SCID.

The cachedNetworkMsg uses the new processedNetworkMsg struct. This
is necessary so that delete-and-reinsert in the funding manager
doesn't process a ChannelUpdate twice and end up in a deadlock since
the err chan is no longer being used.
2022-07-07 17:10:28 -04:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Joost Jager
352008a0c2
channeldb: speed up graph cache loading
Use the optimized ForEachChannel method to reduce the graph cache
loading time.
2022-01-14 14:57:29 +01:00
Joost Jager
2e2229a2e7
channeldb: reallocate node in ForEachNodeCacheable
Allows cacheableNode to be used outside of the callback. This is a
preparation for optimization of the graph cache population.
2022-01-14 14:57:27 +01:00
Joost Jager
cb4703638f
channeldb: optimize ForEachChannel
In this commit, we modify the implementation of ForEachChannel to
utilize the new kvdb method ForAll. This greatly reduces the number of
round-trips to the database needed to iterate over all channels
in the graph.
2022-01-14 14:57:25 +01:00
Joost Jager
54324d554a
channeldb: extract deserializeChanEdgePolicyRaw
Allows for pure deserialization without depending on a database connection.
2022-01-12 19:11:56 +01:00
naveen
87a0e52464
multi: Removed deprecated interfacer linter
Removed the deprecated interfacer linter from being called for linting.

Also removed the `nolint:interfacer` within the code.

https://github.com/lightningnetwork/lnd/issues/5741
2022-01-11 14:08:18 +01:00
naveen
545e84f4ce
multi: formatting changes 2022-01-11 14:08:17 +01:00
Oliver Gugger
b147d589c1
channeldb: add NoMigration mode
In case the channeldb package is used as a library in external tools, it
can be useful to allow read-only access to a DB. This allows such a
tool to access a DB even if not all migrations were executed, which can
be useful for recovery purposes.
To make it possible to even start the DB with a read-only backend, we
need to disable the automatic migration step.
2021-12-13 12:31:49 +01:00
Olaoluwa Osuntokun
fae470293f
channeldb: add new ForEachNode method using the channel graph cache
This commit, adds a new ForEachNode method to the channel graph cache
that assumes the contents won't be modified. This is generally useful,
and will be used in a later commit to optimize some heavy RPC calls.
2021-11-04 15:30:25 -07:00
Andras Banki-Horvath
ea5d43a2a8
channeldb: fix crash when inbound policy is unset 2021-11-02 20:18:58 -07:00
Oliver Gugger
0a2ccfc52b
multi: use single read transaction for path finding
This commit partially reverts bf27d05a.
To avoid creating multiple database transactions during a single path
finding operation, we create an explicit transaction when the cached
graph is instantiated.
We cache the source node to avoid needing to look that up for every path
finding session.
The database transaction will be nil in case of the in-memory graph.
2021-10-22 09:32:49 +02:00
Oliver Gugger
1fef2970cf
channeldb: implement DB fallback for path finding
If the in-memory graph cache is disabled, we fall back to querying the
database.
2021-10-22 09:32:48 +02:00
Oliver Gugger
f216da32f3
lnd+channeldb: add graph cache option to channeldb
With this commit we forward the config option for disabling the channel
graph cache as a boolean to the channeldb. But we invert its meaning to
make the flag easier to understand.
2021-10-22 09:32:48 +02:00
Oliver Gugger
77bf6cfed3
channeldb: fix graph cache feature handling [skip ci]
Fixes #5830.
When a channel for a node is announced before the node itself is
announced on the network, it's possible that we have channels for a node
but no features defined yet. This was previously logged as a warning
which spammed the log unnecessarily.
2021-10-08 10:02:11 +02:00
Oliver Gugger
6240851f93
channeldb: optimize memory usage of initial cache fill
With this commit we use an optimized version of the node iteration that
causes fewer memory allocations by only loading the part of the graph
node that we actually need to know for the cache.
2021-09-29 17:00:06 +02:00
Oliver Gugger
a95a3728b5
lnd+channeldb: pre-allocate cache size
To avoid the channel map needing to be re-grown while we fill the cache
initially, we might as well pre-allocate it with a somewhat sane value
to decrease the number of grow events.
2021-09-29 17:00:05 +02:00
Oliver Gugger
1d1c42f9ba
multi: use minimal policy in cache 2021-09-29 17:00:04 +02:00
Oliver Gugger
15d3f62d5e
multi: use cache for source channels 2021-09-29 17:00:04 +02:00
Joost Jager
369c09be61
channeldb+routing: add in-memory graph
Adds an in-memory channel graph cache for faster pathfinding.

Original PoC by: Joost Jager
Co-Authored by: Oliver Gugger
2021-09-29 17:00:04 +02:00
Oliver Gugger
d6fa912188
multi: further decouple graph
To further separate the channel graph from the channel state, we
refactor the AddrsForNode method to use the graphs's public methods
instead of directly accessing any buckets. This makes sure that we can
have the channel state cached with just its buckets while not using a
kvdb level cache for the graph.
At the same time we refactor the graph's test to also be less dependent
upon the channel state DB.
2021-09-29 17:00:03 +02:00
Andras Banki-Horvath
639faeed6d
channeldb: use kvdb.Backend instead of channeldb.DB for the Graph 2021-09-29 17:00:01 +02:00
Oliver Gugger
482f76a0f4
mod+kvdb+channeldb: use btcwallet new DB interface
Depends on btcsuite/btcwallet#757.
Pulls in the updated version of btcwallet and walletdb that have the DB
interface enhanced by their own View() and Update() methods with the
reset callback/closure supported out of the box. That way the global
package-level View() and Update() functions now become pure redirects.
2021-08-04 14:55:55 +02:00
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Olaoluwa Osuntokun
7b42ad0b0e
channeldb: add new method for adhoc zombie chan creation
In this commit, we add a new method that allows us to mark a channel as
being a zombie on the fly without needing to go through the normal
channel deletion process.
2021-05-03 19:06:45 -07:00
Olaoluwa Osuntokun
7b589e5811
routing: add strict zombie pruning as a config level param
In this commit, we add strict zombie pruning as a config level param.
This allow us to add the option for those that want a tighter graph, and
not change the default composition of the channel graph for most users
over night.

In addition, we expand the test case slightly by testing that the self
node won't be pruned, but also that if there's a node with only a single
known stale edge, then both variants will prune that edge.
2021-04-21 13:56:27 -05:00
Conner Fromknecht
672dbe39e7
channeldb/graph: only set laggard zombie pubkey 2021-04-21 13:56:19 -05:00
Johan T. Halseth
b5d6d7b4fd
channeldb: add SchedulerOp arg to graph update methods 2021-02-10 23:54:03 +01:00
Wilmer Paulino
a4f33ae63c
discovery: adhere to proper channel chunk splitting for ReplyChannelRange 2020-12-08 15:18:07 -08:00
Olaoluwa Osuntokun
7e298f1434
Merge pull request #3367 from cfromknecht/batched-graph-updates
Batched graph updates
2020-11-25 18:40:40 -08:00
Conner Fromknecht
82a238317c
lncfg+itest: expose configurable batch-commit-interval
This will permit a greater degree of tuning or customization depending
on various hardware/environmental factors.
2020-11-25 16:45:25 -08:00
Wilmer Paulino
791ba3eb50
discovery: rate limit incoming channel updates
This change was largely motivated by an increase in high disk usage as a
result of channel update spam. With an in memory graph, this would've
gone mostly undetected except for the increased bandwidth usage, which
this doesn't aim to solve yet. To minimize the effects to disks, we
begin to rate limit channel updates in two ways. Keep alive updates,
those which only increase their timestamps to signal liveliness, are now
limited to one per lnd's rebroadcast interval (current default of 24H).
Non keep alive updates are now limited to one per block per direction.
2020-11-25 15:38:08 -08:00
Conner Fromknecht
edaa5d4308
channeldb/graph: add batched APIs for graph ingestion 2020-11-24 16:39:28 -08:00
Conner Fromknecht
9cfe08c879
channeldb/graph: split out cache updates for policy changes 2020-11-24 16:38:40 -08:00
Andras Banki-Horvath
d89f51d1d0
multi: add reset closure to kvdb.Update
Similarly as with kvdb.View this commits adds a reset closure to the
kvdb.Update call in order to be able to reset external state if the
underlying db backend needs to retry the transaction.
2020-11-05 17:57:12 +01:00
Andras Banki-Horvath
2a358327f4
multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will
be called before each retry (including the first) of the view
transaction. The reset() closure can be used to reset external state
(eg slices or maps) where the view closure puts intermediate results.
2020-11-05 17:57:12 +01:00
Conner Fromknecht
455ddfebdb
multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Conner Fromknecht
90d3bf532d
channeldb+routing: remove tx arg for ForEachNode 2020-05-12 17:53:20 -07:00
Andras Banki-Horvath
556e3525ea misc: fix error formatting in multiple files 2020-04-24 19:15:08 +02:00
Olaoluwa Osuntokun
a4e39906b1
build: silence new linter errors, tidy modules
The explicit `bbolt` dep is gone, as we depend on `kvdb`, which is
actually `walletdb`, which has its own module that defines the proper
`bbolt` version.
2020-03-18 19:35:29 -07:00
Olaoluwa Osuntokun
f0911765af
channeldb: convert to uniformly use new kvdb abstractions
In this commit, we migrate all the code in `channeldb` to only reference
the new `kvdb` package rather than `bbolt` directly.

In many instances, we need to add two version to fetch a bucket as both
read and write when needed. As an example, we add a new
`fetchChanBucketRw` function. This function is identical to
`fetchChanBucket`, but it will be used to fetch the main channel bucket
for all _write_ transactions. We need a new method as you can pass a
write transaction where a read is accepted, but not the other way around
due to the stronger typing of the new `kvdb` package.
2020-03-18 19:34:49 -07:00
Joost Jager
95ddab57fa
channeldb: add tx argument for FetchLightningNode
To allow execution within an existing tx.
2019-12-20 10:17:01 +01:00
Joost Jager
37d9ee302c
channeldb: take serialized key to fetch lightning node
This prevents inefficient key conversions in a follow up commit that
change the inner pathfinding loop.
2019-12-19 12:44:00 +01:00
Conner Fromknecht
80802d8e84
channeldb/graph: always populate LightningNode features
Previously we would return nil features when we didn't have a node
announcement or a given node. With this change, we can always assume the
feature vector is populated during pathfinding.
2019-12-18 23:53:05 -08:00
Joost Jager
d8fd6fae23
config+channeldb: describe min_htlc fields more accurately 2019-12-11 00:16:55 +01:00
Conner Fromknecht
5e27b5022c
multi: remove LocalFeatures and GlobalFeatures 2019-11-08 05:32:00 -08:00