discovery

package
v0.0.0-...-bd4bb24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxChannelUpdateBurst is the default maximum number of updates
	// for a specific channel and direction that we'll accept over an
	// interval.
	DefaultMaxChannelUpdateBurst = 10

	// DefaultChannelUpdateInterval is the default interval we'll use to
	// determine how often we should allow a new update for a specific
	// channel and direction.
	DefaultChannelUpdateInterval = time.Minute
)
View Source
const (
	// DefaultSyncerRotationInterval is the default interval in which we'll
	// rotate a single active syncer.
	DefaultSyncerRotationInterval = 20 * time.Minute

	// DefaultHistoricalSyncInterval is the default interval in which we'll
	// force a historical sync to ensure we have as much of the public
	// network as possible.
	DefaultHistoricalSyncInterval = time.Hour
)
View Source
const (
	// DefaultMaxUndelayedQueryReplies specifies how many gossip queries we
	// will respond to immediately before starting to delay responses.
	DefaultMaxUndelayedQueryReplies = 10

	// DefaultDelayedQueryReplyInterval is the length of time we will wait
	// before responding to gossip queries after replying to
	// maxUndelayedQueryReplies queries.
	DefaultDelayedQueryReplyInterval = 5 * time.Second
)

Variables

View Source
var (
	// ErrGossiperShuttingDown is an error that is returned if the gossiper
	// is in the process of being shut down.
	ErrGossiperShuttingDown = errors.New("gossiper is shutting down")

	// ErrGossipSyncerNotFound signals that we were unable to find an active
	// gossip syncer corresponding to a gossip query message received from
	// the remote peer.
	ErrGossipSyncerNotFound = errors.New("gossip syncer not found")
)
View Source
var (

	// ErrUnsupportedMessage is an error returned when we attempt to add a
	// message to the store that is not supported.
	ErrUnsupportedMessage = errors.New("unsupported message type")

	// ErrCorruptedMessageStore indicates that the on-disk bucketing
	// structure has altered since the gossip message store instance was
	// initialized.
	ErrCorruptedMessageStore = errors.New("gossip message store has been " +
		"corrupted")
)
View Source
var (

	// ErrGossipSyncerExiting signals that the syncer has been killed.
	ErrGossipSyncerExiting = errors.New("gossip syncer exiting")

	// ErrSyncTransitionTimeout is an error returned when we've timed out
	// attempting to perform a sync transition.
	ErrSyncTransitionTimeout = errors.New("timed out attempting to " +
		"transition sync type")
)
View Source
var (
	// ErrSyncManagerExiting is an error returned when we attempt to
	// start/stop a gossip syncer for a connected/disconnected peer, but the
	// SyncManager has already been stopped.
	ErrSyncManagerExiting = errors.New("sync manager exiting")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func IsKeepAliveUpdate

func IsKeepAliveUpdate(update *lnwire.ChannelUpdate,
	prev *channeldb.ChannelEdgePolicy) bool

IsKeepAliveUpdate determines whether this channel update is considered a keep-alive update based on the previous channel update processed for the same direction.

func MultiSourceBootstrap

func MultiSourceBootstrap(ignore map[autopilot.NodeID]struct{}, numAddrs uint32,
	bootstrappers ...NetworkPeerBootstrapper) ([]*lnwire.NetAddress, error)

MultiSourceBootstrap attempts to utilize a set of NetworkPeerBootstrapper passed in to return the target (numAddrs) number of peer addresses that can be used to bootstrap a peer just joining the Lightning Network. Each bootstrapper will be queried successively until the target amount is met. If the ignore map is populated, then the bootstrappers will be instructed to skip those nodes.

func UseLogger

func UseLogger(logger bronlog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using bronlog.

Types

type AuthenticatedGossiper

type AuthenticatedGossiper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

AuthenticatedGossiper is a subsystem which is responsible for receiving announcements, validating them and applying the changes to router, syncing lightning network with newly connected nodes, broadcasting announcements after validation, negotiating the channel announcement proofs exchange and handling the premature announcements. All outgoing announcements are expected to be properly signed as dictated in BOLT#7, additionally, all incoming message are expected to be well formed and signed. Invalid messages will be rejected by this struct.

func New

func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper

New creates a new AuthenticatedGossiper instance, initialized with the passed configuration parameters.

func (*AuthenticatedGossiper) InitSyncState

func (d *AuthenticatedGossiper) InitSyncState(syncPeer lnpeer.Peer)

InitSyncState is called by outside sub-systems when a connection is established to a new peer that understands how to perform channel range queries. We'll allocate a new gossip syncer for it, and start any goroutines needed to handle new queries.

func (*AuthenticatedGossiper) ProcessLocalAnnouncement

func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
	optionalFields ...OptionalMsgField) chan error

ProcessLocalAnnouncement sends a new remote announcement message along with the peer that sent the routing message. The announcement will be processed then added to a queue for batched trickled announcement to all connected peers. Local channel announcements don't contain the announcement proof and will not be fully validated. Once the channel proofs are received, the entire channel announcement and update messages will be re-constructed and broadcast to the rest of the network.

func (*AuthenticatedGossiper) ProcessRemoteAnnouncement

func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
	peer lnpeer.Peer) chan error

