Commit graph

34 commits

Author SHA1 Message Date
Oliver Gugger
0e87863481
Merge pull request #9523 from ellemouton/graph9
graph/db: use View directly instead of manual DB tx creation and commit
2025-02-19 01:55:18 -06:00
Oliver Gugger
31418e4b85
Merge pull request #9525 from ellemouton/graph10
graph: Restrict interface to update channel proof instead of entire channel
2025-02-18 11:34:38 -06:00
Elle Mouton
9df8773163
graph: update proof by ID
This commit restricts the graph CRUD interface such that one can only
add a proof to a channel announcement and not update any other fields.
This pattern is better suited for SQL land too.
2025-02-18 11:05:28 -03:00
Elle Mouton
e58abbf0e5
graph/db: fix edges bucket check
This commit fixes a bug that would check that the passed `edge` argument
of UpdateChannelEdge is nil but it should actually be checking if the
`edges` bucket is nil.
2025-02-18 11:04:27 -03:00
Elle Mouton
03899ab1f9
graph/db: use View directly instead of manual Tx handling
In this commit, we use the available kvdb `View` method directly for
starting a graph session instead of manually creating and commiting the
transaction. Note this changes behaviour since failed tx create/commit
will now error instead of just log.
2025-02-18 10:18:55 -03:00
Elle Mouton
f3805002ff
graph/db: unexport methods that take a transaction
Unexport and rename the methods that were previously used by the
graphsession package.
2025-02-18 10:15:55 -03:00
Elle Mouton
e004447da6
multi: remove the need for the graphsession package
In this commit, we add a `GraphSession` method to the `ChannelGraph`.
This method provides a caller with access to a `NodeTraverser`. This is
used by pathfinding to create a graph "session" overwhich to perform a
set of queries for a pathfinding attempt. With this refactor, we hide
details such as DB transaction creation and transaction commits from the
caller. So with this, pathfinding does not need to remember to "close
the graph session". With this commit, the `graphsession` package may be
completely removed.
2025-02-18 10:15:41 -03:00
Elle Mouton
99c9440520
graph/db: define a NodeTraverser interface
Which describes methods that will use the graph cache if it is available
for fast read-only calls.
2025-02-18 10:10:04 -03:00
Elle Mouton
8ec08fbfa4
multi: remove the need for NewRoutingGraph
The `graphsession.NewRoutingGraph` method was used to create a
RoutingGraph instance with no consistent read transaction across calls.
But now that the ChannelGraph directly implements this, we can remove
The NewRoutingGraph method.
2025-02-18 07:59:57 -03:00
Elle Mouton
971832c792
graph: temporarily rename some ChannelGraph methods
Add the `Tx` suffix to both ForEachNodeDirectedChannelTx and
FetchNodeFeatures temporarily so that we free up the original names for
other use. The renamed methods will be removed or unexported in an
upcoming commit. The aim is to have no exported methods on the
ChannelGraph that accept a kvdb.RTx as a parameter.
2025-02-18 07:59:57 -03:00
Elle Mouton
9068ffcd8b
graph: let FetchNodeFeatures take an optional read tx
For consistency in the graphsessoin.graph interface, we let the
FetchNodeFeatures method take a read transaction just like the
ForEachNodeDirectedChannel. This is nice because then all calls in the
same pathfinding transaction use the same read transaction.
2025-02-18 07:59:57 -03:00
Oliver Gugger
fa10991545
multi: fix linter by updating to latest version 2025-02-17 10:40:55 +01:00
Elle Mouton
7853e36488
graph+discovery: calculate funding tx script in gossiper
In preparation for an upcoming commit which will move all channel
funding tx validation to the gossiper, we first move the helper method
which helps build the expected funding transaction script based on the
fields in the channel announcement. We will still want this script later
on in the builder for updating the ChainView though, and so we pass this
field along with the ChannelEdgeInfo. With this change, we can remove
the TapscriptRoot field from the ChannelEdgeInfo since the only reason
it was there was so that the builder could reconstruct the full funding
script.
2025-02-12 13:15:54 +02:00
Elle Mouton
5c2c00e414
graph/db: remove GraphCacheNode interface
With the previous commit, the AddNode method was removed and since that
was the only method making use of the ForEachChannel on the
GraphCacheNode interface, we can remove that method. Since the only two
methods left just expose the node's pub key and features, it really is
not required anymore and so the entire thing can be removed along with
the implementation of it.
2025-02-11 08:19:33 +02:00
Elle Mouton
90179b651e
graph/db: remove unnecessary AddNode method on GraphCache
The AddNode method on the GraphCache calls `AddNodeFeatures` underneath
and then iterates through all the node's persisted channels and adds
them to the cache too via `AddChannel`.

This is, however, not required since at the time the cache is populated
in `NewChannelGraph`, the cache is populated will all persisted nodes
and all persisted channels. Then, once any new channels come in, via
`AddChannelEdge`, they are added to the cache via AddChannel. If any new
nodes come in via `AddLightningNode`, then currently the cache's AddNode
method is called which the both adds the node and again iterates through
all persisted channels and re-adds them to the cache. This is definitely
redundent since the initial cache population and updates via
AddChannelEdge should keep the cache fresh in terms of channels.

So we remove this for 2 reasons: 1) to remove the redundent DB calls and
2) this requires a kvdb.RTx to be passed in to the GraphCache calls
   which will make it hard to extract the cache out of the CRUD layer
and be used more generally.

The AddNode method made sense when the cache was first added in the
code-base
[here](369c09be61 (diff-ae36bdb6670644d20c4e43f3a0ed47f71886c2bcdf3cc2937de24315da5dc072R213))
since then during graph cache population, nodes and channels would be
added to the cache in a single DB transaction. This was, however,
changed [later
on](352008a0c2)
to be done in 2 separate DB calls for efficiency reasons.
2025-02-10 17:10:53 +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
14cedef58e
graph/db: add NodeRTx interface and implement it
In this commit, a new NodeRTx interface is added which represents
consistent access to a persisted models.LightningNode. The
ForEachChannel method of the interface gives the caller access to the
node's channels under the same read transaction (if any) that was used
to fetch the node in the first place. The FetchNode method returns
another NodeRTx which again will have the same underlying read
transaction.

The main point of this interface is to provide this consistent access
without needing to expose the `kvdb.RTx` type as a method parameter.
This will then make it much easier in future to add new implementations
of this interface that are backed by other databases (or RPC
connections) where the `kvdb.RTx` type does not apply.

We will make use of the new interface in the `autopilot` package in
upcoming commits in order to remove the `autopilot`'s dependence on the
pointer to the `*graphdb.ChannelGraph` which it has today.
2025-02-10 08:23:58 +02:00
Elle Mouton
71b2338d53
graph/db: de(ser)ialise opaque node addrs
In this commit, we fix the bug demonstrated in the prior commit. We
correctly handle the persistence of lnwire.OpaqueAddrs.
2025-02-05 12:41:50 +02:00
Elle Mouton
d68d24d97e
graph/db: demonstrate LightningNode serialisation bug 2025-02-05 08:24:45 +02:00
Elle Mouton
b7509897d5
models: create a helper to convert wire NodeAnn to models.LNNode type
And use it in the gossiper. This helps ensure that we do this conversion
consistently.
2025-02-05 08:20:10 +02:00
yyforyongyu
001e5599b6
multi: add debug logs for edge policy flow
This commit adds more logs around the ChannelUpdate->edge policy process
flow.
2025-01-17 00:17:23 +08:00
alingse
a79fd08294 fix check node1Err !=nil but return a nil value error err
Signed-off-by: alingse <alingse@foxmail.com>
2024-12-19 14:57:28 +00:00
Alex Akselrod
c01dcc2be7
graph/db: handle previously-unhandled errors 2024-12-12 10:40:36 -08:00
Keagan McClelland
ed2989ae33
multi: update to fn v2 2024-12-04 13:19:00 -07:00
Elle Mouton
ab7aae0708
multi: rename nolint:lll to nolint:ll
Find and replace all nolint instances refering to the `lll` linter and
replace with `ll` which is the name of our custom version of the `lll`
linter which can be used to ignore log lines during linting.

The next commit will do the configuration of the custom linter and
disable the default one.
2024-12-02 09:14:21 +02: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
2c083bc017
multi: let chan and graph db implement AddrSource
Then use both to construct a multiAddrSource AddrSource and use that
around the code-base.
2024-11-28 13:36:15 +02:00
Elle Mouton
1859993734
channeldb+graphdb: init graph DB outside of channel db
We also now use the graph DB's own optional functions. An instance of
the graph is currently still passed to the channeldb's
`CreateWithBackend` function. This will be removed in a later commit
once the two have been completely disjoint.
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
382539a6eb
channeldb/graphdb: move outpoint ser/deser funcs to graphdb
We have the same helpers for writing and reading a wire.Outpoint type
defined separately in a couple places. We will want to use these from
the graph db package soon though so instead of defining them again
there, this commit unifies things and creates a single exported set of
helpers. The next commit will make use of these.
2024-11-28 13:34:08 +02:00
Elle Mouton
3365461500
channeldb+graph/db: move net.Addr encode/decode to graph db package
In preparation for moving the graph related schema structs to the graph
package in an upcoming commit, we move these methods to the graph
package. The structs we will move make use of these methods but we still
import them from channeldb so as to keep the ReadElement and
WriteElement helpers working as they do today.
2024-11-28 13:34:08 +02:00