Documentation
¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func IsError(e interface{}, codes ...ErrorCode) bool
- func UseLogger(logger flog.Logger)
- type Builder
- func (b *Builder) AddEdge(ctx context.Context, edge *models.ChannelEdgeInfo, op ...batch.SchedulerOption) error
- func (b *Builder) AddNode(ctx context.Context, node *models.Node, op ...batch.SchedulerOption) error
- func (b *Builder) AddProof(chanID lnwire.ShortChannelID, proof *models.ChannelAuthProof) error
- func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool
- func (b *Builder) CurrentBlockHeight() (uint32, error)
- func (b *Builder) FetchNode(ctx context.Context, node route.Vertex) (*models.Node, error)
- func (b *Builder) ForAllOutgoingChannels(ctx context.Context, ...) error
- func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, ...)
- func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool
- func (b *Builder) IsPublicNode(node route.Vertex) (bool, error)
- func (b *Builder) IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time, ...) bool
- func (b *Builder) IsStaleNode(ctx context.Context, node route.Vertex, timestamp time.Time) bool
- func (b *Builder) IsZombieChannel(updateTime1, updateTime2 time.Time) bool
- func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error)
- func (b *Builder) MarkEdgeLive(chanID lnwire.ShortChannelID) error
- func (b *Builder) MarkZombieEdge(chanID uint64) error
- func (b *Builder) Start() error
- func (b *Builder) Stop() error
- func (b *Builder) SyncedHeight() uint32
- func (b *Builder) UpdateEdge(ctx context.Context, update *models.ChannelEdgePolicy, ...) error
- type ChannelGraphSource
- type Config
- type Error
- type ErrorCode
Constants ¶
const ( // DefaultChannelPruneExpiry is the default duration used to determine // if a channel should be pruned or not. DefaultChannelPruneExpiry = time.Hour * 24 * 14 // DefaultFirstTimePruneDelay is the time we'll wait after startup // before attempting to prune the graph for zombie channels. We don't // do it immediately after startup to allow lnd to start up without // getting blocked by this job. DefaultFirstTimePruneDelay = 30 * time.Second )
const Subsystem = "GRPH"
Variables ¶
var ( // ErrGraphBuilderShuttingDown is returned if the graph builder is in // the process of shutting down. ErrGraphBuilderShuttingDown = fmt.Errorf("graph builder shutting down") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds and maintains a view of the Lightning Network graph.
func NewBuilder ¶
NewBuilder constructs a new Builder.
func (*Builder) AddEdge ¶
func (b *Builder) AddEdge(ctx context.Context, edge *models.ChannelEdgeInfo, op ...batch.SchedulerOption) error
AddEdge is used to add edge/channel to the topology of the router, after all information about channel will be gathered this edge/channel might be used in construction of payment path.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) AddNode ¶
func (b *Builder) AddNode(ctx context.Context, node *models.Node, op ...batch.SchedulerOption) error
AddNode is used to add information about a node to the router database. If the node with this pubkey is not present in an existing channel, it will be ignored.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) AddProof ¶
func (b *Builder) AddProof(chanID lnwire.ShortChannelID, proof *models.ChannelAuthProof) error
AddProof updates the channel edge info with proof which is needed to properly announce the edge to the rest of the network.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) ApplyChannelUpdate ¶
func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool
ApplyChannelUpdate validates a channel update and if valid, applies it to the database. It returns a bool indicating whether the updates were successful.
func (*Builder) CurrentBlockHeight ¶
CurrentBlockHeight returns the block height from POV of the router subsystem.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) FetchNode ¶
FetchNode attempts to look up a target node by its identity public key. graphdb.ErrGraphNodeNotFound is returned if the node doesn't exist within the graph.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) ForAllOutgoingChannels ¶
func (b *Builder) ForAllOutgoingChannels(ctx context.Context, cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error, reset func()) error
ForAllOutgoingChannels is used to iterate over all outgoing channels owned by the router.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) GetChannelByID ¶
func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) ( *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error)
GetChannelByID return the channel by the channel id.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) IsKnownEdge ¶
func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool
IsKnownEdge returns true if the graph source already knows of the passed channel ID either as a live or zombie edge.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) IsPublicNode ¶
IsPublicNode determines whether the given vertex is seen as a public node in the graph from the graph's source node's point of view.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) IsStaleEdgePolicy ¶
func (b *Builder) IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time, flags lnwire.ChanUpdateChanFlags) bool
IsStaleEdgePolicy returns true if the graph source has a channel edge for the passed channel ID (and flags) that have a more recent timestamp.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) IsStaleNode ¶
IsStaleNode returns true if the graph source has a node announcement for the target node with a more recent timestamp.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) IsZombieChannel ¶
IsZombieChannel takes the timestamps of the latest channel updates for a channel and returns true if the channel should be considered a zombie based on these timestamps.
func (*Builder) IsZombieEdge ¶
func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error)
IsZombieEdge returns true if the graph source has marked the given channel ID as a zombie edge.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) MarkEdgeLive ¶
func (b *Builder) MarkEdgeLive(chanID lnwire.ShortChannelID) error
MarkEdgeLive clears an edge from our zombie index, deeming it as live.
NOTE: This method is part of the ChannelGraphSource interface.
func (*Builder) MarkZombieEdge ¶
MarkZombieEdge adds a channel that failed complete validation into the zombie index so we can avoid having to re-validate it in the future.
func (*Builder) Start ¶
Start launches all the goroutines the Builder requires to carry out its duties. If the builder has already been started, then this method is a noop.
func (*Builder) Stop ¶
Stop signals to the Builder that it should halt all routines. This method will *block* until all goroutines have excited. If the builder has already stopped then this method will return immediately.
func (*Builder) SyncedHeight ¶
SyncedHeight returns the block height to which the router subsystem currently is synced to. This can differ from the above chain height if the goroutine responsible for processing the blocks isn't yet up to speed.
func (*Builder) UpdateEdge ¶
func (b *Builder) UpdateEdge(ctx context.Context, update *models.ChannelEdgePolicy, op ...batch.SchedulerOption) error
UpdateEdge is used to update edge information, without this message edge considered as not fully constructed.
NOTE: This method is part of the ChannelGraphSource interface.
type ChannelGraphSource ¶
type ChannelGraphSource interface {
// AddNode is used to add information about a node to the router
// database. If the node with this pubkey is not present in an existing
// channel, it will be ignored.
AddNode(ctx context.Context, node *models.Node,
op ...batch.SchedulerOption) error
// AddEdge is used to add edge/channel to the topology of the router,
// after all information about channel will be gathered this
// edge/channel might be used in construction of payment path.
AddEdge(ctx context.Context, edge *models.ChannelEdgeInfo,
op ...batch.SchedulerOption) error
// AddProof updates the channel edge info with proof which is needed to
// properly announce the edge to the rest of the network.
AddProof(chanID lnwire.ShortChannelID,
proof *models.ChannelAuthProof) error
// UpdateEdge is used to update edge information, without this message
// edge considered as not fully constructed.
UpdateEdge(ctx context.Context, policy *models.ChannelEdgePolicy,
op ...batch.SchedulerOption) error
// IsStaleNode returns true if the graph source has a node announcement
// for the target node with a more recent timestamp. This method will
// also return true if we don't have an active channel announcement for
// the target node.
IsStaleNode(ctx context.Context, node route.Vertex,
timestamp time.Time) bool
// IsPublicNode determines whether the given vertex is seen as a public
// node in the graph from the graph's source node's point of view.
IsPublicNode(node route.Vertex) (bool, error)
// IsKnownEdge returns true if the graph source already knows of the
// passed channel ID either as a live or zombie edge.
IsKnownEdge(chanID lnwire.ShortChannelID) bool
// IsStaleEdgePolicy returns true if the graph source has a channel
// edge for the passed channel ID (and flags) that have a more recent
// timestamp.
IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time,
flags lnwire.ChanUpdateChanFlags) bool
// MarkEdgeLive clears an edge from our zombie index, deeming it as
// live.
MarkEdgeLive(chanID lnwire.ShortChannelID) error
// ForAllOutgoingChannels is used to iterate over all channels
// emanating from the "source" node which is the center of the
// star-graph.
ForAllOutgoingChannels(ctx context.Context,
cb func(c *models.ChannelEdgeInfo,
e *models.ChannelEdgePolicy) error, reset func()) error
// CurrentBlockHeight returns the block height from POV of the router
// subsystem.
CurrentBlockHeight() (uint32, error)
// GetChannelByID return the channel by the channel id.
GetChannelByID(chanID lnwire.ShortChannelID) (
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
*models.ChannelEdgePolicy, error)
// FetchNode attempts to look up a target node by its identity
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
// doesn't exist within the graph.
FetchNode(context.Context, route.Vertex) (*models.Node, error)
// MarkZombieEdge marks the channel with the given ID as a zombie edge.
MarkZombieEdge(chanID uint64) error
// IsZombieEdge returns true if the edge with the given channel ID is
// currently marked as a zombie edge.
IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error)
}
ChannelGraphSource represents the source of information about the topology of the lightning network. It's responsible for the addition of nodes, edges, applying edge updates, and returning the current block height with which the topology is synchronized.
type Config ¶
type Config struct {
// SelfNode is the public key of the node that this channel router
// belongs to.
SelfNode route.Vertex
// Graph is the channel graph that the ChannelRouter will use to gather
// metrics from and also to carry out path finding queries.
Graph *graphdb.ChannelGraph
// Chain is the router's source to the most up-to-date blockchain data.
// All incoming advertised channels will be checked against the chain
// to ensure that the channels advertised are still open.
Chain lnwallet.BlockChainIO
// ChainView is an instance of a FilteredChainView which is used to
// watch the sub-set of the UTXO set (the set of active channels) that
// we need in order to properly maintain the channel graph.
ChainView chainview.FilteredChainView
// Notifier is a reference to the ChainNotifier, used to grab
// the latest blocks if the router is missing any.
Notifier chainntnfs.ChainNotifier
// ChannelPruneExpiry is the duration used to determine if a channel
// should be pruned or not. If the delta between now and when the
// channel was last updated is greater than ChannelPruneExpiry, then
// the channel is marked as a zombie channel eligible for pruning.
ChannelPruneExpiry time.Duration
// GraphPruneInterval is used as an interval to determine how often we
// should examine the channel graph to garbage collect zombie channels.
GraphPruneInterval time.Duration
// FirstTimePruneDelay is the time we'll wait after startup before
// attempting to prune the graph for zombie channels. We don't do it
// immediately after startup to allow lnd to start up without getting
// blocked by this job.
FirstTimePruneDelay time.Duration
// AssumeChannelValid toggles whether the builder will prune channels
// based on their spentness vs using the fact that they are considered
// zombies.
AssumeChannelValid bool
// StrictZombiePruning determines if we attempt to prune zombie
// channels according to a stricter criteria. If true, then we'll prune
// a channel if only *one* of the edges is considered a zombie.
// Otherwise, we'll only prune the channel when both edges have a very
// dated last update.
StrictZombiePruning bool
// IsAlias returns whether a passed ShortChannelID is an alias. This is
// only used for our local channels.
IsAlias func(scid lnwire.ShortChannelID) bool
}
Config holds the configuration required by the Builder.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a structure that represent the error inside the graph package, this structure carries additional information about error code in order to be able distinguish errors outside of the current package.
type ErrorCode ¶
type ErrorCode uint8
ErrorCode is used to represent the various errors that can occur within this package.
const ( // ErrOutdated is returned when the routing update already have // been applied, or a newer update is already known. ErrOutdated ErrorCode = iota // ErrIgnored is returned when the update have been ignored because // this update can't bring us something new, or because a node // announcement was given for node not found in any channel. ErrIgnored )