@@ -2,13 +2,9 @@ package graph
22
33import (
44 "context"
5- "iter"
65 "time"
76
8- "github.com/btcsuite/btcd/chaincfg/chainhash"
9- "github.com/btcsuite/btcd/wire"
107 "github.com/lightningnetwork/lnd/batch"
11- graphdb "github.com/lightningnetwork/lnd/graph/db"
128 "github.com/lightningnetwork/lnd/graph/db/models"
139 "github.com/lightningnetwork/lnd/lnwire"
1410 "github.com/lightningnetwork/lnd/routing/route"
@@ -73,7 +69,7 @@ type ChannelGraphSource interface {
7369 // star-graph.
7470 ForAllOutgoingChannels (ctx context.Context ,
7571 cb func (c * models.ChannelEdgeInfo ,
76- e * models.ChannelEdgePolicy ) error , reset func ()) error
72+ e * models.ChannelEdgePolicy ) error , reset func ()) error
7773
7874 // CurrentBlockHeight returns the block height from POV of the router
7975 // subsystem.
@@ -96,183 +92,3 @@ type ChannelGraphSource interface {
9692 // currently marked as a zombie edge.
9793 IsZombieEdge (chanID lnwire.ShortChannelID ) (bool , error )
9894}
99-
100- // DB is an interface describing a persisted Lightning Network graph.
101- //
102- //nolint:interfacebloat
103- type DB interface {
104- // PruneTip returns the block height and hash of the latest block that
105- // has been used to prune channels in the graph. Knowing the "prune tip"
106- // allows callers to tell if the graph is currently in sync with the
107- // current best known UTXO state.
108- PruneTip () (* chainhash.Hash , uint32 , error )
109-
110- // PruneGraph prunes newly closed channels from the channel graph in
111- // response to a new block being solved on the network. Any transactions
112- // which spend the funding output of any known channels within the graph
113- // will be deleted. Additionally, the "prune tip", or the last block
114- // which has been used to prune the graph is stored so callers can
115- // ensure the graph is fully in sync with the current UTXO state. A
116- // slice of channels that have been closed by the target block are
117- // returned if the function succeeds without error.
118- PruneGraph (spentOutputs []* wire.OutPoint , blockHash * chainhash.Hash ,
119- blockHeight uint32 ) ([]* models.ChannelEdgeInfo , error )
120-
121- // ChannelView returns the verifiable edge information for each active
122- // channel within the known channel graph. The set of UTXO's (along with
123- // their scripts) returned are the ones that need to be watched on
124- // chain to detect channel closes on the resident blockchain.
125- ChannelView () ([]graphdb.EdgePoint , error )
126-
127- // PruneGraphNodes is a garbage collection method which attempts to
128- // prune out any nodes from the channel graph that are currently
129- // unconnected. This ensure that we only maintain a graph of reachable
130- // nodes. In the event that a pruned node gains more channels, it will
131- // be re-added back to the graph.
132- PruneGraphNodes () error
133-
134- // SourceNode returns the source node of the graph. The source node is
135- // treated as the center node within a star-graph. This method may be
136- // used to kick off a path finding algorithm in order to explore the
137- // reachability of another node based off the source node.
138- SourceNode (ctx context.Context ) (* models.Node , error )
139-
140- // DisabledChannelIDs returns the channel ids of disabled channels.
141- // A channel is disabled when two of the associated ChanelEdgePolicies
142- // have their disabled bit on.
143- DisabledChannelIDs () ([]uint64 , error )
144-
145- // FetchChanInfos returns the set of channel edges that correspond to
146- // the passed channel ID's. If an edge is the query is unknown to the
147- // database, it will skipped and the result will contain only those
148- // edges that exist at the time of the query. This can be used to
149- // respond to peer queries that are seeking to fill in gaps in their
150- // view of the channel graph.
151- FetchChanInfos (chanIDs []uint64 ) ([]graphdb.ChannelEdge , error )
152-
153- // ChanUpdatesInHorizon returns all the known channel edges which have
154- // at least one edge that has an update timestamp within the specified
155- // horizon.
156- ChanUpdatesInHorizon (startTime , endTime time.Time ,
157- opts ... graphdb.IteratorOption ,
158- ) iter.Seq2 [graphdb.ChannelEdge , error ]
159-
160- // DeleteChannelEdges removes edges with the given channel IDs from the
161- // database and marks them as zombies. This ensures that we're unable to
162- // re-add it to our database once again. If an edge does not exist
163- // within the database, then ErrEdgeNotFound will be returned. If
164- // strictZombiePruning is true, then when we mark these edges as
165- // zombies, we'll set up the keys such that we require the node that
166- // failed to send the fresh update to be the one that resurrects the
167- // channel from its zombie state. The markZombie bool denotes whether
168- // to mark the channel as a zombie.
169- DeleteChannelEdges (strictZombiePruning , markZombie bool ,
170- chanIDs ... uint64 ) error
171-
172- // DisconnectBlockAtHeight is used to indicate that the block specified
173- // by the passed height has been disconnected from the main chain. This
174- // will "rewind" the graph back to the height below, deleting channels
175- // that are no longer confirmed from the graph. The prune log will be
176- // set to the last prune height valid for the remaining chain.
177- // Channels that were removed from the graph resulting from the
178- // disconnected block are returned.
179- DisconnectBlockAtHeight (height uint32 ) ([]* models.ChannelEdgeInfo ,
180- error )
181-
182- // HasChannelEdge returns true if the database knows of a channel edge
183- // with the passed channel ID, and false otherwise. If an edge with that
184- // ID is found within the graph, then two time stamps representing the
185- // last time the edge was updated for both directed edges are returned
186- // along with the boolean. If it is not found, then the zombie index is
187- // checked and its result is returned as the second boolean.
188- HasChannelEdge (chanID uint64 ) (time.Time , time.Time , bool , bool , error )
189-
190- // FetchChannelEdgesByID attempts to lookup the two directed edges for
191- // the channel identified by the channel ID. If the channel can't be
192- // found, then ErrEdgeNotFound is returned. A struct which houses the
193- // general information for the channel itself is returned as well as
194- // two structs that contain the routing policies for the channel in
195- // either direction.
196- //
197- // ErrZombieEdge an be returned if the edge is currently marked as a
198- // zombie within the database. In this case, the ChannelEdgePolicy's
199- // will be nil, and the ChannelEdgeInfo will only include the public
200- // keys of each node.
201- FetchChannelEdgesByID (chanID uint64 ) (* models.ChannelEdgeInfo ,
202- * models.ChannelEdgePolicy , * models.ChannelEdgePolicy , error )
203-
204- // AddNode adds a vertex/node to the graph database. If the
205- // node is not in the database from before, this will add a new,
206- // unconnected one to the graph. If it is present from before, this will
207- // update that node's information. Note that this method is expected to
208- // only be called to update an already present node from a node
209- // announcement, or to insert a node found in a channel update.
210- AddNode (ctx context.Context , node * models.Node ,
211- op ... batch.SchedulerOption ) error
212-
213- // AddChannelEdge adds a new (undirected, blank) edge to the graph
214- // database. An undirected edge from the two target nodes are created.
215- // The information stored denotes the static attributes of the channel,
216- // such as the channelID, the keys involved in creation of the channel,
217- // and the set of features that the channel supports. The chanPoint and
218- // chanID are used to uniquely identify the edge globally within the
219- // database.
220- AddChannelEdge (ctx context.Context , edge * models.ChannelEdgeInfo ,
221- op ... batch.SchedulerOption ) error
222-
223- // MarkEdgeZombie attempts to mark a channel identified by its channel
224- // ID as a zombie. This method is used on an ad-hoc basis, when channels
225- // need to be marked as zombies outside the normal pruning cycle.
226- MarkEdgeZombie (chanID uint64 , pubKey1 , pubKey2 [33 ]byte ) error
227-
228- // UpdateEdgePolicy updates the edge routing policy for a single
229- // directed edge within the database for the referenced channel. The
230- // `flags` attribute within the ChannelEdgePolicy determines which of
231- // the directed edges are being updated. If the flag is 1, then the
232- // first node's information is being updated, otherwise it's the second
233- // node's information. The node ordering is determined by the
234- // lexicographical ordering of the identity public keys of the nodes on
235- // either side of the channel.
236- UpdateEdgePolicy (ctx context.Context , edge * models.ChannelEdgePolicy ,
237- op ... batch.SchedulerOption ) error
238-
239- // HasNode determines if the graph has a vertex identified by
240- // the target node identity public key. If the node exists in the
241- // database, a timestamp of when the data for the node was lasted
242- // updated is returned along with a true boolean. Otherwise, an empty
243- // time.Time is returned with a false boolean.
244- HasNode (ctx context.Context , nodePub [33 ]byte ) (time.Time , bool , error )
245-
246- // FetchNode attempts to look up a target node by its identity
247- // public key. If the node isn't found in the database, then
248- // ErrGraphNodeNotFound is returned.
249- FetchNode (ctx context.Context , nodePub route.Vertex ) (* models.Node ,
250- error )
251-
252- // ForEachNodeChannel iterates through all channels of the given node,
253- // executing the passed callback with an edge info structure and the
254- // policies of each end of the channel. The first edge policy is the
255- // outgoing edge *to* the connecting node, while the second is the
256- // incoming edge *from* the connecting node. If the callback returns an
257- // error, then the iteration is halted with the error propagated back up
258- // to the caller.
259- //
260- // Unknown policies are passed into the callback as nil values.
261- ForEachNodeChannel (ctx context.Context , nodePub route.Vertex ,
262- cb func (* models.ChannelEdgeInfo , * models.ChannelEdgePolicy ,
263- * models.ChannelEdgePolicy ) error , reset func ()) error
264-
265- // AddEdgeProof sets the proof of an existing edge in the graph
266- // database.
267- AddEdgeProof (chanID lnwire.ShortChannelID ,
268- proof * models.ChannelAuthProof ) error
269-
270- // IsPublicNode is a helper method that determines whether the node with
271- // the given public key is seen as a public node in the graph from the
272- // graph's source node's point of view.
273- IsPublicNode (pubKey [33 ]byte ) (bool , error )
274-
275- // MarkEdgeLive clears an edge from our zombie index, deeming it as
276- // live.
277- MarkEdgeLive (chanID uint64 ) error
278- }
0 commit comments