ProcessRemoteAnnouncement sends a new remote announcement message along with the peer that sent the routing message. The announcement will be processed then added to a queue for batched trickled announcement to all connected peers. Remote channel announcements should contain the announcement proof and be fully validated.

func (*AuthenticatedGossiper) PropagateChanPolicyUpdate

func (d *AuthenticatedGossiper) PropagateChanPolicyUpdate(
	edgesToUpdate []EdgeWithInfo) error

PropagateChanPolicyUpdate signals the AuthenticatedGossiper to perform the specified edge updates. Updates are done in two stages: first, the AuthenticatedGossiper ensures the update has been committed by dependent sub-systems, then it signs and broadcasts new updates to the network. A mapping between outpoints and updated channel policies is returned, which is used to update the forwarding policies of the underlying links.

func (*AuthenticatedGossiper) PruneSyncState

func (d *AuthenticatedGossiper) PruneSyncState(peer route.Vertex)

PruneSyncState is called by outside sub-systems once a peer that we were previously connected to has been disconnected. In this case we can stop the existing GossipSyncer assigned to the peer and free up resources.

func (*AuthenticatedGossiper) Start

func (d *AuthenticatedGossiper) Start() error

Start spawns network messages handler goroutine and registers on new block notifications in order to properly handle the premature announcements.

func (*AuthenticatedGossiper) Stop

func (d *AuthenticatedGossiper) Stop() error

Stop signals any active goroutines for a graceful closure.

func (*AuthenticatedGossiper) SyncManager

func (d *AuthenticatedGossiper) SyncManager() *SyncManager

SyncManager returns the gossiper's SyncManager instance.

type ChanSeries

type ChanSeries struct {
	// contains filtered or unexported fields
}

ChanSeries is an implementation of the ChannelGraphTimeSeries interface backed by the channeldb ChannelGraph database. We'll provide this implementation to the AuthenticatedGossiper so it can properly use the in-protocol channel range queries to quickly and efficiently synchronize our channel state with all peers.

func NewChanSeries

func NewChanSeries(graph *channeldb.ChannelGraph) *ChanSeries

NewChanSeries constructs a new ChanSeries backed by a channeldb.ChannelGraph. The returned ChanSeries implements the ChannelGraphTimeSeries interface.

func (*ChanSeries) FetchChanAnns

func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
	shortChanIDs []lnwire.ShortChannelID) ([]lnwire.Message, error)

FetchChanAnns returns a full set of channel announcements as well as their updates that match the set of specified short channel ID's. We'll use this to reply to a QueryShortChanIDs message sent by a remote peer. The response will contain a unique set of ChannelAnnouncements, the latest ChannelUpdate for each of the announcements, and a unique set of NodeAnnouncements.

NOTE: This is part of the ChannelGraphTimeSeries interface.

func (*ChanSeries) FetchChanUpdates

func (c *ChanSeries) FetchChanUpdates(chain chainhash.Hash,
	shortChanID lnwire.ShortChannelID) ([]*lnwire.ChannelUpdate, error)

FetchChanUpdates returns the latest channel update messages for the specified short channel ID. If no channel updates are known for the channel, then an empty slice will be returned.

