Graph Abstraction & Gossiper->to->DB stack clean-up with Remote Graph & Gossip 1.75 projects in mind #9494
Labels
enhancement
Improvements to existing features / behaviour
gossip
graph
interface abstraction
refactoring
Click for Background Context
Today's Gossip -> DB stack
(click to see diagram)
Gossiper
lnwire
(LN protocol) message comes in from either our peers or from us into ourgossiper
gossiper
does some read calls via thegraph.Builder
to theDB
to ensure basic DoS protection (ie should we bother continuing with this announcement at all?)gossiper
then does protocol level checks on the gossip such as: is the signature valid? (and other checks mentioned in bolt 7). NB: today, thegossiper
does not do funding transaction validation when it gets achannel_announcement
as this is currently done further down the stack. This should be changed.gossiper
converts thelnwire
message to our internalmodels
representation (** this is probably the wrong place for this conversion) and calls thegraph.Builder
's Add/Update methods.graph.Builder
ChannelGraph
.-
node_announcement
: again checks freshness (** repeats the check that the gossiper already did...)-
channel_update
: checks that we do know about the channel & that the update is fresh (** again repeating what was done in gossiper)-
channel_announcement
: does funding tx validation (** wrong place!!) along with checks like ensuring we dont already know of this channel (again already done in gossiper).1) it is responsible for pruning closed channels & marking channels as zombies
2) it provides a topology change subscription since it knows when we go and actually persist a new update & need to notify clients.
ChannelGraph
This is our CRUD layer. It has a direct connection to a backing kvdb.Backend & does all our persistence logic.
It also constructs and maintains the
graphCache
which, is a cache that holds the info required by the router.many parts of the code-base currently have direct access to the
graphdb.ChannelGraph
.Remote Graph Vision
If many LND nodes are owned by the same entity, there is really no need for them all to sync their own gossip on init. A node can instead persist just its own gossip updates but instead rely on a remote graph source for populating the rest of its
graphCache
for the purposes of pathfinding.Here is a diagram showing an example configuration: One
Graph Source
that 2 clients depend on:Multi client vision
Zooming in on 1 client
To get to this vision, however, there are a few things that we need to consider and change to get from the current architecture to this ideal architecture:
graphCache
will be populated both via our local updates along with updates from the remote. So it makes sense to have this cache lifted out of the CRUD layer. This will also lend itself to the gossip v1.75 changes (see later on). So steps here include:- rename the current
ChannelGraph
to be a more descriptiveKVDBStore
(orV1Store
(see gossip updates later).- Create a new
ChannelGraph
struct which is responsible for creating thegraphCache
.- The KVDBStore the only defines CRUD logic. Which is a cleaner separation anyways.
graphdb.ChannelGraph
instead of going directly to the CRUD layer. This is needed so that these calls can correctly query the graph-cache/remote graph where needed.graph.Builder
and into the newgraphdb.ChannelGraph
since this is where management of the remote source will happen and so if we want our topology subscription clients to be up to date with changes in the remote source (and not only updates from our own node), then it makes sense for this to be done in theChannelGraph
.ChannelGraph
, both reads and writes, should take acontext.Context
for 2 reasons:1) to prepare for any remote gRPC calls which need a context
2) to prepare for SQL DB backend which will also take a context.
Gossip V175 support vision
click
A couple of things to keep in mind for the gossip 175 support:
graphCache
out of the current V1Store layer and into the newChannelGraph
layer.V1Store
CRUD will deal with*models.Channel1/Node1/Update1
struct types andV2Store
CRUD will deal with*models.Channel2/Node2/Update2
. So ourChannelGraph
layer will also deal with providing Read interface methods to the rest of the code base via newmodels.Channel/Node/Update
interfaces. This is good to keep in mind from the start since there will be some time when some read calls toChannelGraph
are just forwarded directly to the current CRUD layer. So it might be confusing as to why we have that extra layer - but the reason is to allow for this future where we want to mux results.Given the detailed vision and context re other associated projects outlined above, let's narrow down on the initial goals of this ticket that is just focused on Graph Query Abstraction & general clean-up and separation of concerns.
This is what we are aiming for:
Here are the initial high level steps to completion. Along the way during review, small things will probably be added that are worth addressing.
Steps to completion (not necessarily in order)
graph.Builder
to thegossiper
(discovery+graph: move funding tx validation to the gossiper #9478)ChannelGraph
toKVDBStore
, introduce a newChannelGraph
and let it handle thegraphCache
(ie move cache handling out of CRUD layer).Builder
to the newChannelGraph
ChannelGraph
.- [x] autopilot server: graph+autopilot: remove
autopilot
access to rawgraphdb.ChannelGraph
#9480- [ ] invoices rpc server
- [ ] netann
- [ ] rpcserver
lnwire
types. TheBuilder
should then be responsible for converting to our internalmodels
types.ChannelGraph
, update them to take a context. This will involve ensuring that any calling sub-systems actually have a context to thread through. So quite a few PRs will be dedicated to just threading contexts through.Additional goals added on during review:
Associated Issues:
Completed PRs:
graph.Builder
update handling #9476autopilot
access to rawgraphdb.ChannelGraph
#9480The text was updated successfully, but these errors were encountered: