Commit Graph

112 Commits

Author SHA1 Message Date
Elle Mouton
9b877b94c3 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-07-01 20:08:12 +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
de11997fad graph/db: use only exported KVStore methods in tests
Replace all calls to bbolt specific methods on the KVStore to instead
use exported methods on the KVStore that are more db-agnostic.
2025-06-04 10:54:35 +02:00
Elle Mouton
9aab68a6f5 graph/db: unexport various methods that expose kvdb.RTx
Unexport the KVStore `FetchOtherNode` and `ForEachNodeChannelTx` methods
so that fewer exposed methods are leaking implementation details.
2025-06-04 10:54:35 +02:00
Elle Mouton
c15740ba09 graph/db: introduce ForEachSourceNodeChannel
In preparation for creating a clean interface for the graph store, we
want to hide anything that is DB specific from the exposed methods on
the interface. Currently the `ForEachNodeChannel` and the
`FetchOtherNode` methods of the `KVStore` expose a `kvdb.RTx` parameter
which is bbolt specific. There is only one call-site of
`ForEachNodeChannel` actually makes use of the passed `kvdb.RTx`
parameter, and that is in the `establishPersistentConnections` method of
the `server` which then passes the tx parameter to `FetchOtherNode`.

So to clean-up the interface such that the `kvdb.RTx` is no longer
exposed: we instead create one new method called
`ForEachSourceNodeChannel` which can be used to replace the above
mentioned call-site. So as of this commit, all the remaining call-site
of `ForEachNodeChannel` pass in a nil param for `kvdb.RTx` - meaning we
can remove the parameter in a future commit.
2025-06-04 10:54:35 +02:00
Elle Mouton
9c3c2b970c graph/db: remove unused Wipe method
Later on we will create an interface for the persisted graph data. We
want this interface to be as small and as neat as possible. In
preparation for this, we remove this unused `Wipe` method.
2025-06-04 10:54:34 +02:00
Elle Mouton
ca52834795 graph/db: use only exported KVStore ForEachNode method in tests
Replace all tests calls to the private `forEachNode` method on the
`KVStore` with the exported ForEachNode method. This is in preparation
for having the tests run against an abstract DB backend.
2025-06-04 10:54:34 +02:00
Elle Mouton
861606d28b graph/db: remove kvdb.Backend from test helpers
Remove unused kvdb.Backend param from `randEdgePolicy` and
`newEdgePolicy` test helpers.
2025-06-04 10:54:34 +02:00
Elle Mouton
29ce7627fd graph/db: remove kvdb param from test helper
Remove the kvdb.Backend parameter from the `createChannelEdge` helper.
This is all in preparation for having the unit tests run against any DB
backend.
2025-06-04 10:54:33 +02:00
Elle Mouton
1b26b590b4 graph/db: test clean-up
This commit cleans up the graph test code by removing unused kvdb type
parameters from the `createTextVertex` and `createLightningNode` helper
methods. We also pass in the testing parameter now so that we dont need
to check the error each time we call `createTestVertex`.
2025-06-04 10:54:33 +02:00
Oliver Gugger
b0cba7dd08 Merge pull request #9804 from ellemouton/removeChanGraphCacheMu
graph/db: remove ChannelGraph cacheMu
2025-05-13 16:10:17 +02:00
Elle Mouton
0155d5d7b0 graph/db: handle topology updates in a single location
In this commit, we ensure that any topology update is forced to go via
the `handleTopologySubscriptions` handler so that client subscriptions
and updates are handled correctly and in the correct order.

This removes a bug that could result from a client missing a
notification about a channel being closed if the client is subscribed
and shortly after, `PruneGraph` is called which would notify all
subscribed clients and possibly do so before the client subscription has
actually been persisted.
2025-05-12 14:42:22 +02:00
Elle Mouton
765fc6c132 graph/db: remove ChannelGraph cacheMu
We remove the mutex that was previously held between DB calls and calls
that update the graphCache. This is done so that the underlying DB calls
can make use of any batch requests which they currently cannot since the
mutex prevents multiple requests from calling the methods at once.