NOTE: This is part of the ChannelGraphTimeSeries interface.

func (*ChanSeries) FilterChannelRange

func (c *ChanSeries) FilterChannelRange(chain chainhash.Hash,
	startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error)

FilterChannelRange returns the set of channels that we created between the start height and the end height. The channel IDs are grouped by their common block height. We'll use this respond to a remote peer's QueryChannelRange message.

NOTE: This is part of the ChannelGraphTimeSeries interface.

func (*ChanSeries) FilterKnownChanIDs

func (c *ChanSeries) FilterKnownChanIDs(chain chainhash.Hash,
	superSet []lnwire.ShortChannelID) ([]lnwire.ShortChannelID, error)

FilterKnownChanIDs takes a target chain, and a set of channel ID's, and returns a filtered set of chan ID's. This filtered set of chan ID's represents the ID's that we don't know of which were in the passed superSet.

NOTE: This is part of the ChannelGraphTimeSeries interface.

func (*ChanSeries) HighestChanID

func (c *ChanSeries) HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error)

HighestChanID should return is the channel ID of the channel we know of that's furthest in the target chain. This channel will have a block height that's close to the current tip of the main chain as we know it. We'll use this to start our QueryChannelRange dance with the remote node.

NOTE: This is part of the ChannelGraphTimeSeries interface.

func (*ChanSeries) UpdatesInHorizon

func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
	startTime time.Time, endTime time.Time) ([]lnwire.Message, error)

UpdatesInHorizon returns all known channel and node updates with an update timestamp between the start time and end time. We'll use this to catch up a remote node to the set of channel updates that they may have missed out on within the target chain.

NOTE: This is part of the ChannelGraphTimeSeries interface.

type ChannelGraphBootstrapper

type ChannelGraphBootstrapper struct {
	// contains filtered or unexported fields
}

ChannelGraphBootstrapper is an implementation of the NetworkPeerBootstrapper which attempts to retrieve advertised peers directly from the active channel graph. This instance requires a backing autopilot.ChannelGraph instance in order to operate properly.

func (*ChannelGraphBootstrapper) Name

func (c *ChannelGraphBootstrapper) Name() string

Name returns a human readable string which names the concrete implementation of the NetworkPeerBootstrapper.

NOTE: Part of the NetworkPeerBootstrapper interface.

func (*ChannelGraphBootstrapper) SampleNodeAddrs

func (c *ChannelGraphBootstrapper) SampleNodeAddrs(numAddrs uint32,
	ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

SampleNodeAddrs uniformly samples a set of specified address from the network peer bootstrapper source. The num addrs field passed in denotes how many valid peer addresses to return.

NOTE: Part of the NetworkPeerBootstrapper interface.

type ChannelGraphTimeSeries

type ChannelGraphTimeSeries interface {
	// HighestChanID should return the channel ID of the channel we know of
	// that's furthest in the target chain. This channel will have a block
	// height that's close to the current tip of the main chain as we
	// know it.  We'll use this to start our QueryChannelRange dance with
	// the remote node.
	HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error)

	// UpdatesInHorizon returns all known channel and node updates with an
	// update timestamp between the start time and end time. We'll use this
	// to catch up a remote node to the set of channel updates that they
	// may have missed out on within the target chain.
	UpdatesInHorizon(chain chainhash.Hash,
		startTime time.Time, endTime time.Time) ([]lnwire.Message, error)

	// FilterKnownChanIDs takes a target chain, and a set of channel ID's,
	// and returns a filtered set of chan ID's. This filtered set of chan
	// ID's represents the ID's that we don't know of which were in the
	// passed superSet.
	FilterKnownChanIDs(chain chainhash.Hash,
		superSet []lnwire.ShortChannelID) ([]lnwire.ShortChannelID, error)

	// FilterChannelRange returns the set of channels that we created
	// between the start height and the end height. The channel IDs are
	// grouped by their common block height. We'll use this to to a remote
	// peer's QueryChannelRange message.
	FilterChannelRange(chain chainhash.Hash,
		startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error)

	// FetchChanAnns returns a full set of channel announcements as well as
	// their updates that match the set of specified short channel ID's.
	// We'll use this to reply to a QueryShortChanIDs message sent by a
	// remote peer. The response will contain a unique set of
	// ChannelAnnouncements, the latest ChannelUpdate for each of the
	// announcements, and a unique set of NodeAnnouncements.
	FetchChanAnns(chain chainhash.Hash,
		shortChanIDs []lnwire.ShortChannelID) ([]lnwire.Message, error)

	// FetchChanUpdates returns the latest channel update messages for the
	// specified short channel ID. If no channel updates are known for the
	// channel, then an empty slice will be returned.
	FetchChanUpdates(chain chainhash.Hash,
		shortChanID lnwire.ShortChannelID) ([]*lnwire.ChannelUpdate, error)
}

