discovery

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

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 CreateChanAnnouncement

CreateChanAnnouncement is a helper function which creates all channel announcements given the necessary channel related database items. This function is used to transform out database structs into the corresponding wire structs for announcing new channels to other peers, or simply syncing up a peer's initial routing table upon connect.

func DisableLog

func DisableLog()

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

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 SignAnnouncement

func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
	msg lnwire.Message) (*btcec.Signature, error)

SignAnnouncement is a helper function which is used to sign any outgoing channel node node announcement messages.

func UseLogger

func UseLogger(logger btclog.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 btclog.

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, selfKey *btcec.PublicKey) *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,
	source *btcec.PublicKey, 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(
	newSchema routing.ChannelPolicy, chanPoints ...wire.OutPoint) error

PropagateChanPolicyUpdate signals the AuthenticatedGossiper to update the channel forwarding policies for the specified channels. If no channels are specified, then the update will be applied to all outgoing channels from the source node. Policy 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.

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()

Stop signals any active goroutines for a graceful closure.

func (*AuthenticatedGossiper) SyncManager

func (d *AuthenticatedGossiper) SyncManager() *SyncManager

SyncManager returns the gossiper's SyncManager instance.

func (*AuthenticatedGossiper) SynchronizeNode

func (d *AuthenticatedGossiper) SynchronizeNode(syncPeer lnpeer.Peer) error

SynchronizeNode sends a message to the service indicating it should synchronize lightning topology state with the target node. This method is to be utilized when a node connections for the first time to provide it with the latest topology update state. In order to accomplish this, (currently) the entire network graph is read from disk, then serialized to the format defined within the current wire protocol. This cache of graph data is then sent directly to the target node.

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) ([]lnwire.ShortChannelID, error)

FilterChannelRange returns the set of channels that we created between the start height and the end 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. We'll use this to to a
	// remote peer's QueryChannelRange message.
	FilterChannelRange(chain chainhash.Hash,
		startHeight, endHeight uint32) ([]lnwire.ShortChannelID, 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.
	//
	// TODO(wilmer): use [33]byte to avoid unnecessary serializations.
	NotifyWhenOnline func(peer *btcec.PublicKey, 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{}

	// 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

	// RetransmitDelay is the period of a timer which indicates that we
	// should check if we need re-broadcast any of our personal channels.
	RetransmitDelay 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
}

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 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{})

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 *channeldb.DB) (*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) 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 btcutil.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 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) 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
}

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
)

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