The reason the cacheMu was originally added here was during a code
refactor that moved the `graphCache` out of the `KVStore` and into the
`ChannelGraph` and the aim was then to have a best effort way of
ensuring that updates to the DB and updates to the graphCache were as
consistent/atomic as possible.
2025-05-12 08:29:40 +02:00
Elle Mouton
878746c9c9 graph/db: refactor to group all topology notification fields
A clean-up commit just to separate out all topology related fields in
ChannelGraph into a dedicated struct that then gets mounted to the
ChannelGraph.
2025-03-24 15:05:48 +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
4131b3fc7e graph/db: adjust TestPartialNode
The test as it stands today does not make sense as it adds a
Partial/Shell node to the graph via AddLightningNode which will never
happen since this is only ever triggered by the gossiper which only
calls the method with a full node announcement. Shell/Partial nodes are
only ever added via AddChannelEdge which will insert a partial node if
we are adding a channel edge which has node pub keys that we dont have a
node entry for. So we adjust the test to use this more accurate flow.
2025-03-24 15:05:48 +02:00
Elle Mouton
45450886d7 graph/db: populate the graph cache in Start instead of during construction
In this commit, we move the graph cache population logic out of the
ChannelGraph constructor and into its Start method instead.
2025-03-24 15:05:47 +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
bb3839e422 graph/db: completely remove cache from KVStore 2025-03-24 15:05:47 +02:00
Elle Mouton
ba1d21d5c7 graph/db: move cache write for UpdateEdgePolicy
To the ChannelGraph.
2025-03-24 15:05:47 +02:00
Elle Mouton
9d0b9f9ace graph/db: move cache write for MarkEdgeZombie
From the KVStore to the ChannelGraph.
2025-03-24 15:05:47 +02:00
Elle Mouton
4d00eb2aa4 graph/db: move FilterKnownChanIDs zombie logic up one layer
Here, we move the business logic in FilterKnownChanIDs from the CRUD
layer to the ChannelGraph layer. We also add a test for the logic.
2025-03-24 15:05:47 +02:00
Elle Mouton
cc4fcbf838 graph/db: move cache writes for Prune methods
This commit moves the cache writes for PruneGraphNodes and PruneGraph
from the KVStore to the ChannelGraph.
2025-03-24 15:05:47 +02:00
Elle Mouton
941e7bf6b3 graph/db: move cache update out of pruneGraphNodes
In preparation for moving the cache write completely out of KVStore, we
move the cache write up one layer.
2025-03-24 15:05:46 +02:00
Elle Mouton
71e5ab6200 graph/db: move some cache writes to ChannelGraph.
Here we move the cache writes for DisconnectBlockAtHeight and
DeleteChannelEdges to the ChannelGraph.
2025-03-24 15:05:46 +02:00
Elle Mouton
081c9dc082 graph/db: refactor delChannelEdgeUnsafe to return edge info
And update cache outside the method rather. This will make it easier to
completely move the cache write out to the ChannelGraph layer.
2025-03-24 15:05:46 +02:00
Elle Mouton
f75e6a1c10 graph/db: move various cache write calls to ChannelGraph
Here, we move the graph cache writes for AddLightningNode,
DeleteLightningNode, AddChannelEdge and MarkEdgeLive to the
ChannelGraph. Since these are writes, the cache is only updated if the
DB write is successful.
2025-03-24 15:05:46 +02:00
Elle Mouton
9fe9e32c6e graph/db: move cache read checks to ChannelGraph.
This commit moves the graph cache checks for FetchNodeFeatures,
ForEachNodeDirectedChannel, GraphSession and ForEachNodeCached from the
KVStore to the ChannelGraph. Since the ChannelGraph is currently just a
pass-through for any of the KVStore methods, all that needs to be done
for calls to go via the ChannelGraph instead directly to the KVStore is
for the ChannelGraph to go and implement those methods.
2025-03-24 15:05:46 +02:00
Elle Mouton
88398e3dd9 graph/db: let ChannelGraph init the graphCache
In this commit, we let the ChannelGraph be responsible for populating
the graphCache and then passing it to the KVStore. This is a first step
in moving the graphCache completely out of the KVStore layer.
2025-03-24 15:05:46 +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
Elle Mouton
81e0608c10 graph/db: rename Options to KVStoreOptions
Namespace these options so that we can introduce separate options for
the new ChannelGraph.
2025-03-24 15:05:46 +02:00
Elle Mouton
ae3961b47f graph/db: fix linter issues of old code
Since we have renamed a file housing some very old code, the linter has
now run on all this code for the first time. So we gotta do some
clean-up work here to make it happy.
2025-03-24 15:05:46 +02:00
Elle Mouton
1ee4bb8c51 graph/db: rename ChannelGraph and introduce the new ChannelGraph layer
In this commit, we rename the existing ChannelGraph struct to KVStore to
better reflect its responsibilities as the CRUD layer. We then introduce
a new ChannelGraph struct which will eventually be the layer above the
CRUD layer in which we will handle cacheing and topology subscriptions.
For now, however, it houses only the KVStore. This means that all calls
to the KVStore will now go through this layer of indirection first. This
will allow us to slowly move the graph Cache management out of the
KVStore and into the new ChannelGraph layer.