ChannelGraphTimeSeries is an interface that provides time and block based querying into our view of the channel graph. New channels will have monotonically increasing block heights, and new channel updates will have increasing timestamps. Once we connect to a peer, we'll use the methods in this interface to determine if we're already in sync, or need to request some new information from them.

type Config

type Config struct {
	// ChainHash is a hash that indicates which resident chain of the
	// AuthenticatedGossiper. Any announcements that don't match this
	// chain hash will be ignored.
	//
	// TODO(roasbeef): eventually make into map so can de-multiplex
	// incoming announcements
	//   * also need to do same for Notifier
	ChainHash chainhash.Hash

	// Router is the subsystem which is responsible for managing the
	// topology of lightning network. After incoming channel, node, channel
	// updates announcements are validated they are sent to the router in
	// order to be included in the LN graph.
	Router routing.ChannelGraphSource

	// ChanSeries is an interfaces that provides access to a time series
	// view of the current known channel graph. Each GossipSyncer enabled
	// peer will utilize this in order to create and respond to channel
	// graph time series queries.
	ChanSeries ChannelGraphTimeSeries

	// Notifier is used for receiving notifications of incoming blocks.
	// With each new incoming block found we process previously premature
	// announcements.
	//
	// TODO(roasbeef): could possibly just replace this with an epoch
	// channel.
	Notifier chainntnfs.ChainNotifier

	// Broadcast broadcasts a particular set of announcements to all peers
	// that the daemon is connected to. If supplied, the exclude parameter
	// indicates that the target peer should be excluded from the
	// broadcast.
	Broadcast func(skips map[route.Vertex]struct{},
		msg ...lnwire.Message) error

	// NotifyWhenOnline is a function that allows the gossiper to be
	// notified when a certain peer comes online, allowing it to
	// retry sending a peer message.
	//
	// NOTE: The peerChan channel must be buffered.
	NotifyWhenOnline func(peerPubKey [33]byte, peerChan chan<- lnpeer.Peer)

	// NotifyWhenOffline is a function that allows the gossiper to be
	// notified when a certain peer disconnects, allowing it to request a
	// notification for when it reconnects.
	NotifyWhenOffline func(peerPubKey [33]byte) <-chan struct{}

	// SelfNodeAnnouncement is a function that fetches our own current node
	// announcement, for use when determining whether we should update our
	// peers about our presence on the network. If the refresh is true, a
	// new and updated announcement will be returned.
	SelfNodeAnnouncement func(refresh bool) (lnwire.NodeAnnouncement, error)

	// ProofMatureDelta the number of confirmations which is needed before
	// exchange the channel announcement proofs.
	ProofMatureDelta uint32

	// TrickleDelay the period of trickle timer which flushes to the
	// network the pending batch of new announcements we've received since
	// the last trickle tick.
	TrickleDelay time.Duration

	// RetransmitTicker is a ticker that ticks with a period which
	// indicates that we should check if we need re-broadcast any of our
	// personal channels.
	RetransmitTicker ticker.Ticker

	// RebroadcastInterval is the maximum time we wait between sending out
	// channel updates for our active channels and our own node
	// announcement. We do this to ensure our active presence on the
	// network is known, and we are not being considered a zombie node or
	// having zombie channels.
	RebroadcastInterval time.Duration

	// WaitingProofStore is a persistent storage of partial channel proof
	// announcement messages. We use it to buffer half of the material
	// needed to reconstruct a full authenticated channel announcement.
	// Once we receive the other half the channel proof, we'll be able to
	// properly validate it and re-broadcast it out to the network.
	//
	// TODO(wilmer): make interface to prevent channeldb dependency.
	WaitingProofStore *channeldb.WaitingProofStore

	// MessageStore is a persistent storage of gossip messages which we will
	// use to determine which messages need to be resent for a given peer.
	MessageStore GossipMessageStore

	// AnnSigner is an instance of the MessageSigner interface which will
	// be used to manually sign any outgoing channel updates. The signer
	// implementation should be backed by the public key of the backing
	// Lightning node.
	//
	// TODO(roasbeef): extract ann crafting + sign from fundingMgr into
	// here?
	AnnSigner lnwallet.MessageSigner

	// NumActiveSyncers is the number of peers for which we should have
	// active syncers with. After reaching NumActiveSyncers, any future
	// gossip syncers will be passive.
	NumActiveSyncers int

	// RotateTicker is a ticker responsible for notifying the SyncManager
	// when it should rotate its active syncers. A single active syncer with
	// a chansSynced state will be exchanged for a passive syncer in order
	// to ensure we don't keep syncing with the same peers.
	RotateTicker ticker.Ticker

	// HistoricalSyncTicker is a ticker responsible for notifying the
	// syncManager when it should attempt a historical sync with a gossip
	// sync peer.
	HistoricalSyncTicker ticker.Ticker

	// ActiveSyncerTimeoutTicker is a ticker responsible for notifying the
	// syncManager when it should attempt to start the next pending
	// activeSyncer due to the current one not completing its state machine
	// within the timeout.
	ActiveSyncerTimeoutTicker ticker.Ticker

	// MinimumBatchSize is minimum size of a sub batch of announcement
	// messages.
	MinimumBatchSize int

	// SubBatchDelay is the delay between sending sub batches of
	// gossip messages.
	SubBatchDelay time.Duration

	// IgnoreHistoricalFilters will prevent syncers from replying with
	// historical data when the remote peer sets a gossip_timestamp_range.
	// This prevents ranges with old start times from causing us to dump the
	// graph on connect.
	IgnoreHistoricalFilters bool

	// PinnedSyncers is a set of peers that will always transition to
	// ActiveSync upon connection. These peers will never transition to
	// PassiveSync.
	PinnedSyncers PinnedSyncers

	// MaxChannelUpdateBurst specifies the maximum number of updates for a
	// specific channel and direction that we'll accept over an interval.
	MaxChannelUpdateBurst int

	// ChannelUpdateInterval specifies the interval we'll use to determine
	// how often we should allow a new update for a specific channel and
	// direction.
	ChannelUpdateInterval time.Duration
}

