Commit Graph

217 Commits

Author SHA1 Message Date
Elle Mouton
fe3a862ec3 autopilot: revert passing ctx to Start methods 2025-06-04 10:54:36 +02:00
Elle Mouton
2f99706fa1 multi: remove kvdb.RTx from ForEachNodeChannel
Since we have not removed all call-sites that make use of this
parameter, we can remove it. This helps hide DB-specific details from
the interface we will introduce for the graph store.
2025-06-04 10:54:35 +02:00
Elle Mouton
1507a7fcc7 autopilot: update AttachmentHeuristics with context
Continue threading context through the autopilot system and remove the
remaining context.TODOs.
2025-06-04 10:54:34 +02:00
Elle Mouton
46f09ba1ff autopilot: continue threading context
Remove one context.TODO and add one more.
2025-06-04 10:54:34 +02:00
Elle Mouton
cd4a59071d autopilot: start threading contexts through
The `GraphSource` interface in the `autopilot` package is directly
implemented by the `graphdb.KVStore` and so we will eventually thread
contexts through to this interface. So in this commit, we start updating
the autopilot system to thread contexts through in preparation for
passing the context through to any calls made to the GraphSource.

Two context.TODOs are added here which will be addressed in follow up
commits.
2025-06-04 10:54:34 +02:00
Elle Mouton
2221aaa889 graph/db: move Topology client management to ChannelGraph
We plan to later on add an option for a remote graph source which will
be managed from the ChannelGraph. In such a set-up, a node would rely on
the remote graph source for graph updates instead of from gossip sync.
In this scenario, however, our topology subscription logic should still
notify clients of all updates and so it makes more sense to have the
logic as part of the ChannelGraph so that we can send updates we receive
from the remote graph.
2025-03-24 15:05:48 +02:00
Elle Mouton
b497c4694e multi: add Start and Stop methods for ChannelGraph
We do this in preparation for moving channel cache population logic out
of the constructor and into the Start method. We also will later on
(when topology subscription is moved to the ChannelGraph), have a
goroutine that will need to be kicked off and stopped.
2025-03-24 15:05:47 +02:00
Elle Mouton
00432e46f3 multi: add ChannelGraph Config struct
And use this struct to pass NewChannelGraph anything it needs to be able
to init the KVStore that it houses. This will allow us to add
ChannelGraph specific options.
2025-03-24 15:05:46 +02:00
Oliver Gugger
fa10991545 multi: fix linter by updating to latest version 2025-02-17 10:40:55 +01:00
Oliver Gugger
d10ab03b75 Merge pull request #9480 from ellemouton/autopilotRefactor
graph+autopilot: remove `autopilot` access to raw `graphdb.ChannelGraph`
2025-02-10 09:07:47 -06:00
Elle Mouton
e7988a2c2b autopilot: remove access to *graphdb.ChannelGraph
Define a new GraphSource interface that describes the access required by
the autopilot server. Let its constructor take this interface instead of
a raw pointer to the graphdb.ChannelGraph.
2025-02-10 09:46:15 +02:00
Elle Mouton
9b86ee53db graph+autopilot: let autopilot use new graph ForEachNode method
Which passes a NodeRTx to the call-back instead of a `kvdb.RTx`.
2025-02-10 09:46:15 +02:00
Elle Mouton
3e5d807773 autopilot: add testDBGraph type
Introduce a new type for testing code so the main databaseChannelGraph
type does not need to make various write calls to the
`graphdb.ChannelGraph` but the new testDBGraph type still can for tests.
2025-02-10 08:17:37 +02:00
Elle Mouton
1184c9eaf8 autopilot: move tests code to test files
This is a pure code move commit where we move any code that is only ever
used by tests to test files. Many of the calls to the
graphdb.ChannelGraph pointer are only coming from tests code.
2025-02-10 08:16:34 +02:00
Eng Zer Jun
0899cee987 refactor: replace min/max helpers with built-in min/max
We can use the built-in `min` and `max` functions since Go 1.21.

Reference: https://go.dev/ref/spec#Min_and_max
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-02-06 09:45:10 +08:00
Elle Mouton
4089fbcb44 multi: fix linter errors 2024-11-28 13:51:15 +02:00
Elle Mouton
6e13898981 multi: move LightningNode struct to models package 2024-11-28 13:36:32 +02:00
Elle Mouton
b86980ec40 channeldb: remove graph db from channeldb
Now that the channel.DB no longer uses the ChannelGraph pointer, we can
completely remove it as a member of channeldb.DB.
2024-11-28 13:36:15 +02:00
Elle Mouton
74a4b1922b refactor: move graph related DB code to graph/db from channeldb
This is a pure refactor commit. It moves over all the graph related CRUD
code from `channeldb` to `graph/db`.
2024-11-28 13:36:13 +02:00
Elle Mouton
9f54ec90aa multi+refactor: move models package to graph/db
All the structs defined in the `channeldb/models` package are graph
related. So once we move all the graph CRUD code to the graph package,
it makes sense to have the schema structs there too. So this just moves
the `models` package over to `graph/db/models`.
2024-11-28 13:34:33 +02:00
Elle Mouton
23602e017e multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
Elle Mouton
7f1be39d45 refactor: move various duties from ChannelRouter to graph.Builder
This commit is a large refactor that moves over various responsibilities
from the ChannelRouter to the graph.Builder. These include all graph
related tasks such as:
- graph pruning
- validation of new network updates & persisting new updates
- notifying topology update clients of any changes.

This is a large commit but:
- many of the files are purely moved from `routing` to `graph`
- the business logic put in the graph Builder is copied exactly as is
  from the ChannelRouter with one exception:
- The ChannelRouter just needs to be able to call the Builder's
  `ApplyChannelUpdate` method. So this is now exported and provided to
the ChannelRouter as a config option.
- The trickiest part was just moving over the test code since quite a
  bit had to be duplicated.
2024-07-15 15:56:33 +02:00
Elle Mouton
e9c89ae0ec multi+refactor: create ForEachNodeChannel with no tx param
In prep for a clean Graph DB interface, we add a version of
ForEachNodeChannel that does not take in an existing db transaction.
2024-07-15 15:13:58 +02:00
Elle Mouton
c20d759d41 refactor: create FetchLightningNode with no tx param
In preparation for adding a clean Graph DB interface, we create a
version of FetchLightningNode that doesnt allow a caller to provide in a
transaction.
2024-07-15 15:13:57 +02:00
Oliver Gugger
3d56ffd0e4 Merge pull request #8662 from fuyangpengqi/master
chore: fix function names in comment
2024-04-29 15:10:20 +02:00
fuyangpengqi
5f22d97b51 chore: fix function names in comment
Signed-off-by: fuyangpengqi <995764973@qq.com>
2024-04-27 00:04:09 +08:00
hidewrong
8afb978c81 chore: fix struct names
Signed-off-by: hidewrong <hidewrong@outlook.com>
2024-04-17 11:19:31 +08:00
Oliver Gugger
648fb22f63 multi: wrap all errors 2024-04-11 15:04:03 +02:00
ffranr
cd566eb097 multi: fix fmt.Errorf error wrapping
Refactor fmt.Errorf usage to correctly wrap errors instead of using
non-wrapping format verbs.
2024-02-27 11:13:40 +00:00
Elle Mouton
84cdcd6847 multi: move DB schemas to channeldb/models
This commit moves the ChannelEdgePolicy, ChannelEdgeInfo,
ChanelAuthProof and CachedEdgePolicy structs to the `channeldb/models`
package.
2023-11-08 14:50:35 +02:00
Elle Mouton
3a17479ff4 multi: remove LightningNode from ChannelEdgePolicy
Finally, The LightningNode object is removed from ChannelEdgePolicy.
This is a step towards letting ChannelEdgePolicy reflect exactly the
schema that is on disk.

This is also nice because the `Node` object is not necessarily always
required when the ChannelEdgePolicy is loaded from the DB, so now it
only get's loaded when needed.
2023-11-08 14:50:34 +02:00
Elle Mouton
6c76d31e89 multi: let FetchLightningNode take an optional tx
In preparation for the next commit which will remove the
`*LightningNode` from the `ChannelEdgePolicy` struct,
`FetchLightningNode` is modified to take in an optional transaction so
that it can be utilised in places where a transaction exists.
2023-11-08 14:50:34 +02:00
Elle Mouton
d37f5d7e1a autopilot: use pointer receivers for dbNode methods 2023-11-08 14:50:21 +02:00
Elle Mouton
fa7c1e250b multi: let ForEachChannel be a method on ChannelGraph
Having a `ForEachChannel` method on the `LightningNode` struct itself
results in a `kvdb.Backend` object needing to be stored within the
LightningNode struct. In this commit, this method is replaced with a
`ForEachNodeChannel` method on the `ChannelGraph` struct will perform
the same function without needing the db pointer to be stored within the
LightningNode. This change, the LightningNode struct more closely
represents the schema on disk.

The existing `ForEachNodeChannel` method on `ChannelGraph` is renamed to
`ForEachNodeDirectedChannel`. It performs a slightly different function
since it's call-back operates on Cached policies.
2023-11-08 10:51:50 +02:00
Michael Rooke
78d9996620 trivial: Fix spelling errors
- Fixes some spelling in code comments and a couple of function names
2023-09-21 22:35:33 -04:00
Oliver Gugger
8d6befd797 autopilot: fix loop variables, use require
With this commit we fix a few occurrences of loop variables being
accessed in closures.
While we touch the code, we also migrate it to using the require
library.
2022-10-13 14:40:43 +02:00
Eng Zer Jun
1dcc7d74e6 autopilot: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:01:31 +08:00
ErikEk
6146b8d644 trivial typo[skip ci] 2022-07-01 11:21:46 +02:00
Oliver Gugger
8451d6155f Merge pull request #6504 from tvolk131/fatalf_to_require
Move simple t.Fatalf test assertions to require.NoError
2022-06-17 19:52:07 +02:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Oliver Gugger
ed40eddafd autopilot: return early for empty graph
This fixes an issue where the diameter calculation would crash if the
graph is empty.
2022-06-16 10:10:27 +02: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
bitromortac
45a2dc80c8 autopilot: implement cached ChannelGraph
Using the cached implementation of a ChannelGraph greatly speeds up the
conversion of the channel database to a SimpleGraph.
2022-03-07 11:15:47 +01:00
bitromortac
52d56a8990 lnrpc+autopilot: add graph diameter calculation
* adds a brute force computation of the diameter
* adds a more efficient calculation of the diameter
2022-03-07 11:15:47 +01:00
Oliver Gugger
dfdc2bff8b multi: run gosimports 2022-02-10 11:02:01 +01:00
Dimitris Apostolou
530a2059e5 multi: Fix typos [skip ci] 2022-01-24 12:19:02 +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
14c851c8fc kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
yyforyongyu
e3a6cd8412 autopilot: fix typo 2020-12-04 23:07:52 +08:00
Conner Fromknecht
1b97bcdac1 Merge pull request #4783 from yyforyongyu/autopilot-code-fix
autopilot: fix returned map size in mergeNodeMaps
2020-11-19 11:10:48 -08:00