Commit Graph

236 Commits

Author SHA1 Message Date
Elle Mouton
8aa8c7cc42 multi: remove the NodeRTx interface type 2025-08-06 09:56:21 +02:00
Elle Mouton
699e335954 autopilot: remove the ForEachChannel method from Node interface
And instead make use of the new ForEachNodesChannels method which
uses a much more efficient method for iterating through nodes&channels.
2025-08-06 09:52:09 +02:00
Elle Mouton
ce7fe84da7 autopilot: add ForEachNodesChannels method to ChannelGraph interface
This is in preparation for removing the ForEachChannel method from the
Node interface.
2025-08-06 09:50:58 +02:00
Elle Mouton
5727bfa688 graph/db: let ForEachNodeCached maybe fetch node addresses
Here we adjust the ForEachNodeCached graph DB method to pass in a node's
addresses into the provided call-back if requested. This will allow us
to improve the performance of node/channel iteration in the autopilot
subserver.
2025-08-06 09:50:54 +02:00
Elle Mouton
ae566744c4 graph/db+autopilot: remove NodeRTx FetchNode method
In this commit, we remove the need for the NodeRTx interface to have the
FetchNode method on it.
2025-08-05 09:59:13 +02:00
Elle Mouton
70b8c8ec78 autopilot: convert Peer to route.Vertex
In preparation for removing the ForEachNode/ForEachChannel call pattern,
we refactor the autopilot subserver by simplifying the `ChannelEdge`
such that it no longer returns the `Node` type which has a
`ForEachChannel` method on it. The aim is to completely remove the
`ForEachChannel` usage.
2025-08-05 09:59:12 +02:00
Elle Mouton
21ac7ef6f4 multi: add reset to ForEachNode 2025-07-15 11:25:09 +02:00
Elle Mouton
c32bf642d2 multi: pass reset to ForEachNodeCached 2025-07-15 11:23:27 +02:00
Elle Mouton
e5fbca8299 multi: let ForEachNodeChannel take a reset param 2025-07-15 11:23:27 +02:00
Elle Mouton
3d5e852c8c graph/db: let ForEachNodeCached take a context 2025-07-08 15:11:02 +02:00
Elle Mouton
1e804a3d5f graph/db: let ForEachNode take a context 2025-07-08 15:11:02 +02:00
Elle Mouton
f8d3a3f3ba graph/db: let ForEachNodeChannel take a context 2025-07-08 15:10:30 +02:00
Elle Mouton
2f2845dfc0 refactor+multi: use *lnwire.FeatureVector for ChannelEdgeInfo features
In this commit, we move the serialisation details of a channel's
features to the DB layer and change the `models` field to instead use a
more useful `*lnwire.FeatureVector` type.

This makes the features easier to work with and moves the serialisation
to where it is actually used.
2025-07-01 17:02:07 +02:00
Elle Mouton
81c063eb96 graph/db: thread context through to UpdateEdgePolicy 2025-06-19 14:49:31 +02:00
Elle Mouton
3fdb9b84f4 graph/db: thread context to AddChannelEdge 2025-06-19 14:47:41 +02:00
Elle Mouton
66c5a97202 graph/db: thread context through to FetchLightingNode 2025-06-17 19:20:27 +02:00
Elle Mouton
d1cfb47428 graph/db: thread context to AddLightningNode 2025-06-17 19:20:27 +02:00
Elle Mouton
dc353dc50e multi: use MakeTestGraph everywhere for test graph creation
In this commit, we unify how all unit tests that make use of the graph
create their test ChannelGraph instance. This will make it easier to
ensure that once we plug in different graph DB implementations, that all
unit tests are run against all variants of the graph DB.

With this commit, `NewChannelGraph` is mainly only called via
`MakeTestGraph` for all tests _except_ for `TestGraphLoading` which
needs to be able to reload a ChannelGraph with the same backend. This
will be addressed in a follow-up commit once more helpers are defined.

Note that in all previous packages where we created a test graph using
`kvdb.GetBoltBackend`, we now need to add a `TestMain` function with a
call to `kvdb.RunTest` since the `MakeTestGraph` helper uses
`GetTestBackend` instead of `kvdb.GetBoltBackend` which requires an
embedded postgres instance to be running.
2025-05-22 14:14:42 +02:00
Elle Mouton
526fb7f181 graph/db: init KVStore outside of ChannelGraph
So that we can pass in the abstract V1Store in preparation for adding a
SQL implementation of the KVStore.
2025-05-22 14:14:40 +02:00
Elle Mouton
95d34be0d3 autopilot: revert passing ctx to Start methods 2025-05-22 14:14:40 +02:00
Elle Mouton
da3deeee7c 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-05-22 14:14:39 +02:00
Elle Mouton
3f218dfbbe autopilot: update AttachmentHeuristics with context
Continue threading context through the autopilot system and remove the
remaining context.TODOs.
2025-05-22 14:14:38 +02:00
Elle Mouton
1c6c6436af autopilot: continue threading context
Remove one context.TODO and add one more.
2025-05-22 14:14:38 +02:00
Elle Mouton
13fcb08794 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-05-22 14:14:38 +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