Config defines the configuration for the service. ALL elements within the configuration MUST be non-nil for the service to carry out its duties.

type DNSSeedBootstrapper

type DNSSeedBootstrapper struct {
	// contains filtered or unexported fields
}

DNSSeedBootstrapper as an implementation of the NetworkPeerBootstrapper interface which implements peer bootstrapping via a special DNS seed as defined in BOLT-0010. For further details concerning Lightning's current DNS boot strapping protocol, see this link:

func (*DNSSeedBootstrapper) Name

func (d *DNSSeedBootstrapper) Name() string

Name returns a human readable string which names the concrete implementation of the NetworkPeerBootstrapper.

func (*DNSSeedBootstrapper) SampleNodeAddrs

func (d *DNSSeedBootstrapper) SampleNodeAddrs(numAddrs uint32,
	ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

SampleNodeAddrs uniformly samples a set of specified address from the network peer bootstrapper source. The num addrs field passed in denotes how many valid peer addresses to return. The set of DNS seeds are used successively to retrieve eligible target nodes.

type EdgeWithInfo

type EdgeWithInfo struct {
	// Info describes the channel.
	Info *channeldb.ChannelEdgeInfo

	// Edge describes the policy in one direction of the channel.
	Edge *channeldb.ChannelEdgePolicy
}

EdgeWithInfo contains the information that is required to update an edge.

type GossipMessageStore

type GossipMessageStore interface {
	// AddMessage adds a message to the store for this peer.
	AddMessage(lnwire.Message, [33]byte) error

	// DeleteMessage deletes a message from the store for this peer.
	DeleteMessage(lnwire.Message, [33]byte) error

	// Messages returns the total set of messages that exist within the
	// store for all peers.
	Messages() (map[[33]byte][]lnwire.Message, error)

	// Peers returns the public key of all peers with messages within the
	// store.
	Peers() (map[[33]byte]struct{}, error)

	// MessagesForPeer returns the set of messages that exists within the
	// store for the given peer.
	MessagesForPeer([33]byte) ([]lnwire.Message, error)
}

GossipMessageStore is a store responsible for storing gossip messages which we should reliably send to our peers.

type GossipSyncer

type GossipSyncer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

GossipSyncer is a struct that handles synchronizing the channel graph state with a remote peer. The GossipSyncer implements a state machine that will progressively ensure we're synchronized with the channel state of the remote node. Once both nodes have been synchronized, we'll use an update filter to filter out which messages should be sent to a remote peer based on their update horizon. If the update horizon isn't specified, then we won't send them any channel updates at all.

func (*GossipSyncer) ApplyGossipFilter

func (g *GossipSyncer) ApplyGossipFilter(filter *lnwire.GossipTimestampRange) error

ApplyGossipFilter applies a gossiper filter sent by the remote node to the state machine. Once applied, we'll ensure that we don't forward any messages to the peer that aren't within the time range of the filter.

func (*GossipSyncer) FilterGossipMsgs

func (g *GossipSyncer) FilterGossipMsgs(msgs ...msgWithSenders)

FilterGossipMsgs takes a set of gossip messages, and only send it to a peer iff the message is within the bounds of their set gossip filter. If the peer doesn't have a gossip filter set, then no messages will be forwarded.

func (*GossipSyncer) ProcessQueryMsg

func (g *GossipSyncer) ProcessQueryMsg(msg lnwire.Message, peerQuit <-chan struct{}) error

ProcessQueryMsg is used by outside callers to pass new channel time series queries to the internal processing goroutine.

func (*GossipSyncer) ProcessSyncTransition

func (g *GossipSyncer) ProcessSyncTransition(newSyncType SyncerType) error

ProcessSyncTransition sends a request to the gossip syncer to transition its sync type to a new one.

NOTE: This can only be done once the gossip syncer has reached its final chansSynced state.

func (*GossipSyncer) ResetSyncedSignal

func (g *GossipSyncer) ResetSyncedSignal() chan struct{}

ResetSyncedSignal returns a channel that will be closed in order to serve as a signal for when the GossipSyncer has reached its chansSynced state.

func (*GossipSyncer) Start

func (g *GossipSyncer) Start()

Start starts the GossipSyncer and any goroutines that it needs to carry out its duties.

func (*GossipSyncer) Stop

func (g *GossipSyncer) Stop()

Stop signals the GossipSyncer for a graceful exit, then waits until it has exited.

func (*GossipSyncer) SyncType

func (g *GossipSyncer) SyncType() SyncerType

SyncType returns the current SyncerType of the target GossipSyncer.

type MessageStore

type MessageStore struct {
	// contains filtered or unexported fields
}

MessageStore is an implementation of the GossipMessageStore interface backed by a channeldb instance. By design, this store will only keep the latest version of a message (like in the case of multiple ChannelUpdate's) for a channel with a peer.

func NewMessageStore

func NewMessageStore(db kvdb.Backend) (*MessageStore, error)

NewMessageStore creates a new message store backed by a channeldb instance.

func (*MessageStore) AddMessage

func (s *MessageStore) AddMessage(msg lnwire.Message, peerPubKey [33]byte) error

AddMessage adds a message to the store for this peer.

func (*MessageStore) DeleteMessage

func (s *MessageStore) DeleteMessage(msg lnwire.Message,
	peerPubKey [33]byte) error

DeleteMessage deletes a message from the store for this peer.

func (*MessageStore) Messages

func (s *MessageStore) Messages() (map[[33]byte][]lnwire.Message, error)

Messages returns the total set of messages that exist within the store for all peers.

func (*MessageStore) MessagesForPeer

func (s *MessageStore) MessagesForPeer(
	peerPubKey [33]byte) ([]lnwire.Message, error)

MessagesForPeer returns the set of messages that exists within the store for the given peer.

func (*MessageStore) Peers

func (s *MessageStore) Peers() (map[[33]byte]struct{}, error)

Peers returns the public key of all peers with messages within the store.

type NetworkPeerBootstrapper

type NetworkPeerBootstrapper interface {
	// SampleNodeAddrs uniformly samples a set of specified address from
	// the network peer bootstrapper source. The num addrs field passed in
	// denotes how many valid peer addresses to return. The passed set of
	// node nodes allows the caller to ignore a set of nodes perhaps
	// because they already have connections established.
	SampleNodeAddrs(numAddrs uint32,
		ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

	// Name returns a human readable string which names the concrete
	// implementation of the NetworkPeerBootstrapper.
	Name() string
}

NetworkPeerBootstrapper is an interface that represents an initial peer bootstrap mechanism. This interface is to be used to bootstrap a new peer to the connection by providing it with the pubkey+address of a set of existing peers on the network. Several bootstrap mechanisms can be implemented such as DNS, in channel graph, DHT's, etc.

func NewDNSSeedBootstrapper

func NewDNSSeedBootstrapper(
	seeds [][2]string, net tor.Net,
	timeout time.Duration) NetworkPeerBootstrapper

NewDNSSeedBootstrapper returns a new instance of the DNSSeedBootstrapper. The set of passed seeds should point to DNS servers that properly implement Lightning's DNS peer bootstrapping protocol as defined in BOLT-0010. The set of passed DNS seeds should come in pairs, with the second host name to be used as a fallback for manual TCP resolution in the case of an error receiving the UDP response. The second host should return a single A record with the IP address of the authoritative name server.

func NewGraphBootstrapper

func NewGraphBootstrapper(cg autopilot.ChannelGraph) (NetworkPeerBootstrapper, error)

NewGraphBootstrapper returns a new instance of a ChannelGraphBootstrapper backed by an active autopilot.ChannelGraph instance. This type of network peer bootstrapper will use the authenticated nodes within the known channel graph to bootstrap connections.

type OptionalMsgField

type OptionalMsgField func(*optionalMsgFields)

OptionalMsgField is a functional option parameter that can be used to provide external information that is not included within a network message but serves useful when processing it.

func ChannelCapacity

func ChannelCapacity(capacity bronutil.Amount) OptionalMsgField

ChannelCapacity is an optional field that lets the gossiper know of the capacity of a channel.

func ChannelPoint

func ChannelPoint(op wire.OutPoint) OptionalMsgField

ChannelPoint is an optional field that lets the gossiper know of the outpoint of a channel.

type PinnedSyncers

type PinnedSyncers map[route.Vertex]struct{}

PinnedSyncers is a set of node pubkeys for which we will maintain an active syncer at all times.

type SyncManager

type SyncManager struct {
	// contains filtered or unexported fields
}

SyncManager is a subsystem of the gossiper that manages the gossip syncers for peers currently connected. When a new peer is connected, the manager will create its accompanying gossip syncer and determine whether it should have an ActiveSync or PassiveSync sync type based on how many other gossip syncers are currently active. Any ActiveSync gossip syncers are started in a round-robin manner to ensure we're not syncing with multiple peers at the same time. The first GossipSyncer registered with the SyncManager will attempt a historical sync to ensure we have as much of the public channel graph as possible.

func (*SyncManager) GossipSyncer

func (m *SyncManager) GossipSyncer(peer route.Vertex) (*GossipSyncer, bool)

GossipSyncer returns the associated gossip syncer of a peer. The boolean returned signals whether there exists a gossip syncer for the peer.

func (*SyncManager) GossipSyncers

func (m *SyncManager) GossipSyncers() map[route.Vertex]*GossipSyncer

GossipSyncers returns all of the currently initialized gossip syncers.

func (*SyncManager) InitSyncState

func (m *SyncManager) InitSyncState(peer lnpeer.Peer) error

InitSyncState is called by outside sub-systems when a connection is established to a new peer that understands how to perform channel range queries. We'll allocate a new GossipSyncer for it, and start any goroutines needed to handle new queries. The first GossipSyncer registered with the SyncManager will attempt a historical sync to ensure we have as much of the public channel graph as possible.

TODO(wilmer): Only mark as ActiveSync if this isn't a channel peer.

func (*SyncManager) IsGraphSynced

func (m *SyncManager) IsGraphSynced() bool

IsGraphSynced determines whether we've completed our initial historical sync. The initial historical sync is done to ensure we've ingested as much of the public graph as possible.

func (*SyncManager) PruneSyncState

func (m *SyncManager) PruneSyncState(peer route.Vertex)

PruneSyncState is called by outside sub-systems once a peer that we were previously connected to has been disconnected. In this case we can stop the existing GossipSyncer assigned to the peer and free up resources.

func (*SyncManager) Start

func (m *SyncManager) Start()

Start starts the SyncManager in order to properly carry out its duties.

func (*SyncManager) Stop

func (m *SyncManager) Stop()

Stop stops the SyncManager from performing its duties.

type SyncManagerCfg

type SyncManagerCfg struct {
	// ChainHash is a hash that indicates the specific network of the active
	// chain.
	ChainHash chainhash.Hash

	// ChanSeries is an interface that provides access to a time series view
	// of the current known channel graph. Each GossipSyncer enabled peer
	// will utilize this in order to create and respond to channel graph
	// time series queries.
	ChanSeries ChannelGraphTimeSeries

	// NumActiveSyncers is the number of peers for which we should have
	// active syncers with. After reaching NumActiveSyncers, any future
	// gossip syncers will be passive.
	NumActiveSyncers int

	// RotateTicker is a ticker responsible for notifying the SyncManager
	// when it should rotate its active syncers. A single active syncer with
	// a chansSynced state will be exchanged for a passive syncer in order
	// to ensure we don't keep syncing with the same peers.
	RotateTicker ticker.Ticker

	// HistoricalSyncTicker is a ticker responsible for notifying the
	// SyncManager when it should attempt a historical sync with a gossip
	// sync peer.
	HistoricalSyncTicker ticker.Ticker

	// IgnoreHistoricalFilters will prevent syncers from replying with
	// historical data when the remote peer sets a gossip_timestamp_range.
	// This prevents ranges with old start times from causing us to dump the
	// graph on connect.
	IgnoreHistoricalFilters bool

	// BestHeight returns the latest height known of the chain.
	BestHeight func() uint32

	// PinnedSyncers is a set of peers that will always transition to
	// ActiveSync upon connection. These peers will never transition to
	// PassiveSync.
	PinnedSyncers PinnedSyncers
}

SyncManagerCfg contains all of the dependencies required for the SyncManager to carry out its duties.

type SyncerType

type SyncerType uint8

SyncerType encapsulates the different types of syncing mechanisms for a gossip syncer.

const (
	// ActiveSync denotes that a gossip syncer:
	//
	// 1. Should not attempt to synchronize with the remote peer for
	//    missing channels.
	// 2. Should respond to queries from the remote peer.
	// 3. Should receive new updates from the remote peer.
	//
	// They are started in a chansSynced state in order to accomplish their
	// responsibilities above.
	ActiveSync SyncerType = iota

	// PassiveSync denotes that a gossip syncer:
	//
	// 1. Should not attempt to synchronize with the remote peer for
	//    missing channels.
	// 2. Should respond to queries from the remote peer.
	// 3. Should not receive new updates from the remote peer.
	//
	// They are started in a chansSynced state in order to accomplish their
	// responsibilities above.
	PassiveSync

	// PinnedSync denotes an ActiveSync that doesn't count towards the
	// default active syncer limits and is always active throughout the
	// duration of the peer's connection. Each pinned syncer will begin by
	// performing a historical sync to ensure we are well synchronized with
	// their routing table.
	PinnedSync
)

func (SyncerType) IsActiveSync

func (t SyncerType) IsActiveSync() bool

IsActiveSync returns true if the SyncerType should set a GossipTimestampRange allowing new gossip messages to be received from the peer.

func (SyncerType) String

func (t SyncerType) String() string

String returns a human readable string describing the target SyncerType.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL