/ graph / interfaces.go
interfaces.go
 1  package graph
 2  
 3  import (
 4  	"context"
 5  	"time"
 6  
 7  	"github.com/lightningnetwork/lnd/batch"
 8  	"github.com/lightningnetwork/lnd/graph/db/models"
 9  	"github.com/lightningnetwork/lnd/lnwire"
10  	"github.com/lightningnetwork/lnd/routing/route"
11  )
12  
13  // ChannelGraphSource represents the source of information about the topology
14  // of the lightning network. It's responsible for the addition of nodes, edges,
15  // applying edge updates, and returning the current block height with which the
16  // topology is synchronized.
17  //
18  //nolint:interfacebloat
19  type ChannelGraphSource interface {
20  	// AddNode is used to add information about a node to the router
21  	// database. If the node with this pubkey is not present in an existing
22  	// channel, it will be ignored.
23  	AddNode(ctx context.Context, node *models.Node,
24  		op ...batch.SchedulerOption) error
25  
26  	// AddEdge is used to add edge/channel to the topology of the router,
27  	// after all information about channel will be gathered this
28  	// edge/channel might be used in construction of payment path.
29  	AddEdge(ctx context.Context, edge *models.ChannelEdgeInfo,
30  		op ...batch.SchedulerOption) error
31  
32  	// AddProof updates the channel edge info with proof which is needed to
33  	// properly announce the edge to the rest of the network.
34  	AddProof(chanID lnwire.ShortChannelID,
35  		proof *models.ChannelAuthProof) error
36  
37  	// UpdateEdge is used to update edge information, without this message
38  	// edge considered as not fully constructed.
39  	UpdateEdge(ctx context.Context, policy *models.ChannelEdgePolicy,
40  		op ...batch.SchedulerOption) error
41  
42  	// IsStaleNode returns true if the graph source has a node announcement
43  	// for the target node with a more recent timestamp. This method will
44  	// also return true if we don't have an active channel announcement for
45  	// the target node.
46  	IsStaleNode(ctx context.Context, node route.Vertex,
47  		timestamp time.Time) bool
48  
49  	// IsPublicNode determines whether the given vertex is seen as a public
50  	// node in the graph from the graph's source node's point of view.
51  	IsPublicNode(node route.Vertex) (bool, error)
52  
53  	// IsKnownEdge returns true if the graph source already knows of the
54  	// passed channel ID either as a live or zombie edge.
55  	IsKnownEdge(chanID lnwire.ShortChannelID) bool
56  
57  	// IsStaleEdgePolicy returns true if the graph source has a channel
58  	// edge for the passed channel ID (and flags) that have a more recent
59  	// timestamp.
60  	IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time,
61  		flags lnwire.ChanUpdateChanFlags) bool
62  
63  	// MarkEdgeLive clears an edge from our zombie index, deeming it as
64  	// live.
65  	MarkEdgeLive(chanID lnwire.ShortChannelID) error
66  
67  	// ForAllOutgoingChannels is used to iterate over all channels
68  	// emanating from the "source" node which is the center of the
69  	// star-graph.
70  	ForAllOutgoingChannels(ctx context.Context,
71  		cb func(c *models.ChannelEdgeInfo,
72  			e *models.ChannelEdgePolicy) error, reset func()) error
73  
74  	// CurrentBlockHeight returns the block height from POV of the router
75  	// subsystem.
76  	CurrentBlockHeight() (uint32, error)
77  
78  	// GetChannelByID return the channel by the channel id.
79  	GetChannelByID(chanID lnwire.ShortChannelID) (
80  		*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
81  		*models.ChannelEdgePolicy, error)
82  
83  	// FetchNode attempts to look up a target node by its identity
84  	// public key. channeldb.ErrGraphNodeNotFound is returned if the node
85  	// doesn't exist within the graph.
86  	FetchNode(context.Context, route.Vertex) (*models.Node, error)
87  
88  	// MarkZombieEdge marks the channel with the given ID as a zombie edge.
89  	MarkZombieEdge(chanID uint64) error
90  
91  	// IsZombieEdge returns true if the edge with the given channel ID is
92  	// currently marked as a zombie edge.
93  	IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error)
94  }