Commit graph

58 commits

Author SHA1 Message Date
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
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
ziggie
6373d84baf
graph: fix flake in unit test 2025-02-10 14:07:04 +01: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
7cf5b5be02
graph: remove unused ForEachNode method from Builder
And from various interfaces where it is not needed.
2025-02-10 08:16:34 +02:00
Elle Mouton
b117daaa3c
discovery+graph: convert errors from codes to variables
In preparation for moving funding transaction validiation from the
Builder to the Gossiper in later commit, we first convert these graph
Error Codes to normal error variables. This will help make the later
commit a pure code move.
2025-02-07 15:26:16 +02:00
Oliver Gugger
3c0350e481
Merge pull request #9476 from ellemouton/graph1
graph: refactor `graph.Builder` update handling
2025-02-07 07:23:41 -06:00
Elle Mouton
6169b47d65
graph: rename routerStats to builderStats
This logic used to be handled by the router. Update to reflect new
owner.
2025-02-07 13:01:39 +02:00
Elle Mouton
d757b3bcfc
graph: refactor Builder network message handling
The point of the `graph.Builder`'s `networkHandler` goroutine is to
ensure that certain requests are handled in a synchronous fashion.
However, any requests received on the `networkUpdates` channel, are
currently immediately handled in a goroutine which calls
`handleNetworkUpdate` which calls `processUpdate` before doing topology
notifications. In other words, there is no reason for these
`networkUpdates` to be handled in the `networkHandler` since they are
always handled asynchronously anyways. This design is most likely due to
the fact that originally the gossiper and graph builder code lived in
the same system and so the pattern was copied across.

So in this commit, we just remove the complexity. The only part we need
to spin off in a goroutine is the topology notifications.
2025-02-07 13:01:35 +02:00
Elle Mouton
276b335cf5
graph: refactor announcement handling logic
In this commit, we remove the `processUpdate` method which handles each
announement type (node, channel, channel update) in a separate switch
case. Each of these cases currently has a non-trivial amount of code.
This commit creates separate methods for each message type we want to
handle instead. This removes a level of indentation and will make things
easier to review when we start editing the code for each handler.
2025-02-07 07:30:00 +02:00
Elle Mouton
1974903fb2
multi: move node ann validation code to netann pkg
The `netann` package is a more appropriate place for this code to live.
Also, once the funding transaction code is moved out of the
`graph.Builder`, then no `lnwire` validation will occur in the `graph`
package.
2025-02-07 07:30:00 +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
Eugene Siegel
323b633895 graph -> discovery: move ValidationBarrier to discovery 2025-01-23 13:04:39 -05:00
Eugene Siegel
6a47a501c3 discovery+graph: track job set dependencies in ValidationBarrier
This commit does two things:
- removes the concept of allow / deny. Having this in place was a
  minor optimization and removing it makes the solution simpler.
- changes the job dependency tracking to track sets of abstact
  parent jobs rather than individual parent jobs.

As a note, the purpose of the ValidationBarrier is that it allows us
to launch gossip validation jobs in goroutines while still ensuring
that the validation order of these goroutines is adhered to when it
comes to validating ChannelAnnouncement _before_ ChannelUpdate and
_before_ NodeAnnouncement.
2025-01-23 11:43:07 -05:00
Eugene Siegel
2731d09a0b graph: change ValidationBarrier usage in the builder code
This omits calls to InitJobDependencies, SignalDependants, and
WaitForDependants. These changes have been made here because
the router / builder code does not actually need job dependency
management. Calls to the builder code (i.e. AddNode, AddEdge,
UpdateEdge) are all blocking in the gossiper. This, combined
with the fact that child jobs are run after parent jobs in the
gossiper, means that the calls to the router will happen in the
proper dependency order.
2025-01-23 11:43:07 -05:00
yyforyongyu
eb2b0c783f
graph: fix staticcheck suggestion
From staticcheck: QF1002 - Convert untagged switch to tagged switch.
2025-01-17 00:21:45 +08: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
adcaa8802f
multi: remove kvdb.Tx from ChannelGraphSource.ForAllOutgoingChannels
and the same for ChannelStateDB.FetchChannel. Most of the calls to these
methods provide a `nil` Tx anyways. The only place that currently
provides a non-nil tx is in the `localchans.Manager`. It takes the
transaction provided to the `ForAllOutgoingChannels` callback and passes
it to it's `updateEdge` method. Note, however, that the
`ForAllOutgoingChannels` call is a call to the graph db and the call to
`updateEdge` is a call to the `ChannelStateDB`. There is no reason that
these two calls need to happen under the same transaction as they are
reading from two completely disjoint databases. And so in the effort to
completely split untangle the relationship between the two databases, we
now dont use the same transaction for these two calls.
2024-11-28 13:49:41 +02:00
Elle Mouton
6e13898981
multi: move LightningNode struct to models package 2024-11-28 13:36:32 +02:00
Elle Mouton
ccb8f0eeb8
refactor: move graphsession pkg to graph package 2024-11-28 13:36:15 +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
Elle Mouton
23602e017e
multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
Oliver Gugger
cdad5d988d
Merge pull request #9072 from lightningnetwork/extract-part3-from-staging-branch
[custom channels 3/5]: Extract PART3 from mega staging branch
2024-09-19 01:20:55 -06:00
Elle Mouton
7bbf89625f
multi: move ChannelUpdate validate methods to netann 2024-09-18 16:13:18 +02:00
Elle Mouton
615db1fc2e
multi: move channel announcement validation to netann
from the graph package.
2024-09-18 16:13:17 +02:00
Elle Mouton
9be84c1bdc
graph+lnwallet: move FetchTx logic to lnwallet
So that it can be re-used elsewhere.
2024-09-18 16:13:17 +02:00
Elle Mouton
60f331edb1
multi: rename ChannelUpdate to ChannelUpdate1
In preparation for adding a new ChannelUpdate2 message and a
ChannelUpdate interface, we rename the existing message to
ChannelUpdate1.
2024-09-18 16:13:17 +02:00
Elle Mouton
bb44efa21f
multi: rename ChannelAnnouncement to ChannelAnnouncment1
In preparation for adding the new ChannelAnnouncement2 message along
with a ChannelAnnouncement interface, we rename the existing message to
ChannelAnnouncement1.
2024-09-18 16:13:17 +02:00
Elle Mouton
05d76b696d
multi: rename AnnounceSignatures to AnnounceSignatures1
In preparation for adding a new message, AnnounceSignatures2 along with
an AnnounceSignatures interface, we rename the existing message to
AnnounceSignatures1.
2024-09-18 16:13:16 +02:00
Oliver Gugger
5c854a2f53
multi: add tapscript root to gossip message 2024-09-18 10:25:41 +02:00
Olaoluwa Osuntokun
142b408be7
multi: update GenTaprootFundingScript to pass tapscript root
In most cases, we won't yet be passing a root. The option usage helps us keep the control flow mostly unchanged.
2024-08-28 11:52:31 +02:00
Olaoluwa Osuntokun
2c56b3120a
multi: add new tapscript root option to GenTaprootFundingScript
This'll allow us to create a funding output that uses musig2, but uses a tapscript tweak rather than a normal BIP 86 tweak.
2024-08-28 11:52:31 +02:00
Eugene Siegel
9380292a5a
graph: export NewErrf and ErrorCode for upcoming gossiper unit tests 2024-08-27 14:11:06 -04:00
Oliver Gugger
e99e6662cf
multi: update linter, fix new issues 2024-08-20 19:14:44 +02:00
ziggie
e19f891453
graph: add log lines for stop and start func. 2024-07-31 13:12:20 +02:00