We introduce the new ChannelGraph and rename the old one in the same
commit so that all existing call-sites don't need to change at all :)
2025-03-24 15:05:46 +02:00
Elle Mouton
ed8e10e4b9 graph/db: rename graph.go file
Rename it to kv_store.go so that we can re-use the graph.go file name
later on. We will use it to house the _new_ ChannelGraph when the
existing ChannelGraph is renamed to more clearly reflect its
responsibilities as the CRUD layer.
2025-03-24 15:05:46 +02:00
Elle Mouton
c89b616e7d graph: refactor Builder network message handling
The exposed AddNode, AddEdge and UpdateEdge methods of the Builder are
currently synchronous since even though they pass messages to the
network handler which spins off the handling in a goroutine, the public
methods still wait for a response from the handling before returning.
The only part that is actually done asynchronously is the topology
notifications.

We previously tried to simplify things in [this
commit](d757b3bcfc)
but we soon realised that there was a reason for sending the messages to
the central/synchronous network handler first: it was to ensure
consistency for topology clients: ie, the ordering between when there is
a new topology client or if it is cancelled needs to be consistent and
handled synchronously with new network updates. So for example, if a new
update comes in right after a topology client cancels its subscription,
then it should _not_ be notified. Similariy for new subscriptions. So
this commit was reverted soon after.

We can, however, still simplify things as is done in this commit by
noting that _only topology subscriptions and notifications_ need to be
handled separately. The actual network updates do not need to. So that
is what is done here.

This refactor will make moving the topology subscription logic to a new
subsystem later on much easier.
2025-02-21 10:39:00 -03:00
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
5d5cfe36c7 routing: rename routing Graph method
In preparation for having the ChannelGraph directly implement the
`routing.Graph` interface, we rename the `ForEachNodeChannel` method to
`ForEachNodeDirectedChannel` since the ChannelGraph already uses the
`ForEachNodeChannel` name and the new name is more appropriate since the
ChannelGraph currently has a `ForEachNodeDirectedChannelTx` method which
passes the same DirectedChannel type to the given call-back.
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
Olaoluwa Osuntokun
5ee81e1876 Merge pull request #9512 from Roasbeef/go-1-23
multi: update build system to Go 1.23
2025-02-17 16:45:12 -08:00
Oliver Gugger
fa10991545 multi: fix linter by updating to latest version 2025-02-17 10:40:55 +01:00
Elle Mouton
f39a004662 Revert "graph: refactor Builder network message handling"
This reverts commit d757b3bcfc.
2025-02-13 11:19:07 +02:00