Commit Graph

19077 Commits

Author SHA1 Message Date
Elle Mouton
412e05f85f lnwire: add *OpaqueAddrs case in WriteElements
And then expand the chanbackup unit tests to cover such a case.
2025-05-23 16:14:47 +02:00
Elle Mouton
a15489159a lnwire: remove duplicated logic
Use existing serialisation helpers for serialising TC Pand Onion
addresses in WriteElement.
2025-05-23 16:12:28 +02:00
Elle Mouton
6e9372a3e8 chanbackup: make sure onion addresses are covered in tests 2025-05-23 16:11:27 +02:00
Elle Mouton
3b449820d2 graph/db: init SQLStore caches and batch schedulers
Here, we use the new options to initialise the reject and channel caches
for the SQLStore (as is done for the KVStore) and also the channel and
node batch schedulers.
2025-05-23 11:05:39 +02:00
Elle Mouton
149e1c7d35 graph/db: add StoreOptions to NewSQLStore 2025-05-23 11:05:36 +02:00
Elle Mouton
a0a20bd0d0 graph/db: rename KVStoreOptions to StoreOptions
We'll re-use this options struct for our SQLStore too. So here we rename
it to be more generic.
2025-05-23 11:01:17 +02:00
Elle Mouton
14ca086c72 graph/db: skip TestGraphLoading for non-bbolt store
Let all the NewTestDB functions return the V1Store interface type
instead of pointers. Then add a manual skip in the TestGraphLoading test
for any non-bbolt backend. We can remove this once all the methods used
by the test have been implemented by the SQLStore. We only need the
manual skip for this one test since it is the only one that doesnt use
MakeGraphTest to init the graph db.
2025-05-23 10:53:27 +02:00
Oliver Gugger
cbdd1c22b7 Merge pull request #9692 from lightningnetwork/elle-graph
[graph-work-side-branch]: side branch for graph work
2025-05-23 10:29:09 +02:00
Elle Mouton
7cef62f999 docs: update release notes 2025-05-22 14:17:43 +02:00
Elle Mouton
df1e6da94e batch: update to allow for read-only calls
In this commit, we update the batch schedular so that it has the ability
to do read-only calls. It will do a best effort attempt at keeping a
transaction in read-only mode and then if any requests get added to a
batch that require a read-write tx, then the entire batch's tx will be
upgraded to use a read-write tx.
2025-05-22 14:14:43 +02:00
Elle Mouton
e743878bd5 batch: add a benchmark for SQLite and Postgres 2025-05-22 14:14:43 +02:00
Elle Mouton
bb95b0d9b6 batch: add benchmark tests for KVDB batch writes
Here we add a new BenchmarkBoltBatching test that helps us benchmark the
performance when writing to a bbolt backend using various different
configurations. We test using N txs for N writes, 1 tx for N writes and
then various configurations when using the TimeScheduler.
2025-05-22 14:14:43 +02:00
Elle Mouton
f5a466b051 batch+graph: update batch.Schedular to be generic
In preparation for using the same logic for non-bbolt backends, we adapt
the batch.Schedular to be more generic.

The only user of the scheduler at the moment is the KVStore in the
`graph.db` package. This store instantiates the bbolt implementation of
the scheduler.
2025-05-22 14:14:42 +02:00
Elle Mouton
9b9a964975 graph/db: more test coverage for node addresses
In this commit we add more test coverage for the persistence of the
addresses of a LightningNode. This is so that we have unit test coverage
that ensures that all the various address types can be persisted and
that the order of the addresses (within a type) are preserved.
2025-05-22 14:14:42 +02:00
Elle Mouton
629e74a53c graph/db: add various error assertions
Here we expand TestEdgeInsertionDeletion to assert that the expected
error is returned when AddChannelEdge is called for a channel that has
already been persisted. We also take the opportunity to convert some of
the error checks in the test to use strict error type matching.

Finally, we test that the expected error is returned if
DeleteLightningNode is called for a node that is no longer in the DB.
2025-05-22 14:14:42 +02:00
Elle Mouton
3bc58a0d2f graph/db: test the non-cached version of ForEachNodeDirectedChannel
Expand an existing test for ForEachNodeDirectedChannel so that it also
tests the DB method and not just the ChannelGraph method which will use
the in-memory graph cache for the query.
2025-05-22 14:14:42 +02:00
Elle Mouton
be915f2be7 sqldb: add support for test migrations
Add `migrations_dev.go` and `migrations_prod.go` files which each define
a `migrationAdditions` slice to be appended to the `migrationConfig`
slice. The `migrations_dev.go` file is only built if either the
`test_db_postgres` or `test_db_sqlite` build flags are used.

This slice will be used to add any migrations that are still under
development that we want access to via unit tests and itests but do not
want to expose to our release build.
2025-05-22 14:14:42 +02:00
Elle Mouton
b4121acb1f graph/db: add a framework for testing against SQL backends incrementally
In this commit, we implement the postgres and sqlite versions of the
NewTestDB function. We add the various build flags so that only one of
the three versions of this function can be active at a time.

We also introduce the SQLStore struct which is the SQL implementation of
the V1Store interface.

NOTE: it currently temporarily embeds the KVStore struct so that we can
implement the V1Store interface incrementally. For any method not
implemented, things will fall back to the KVStore. This is ONLY the
case for the time being while this struct is purely used in unit tests
only. Once all the methods have been implemented, the KVStore field will
be removed from the SQLStore struct.
2025-05-22 14:14:42 +02:00
Elle Mouton
383453635b sqldb+go.mod: update sqldb test methods
Update the test methods to take a `testing.TB` param instead of a
`*testing.T` so that the test functions can be used for all the graph's
tests including benchmark tests.

We also add a temporary replace so that we can make use of these changes
and also since we will soon be adding graph related schemas and queries
in this submodule that we'll want to have access to.
2025-05-22 14:14:42 +02:00
Elle Mouton
b285546ce1 graph/db: add NewTestDB method
In this commit, we add a `test_kvdb.go` file with a single definition of
the `NewTestDB` function. A new version of `MakeTestGraph` (called
`MakeTestGraphNew` is added which makes use of this `NewTestDB` function
to create the backing `V1Store` passed to the `ChannelGraph` for tests.

Later on, we will add new implementations of this method backed by
sqlite and postgres.  When those are added, then build flags will
control which version of `NewTestDB` is called.

With this change, the only test call-site of `NewKVStore` is the new
`test_kvdb.go` file.
2025-05-22 14:14:42 +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
7a348e324d graph/db: let MakeTestGraph take ChanGraphOptions
Currently none of the calls to MakeTestGraph make use of the
KVStoreOptionModifier options but later on we will want to make use of
the `WithUseGraphCache` ChannelGraphOption and so we take this
opportunity to switch out the functional parameters that the helper
function takes.
2025-05-22 14:14:42 +02:00
Elle Mouton
7288f280f6 routing+autopilot: rename mission control store var
To clearly separate the mission control DB store (which for now will
remain kvdb only) from the graph store, we rename the `graphBackend`
variable to `mcBackend` in the `testGraphInstance` struct.
2025-05-22 14:14:41 +02:00
Elle Mouton
4233649e6a graph/db: let MakeTestGraph require no error internally
Instead of returning an error and needing to call `require.NoError` for
each call to `MakeTestGraph`, rather just used the available testing
variable to require no error within the function itself.
2025-05-22 14:14:41 +02:00
Elle Mouton
44a92b7efe graph/db: add test coverage for AddEdgeProof 2025-05-22 14:14:41 +02:00
Elle Mouton
3dfc1725d8 graph/db: use mainnet genisis hash in tests
In preparation for our SQL Graph store which wont explicitly store the
chain hash but will instead obtain it from the runtime config, we
replace the test chainhash value with that of the mainnet genesis hash.
2025-05-22 14:14:41 +02:00
Elle Mouton
a9e64542c1 graph/db: set empty Features and ExtraOpaqueData in tests
So we can use`require.Equal` for the ChannelEdgeInfo type.
2025-05-22 14:14:41 +02:00
Elle Mouton
95220b7102 graph/db: check for wrapped errors
In preparation for a different store impl which may wrap errors, we
use `require.ErrorIs` for error assertions rather than direct "="
comparisons in tests.
2025-05-22 14:14:41 +02:00
Elle Mouton
227e49d0ae graph/db: expand TestNodeInsertionAndDeletion
Expand this existing test so that it also tests that a node's addresses
and feature are fetched correctly after insertion. With this, we ensure
that the `FetchNodeFeatures` and `AddrsForNodes` methods of the
`V1Store` interface are properly covered by unit tests.
2025-05-22 14:14:41 +02:00
Elle Mouton
1410a0949d lnwire: validate that gossip messages contain valid TLV
In this commit, we check that the extra bytes appended to gossip
messages contain valid TLV streams. We do this here for:
- channel_announcement
- channel_announcement_2
- channel_update
- channel_update_2
- node_announcement

This is in preparation for the SQL version of the graph store which will
normalise TLV streams at persistence time.
2025-05-22 14:14:41 +02:00
Elle Mouton
0db91304cf graph/db: make all ExtraOpaqueData valid TLV streams
Later when we introduce our SQL version of the graph store, we will
normalise the persistence of the ExtraOpaqueData using the fact that it
is always made up of TLV entries. So we update our tests here to ensure
that they use valid TLV streams as examples.
2025-05-22 14:14:40 +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
449684de87 graph/db: use V1Store interface in ChannelGraph
Use the new `V1Store` interface as a field in the `ChannelGraph` rather than
a pointer to the `KVStore` implementation in preparation for allowing a
SQL implementation of `V1Store` to be used by the `ChannelGraph`.

Note that two tests are adjusted in this commit to be skipped if the
V1Store is not the `KVStore` implementation since the tests are very
bbolt specific.
2025-05-22 14:14:40 +02:00
Elle Mouton
52018dbbec graph/db: introduce the V1Store interface
In this commit, we introduce the `V1Store` interface which the existing
`graphdb.KVStore` implements today. The idea is to eventually create a
SQL DB backed implementation of this interface.
2025-05-22 14:14:40 +02:00
Elle Mouton
11b27f07da batch: dont expose kvdb.RwTx in batch.SchedulerOptions
Currently, a few of the graph KVStore methods take the
`batch.SchedulerOptions` param. This is only used to set the LazyAdd
option. A SchedulerOption is a functional option that takes a
`batch.Request` which has bolt-specific fields in it. This commit
restructures things a bit such that the `batch.Request` type is no
longer part of the `batch.SchedulerOptions` - this will make it easier
to implement the graph store with a different DB backend.
2025-05-22 14:14:40 +02:00
Elle Mouton
5d7c6c4b60 channeldb: remove graph calls from tests
The channeldb no longer depends on the graph. So remove the use of
MakeTestGraph from tests.
2025-05-22 14:14:40 +02:00
Elle Mouton
a5c1219999 graph: test cleanup
Remove the kvdb.Backend return type of the `makeTestGraph` helper. This
is in preparation for the helper being used to create a test graph
backed by a DB other than bbolt.
2025-05-22 14:14:40 +02:00
Elle Mouton
258dd12cb2 graph/db: update the compareNodes helper
- Let it do a proper comparison of the full structs passed in.
- Pass in a testing parameter so we can remove the returned error.
- Make sure the callers are passing in the expected and result
  parameters in the correct order.
- Fix a bug: the compareNodes was not comparing the Features field of
  the LightningNode structs. Now that it does, one test needed to be
updated to properly set the expected Features fields.
2025-05-22 14:14:40 +02:00
Elle Mouton
8468c7c4ba graph/db: let test alias be UTF-8 compatible
Later on we will store the Alias as a Text field in our sql impls of the
graph db. For Postgres, this field then MUST be a valid UTF-8 string.
This is also the case in general for the alias according to [bolt
7](e1fa25cf00/07-routing-gossip.md (L313))
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
c68a19c0ba discovery: revert passing ctx through to Start methods 2025-05-22 14:14:39 +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
3ec4798311 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-05-22 14:14:39 +02:00
Elle Mouton
ea4b8c30a4 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-05-22 14:14:39 +02:00
Elle Mouton
42e87396ec 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-05-22 14:14:39 +02:00
Elle Mouton
cf1ec68c0c 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-05-22 14:14:38 +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
2f54a0a26a 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-05-22 14:14:38 +02:00