netann

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChanStatusManagerExiting signals that a shutdown of the
	// ChanStatusManager has already been requested.
	ErrChanStatusManagerExiting = errors.New("chan status manager exiting")

	// ErrInvalidTimeoutConstraints signals that the ChanStatusManager could
	// not be initialized because the timeouts and sample intervals were
	// malformed.
	ErrInvalidTimeoutConstraints = errors.New("active_timeout + " +
		"sample_interval must be less than or equal to " +
		"inactive_timeout and be positive integers")

	// ErrEnableInactiveChan signals that a request to enable a channel
	// could not be completed because the channel isn't actually active at
	// the time of the request.
	ErrEnableInactiveChan = errors.New("unable to enable channel which " +
		"is not currently active")
)

Functions

func ChannelUpdateFromEdge

func ChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
	policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error)

ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge info and policy.

func DisableLog

func DisableLog()

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

func ExtractChannelUpdate

func ExtractChannelUpdate(ownerPubKey []byte,
	info *channeldb.ChannelEdgeInfo,
	policies ...*channeldb.ChannelEdgePolicy) (
	*lnwire.ChannelUpdate, error)

ExtractChannelUpdate attempts to retrieve a lnwire.ChannelUpdate message from an edge's info and a set of routing policies.

NOTE: The passed policies can be nil.

func SignChannelUpdate

func SignChannelUpdate(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
	update *lnwire.ChannelUpdate, mods ...ChannelUpdateModifier) error

SignChannelUpdate applies the given modifiers to the passed lnwire.ChannelUpdate, then signs the resulting update. The provided update should be the most recent, valid update, otherwise the timestamp may not monotonically increase from the prior.

NOTE: This method modifies the given update.

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 ChanStatus

type ChanStatus uint8

ChanStatus is a type that enumerates the possible states a ChanStatusManager tracks for its known channels.

const (
	// ChanStatusEnabled indicates that the channel's last announcement has
	// the disabled bit cleared.
	ChanStatusEnabled ChanStatus = iota

	// ChanStatusPendingDisabled indicates that the channel's last
	// announcement has the disabled bit cleared, but that the channel was
	// detected in an inactive state. Channels in this state will have a
	// disabling announcement sent after the ChanInactiveTimeout expires
	// from the time of the first detection--unless the channel is
	// explicitly reenabled before the disabling occurs.
	ChanStatusPendingDisabled

	// ChanStatusDisabled indicates that the channel's last announcement has
	// the disabled bit set.
	ChanStatusDisabled
)

type ChanStatusConfig

type ChanStatusConfig struct {
	// OurPubKey is the public key identifying this node on the network.
	OurPubKey *btcec.PublicKey

	// MessageSigner signs messages that validate under OurPubKey.
	MessageSigner lnwallet.MessageSigner

	// IsChannelActive checks whether the channel identified by the provided
	// ChannelID is considered active. This should only return true if the
	// channel has been sufficiently confirmed, the channel has received
	// FundingLocked, and the remote peer is online.
	IsChannelActive func(lnwire.ChannelID) bool

	// ApplyChannelUpdate processes new ChannelUpdates signed by our node by
	// updating our local routing table and broadcasting the update to our
	// peers.
	ApplyChannelUpdate func(*lnwire.ChannelUpdate) error

	// DB stores the set of channels that are to be monitored.
	DB DB

	// Graph stores the channel info and policies for channels in DB.
	Graph ChannelGraph

	// ChanEnableTimeout is the duration a peer's connect must remain stable
	// before attempting to reenable the channel.
	//
	// NOTE: This value is only used to verify that the relation between
	// itself, ChanDisableTimeout, and ChanStatusSampleInterval is correct.
	// The user is still responsible for ensuring that the same duration
	// elapses before attempting to reenable a channel.
	ChanEnableTimeout time.Duration

	// ChanDisableTimeout is the duration the manager will wait after
	// detecting that a channel has become inactive before broadcasting an
	// update to disable the channel.
	ChanDisableTimeout time.Duration

	// ChanStatusSampleInterval is the long-polling interval used by the
	// manager to check if the channels being monitored have become
	// inactive.
	ChanStatusSampleInterval time.Duration
}

ChanStatusConfig holds parameters and resources required by the ChanStatusManager to perform its duty.

type ChanStatusManager

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

ChanStatusManager facilitates requests to enable or disable a channel via a network announcement that sets the disable bit on the ChannelUpdate accordingly. The manager will periodically sample to detect cases where a link has become inactive, and facilitate the process of disabling the channel passively. The ChanStatusManager state machine is designed to reduce the likelihood of spamming the network with updates for flapping peers.

func NewChanStatusManager

func NewChanStatusManager(cfg *ChanStatusConfig) (*ChanStatusManager, error)

NewChanStatusManager initializes a new ChanStatusManager using the given configuration. An error is returned if the timeouts and sample interval fail to meet do not satisfy the equation:

ChanEnableTimeout + ChanStatusSampleInterval > ChanDisableTimeout.

func (*ChanStatusManager) RequestDisable

func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint) error

RequestDisable submits a request to immediately disable a channel identified by the provided outpoint. If the channel is already disabled, no action will be taken. Otherwise, a new announcement will be signed with the disabled bit set and broadcast to the network.

func (*ChanStatusManager) RequestEnable

func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint) error

RequestEnable submits a request to immediately enable a channel identified by the provided outpoint. If the channel is already enabled, no action will be taken. If the channel is marked pending-disable the channel will be returned to an active status as the scheduled disable was never sent. Otherwise if the channel is found to be disabled, a new announcement will be signed with the disabled bit cleared and broadcast to the network.

NOTE: RequestEnable should only be called after a stable connection with the channel's peer has lasted at least the ChanEnableTimeout. Failure to do so may result in behavior that deviates from the expected behavior of the state machine.

func (*ChanStatusManager) Start

func (m *ChanStatusManager) Start() error

Start safely starts the ChanStatusManager.

func (*ChanStatusManager) Stop

func (m *ChanStatusManager) Stop() error

Stop safely shuts down the ChanStatusManager.

type ChannelGraph

type ChannelGraph interface {
	// FetchChannelEdgesByOutpoint returns the channel edge info and most
	// recent channel edge policies for a given outpoint.
	FetchChannelEdgesByOutpoint(*wire.OutPoint) (*channeldb.ChannelEdgeInfo,
		*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy, error)
}

ChannelGraph abstracts the required channel graph queries used by the ChanStatusManager.

type ChannelState

type ChannelState struct {
	// Status is the channel's current ChanStatus from the POV of the
	// ChanStatusManager.
	Status ChanStatus

	// SendDisableTime is the earliest time at which the ChanStatusManager
	// will passively send a new disable announcement on behalf of this
	// channel.
	//
	// NOTE: This field is only non-zero if status is
	// ChanStatusPendingDisabled.
	SendDisableTime time.Time
}

ChannelState describes the ChanStatusManager's view of a channel, and describes the current state the channel's disabled status on the network.

type ChannelUpdateModifier

type ChannelUpdateModifier func(*lnwire.ChannelUpdate)

ChannelUpdateModifier is a closure that makes in-place modifications to an lnwire.ChannelUpdate.

func ChannelUpdateSetDisable

func ChannelUpdateSetDisable(disabled bool) ChannelUpdateModifier

ChannelUpdateSetDisable sets the disabled channel flag if disabled is true, and clears the bit otherwise.

type DB

type DB interface {
	// FetchAllOpenChannels returns a slice of all open channels known to
	// the daemon. This may include private or pending channels.
	FetchAllOpenChannels() ([]*channeldb.OpenChannel, error)
}

DB abstracts the required database functionality needed by the ChanStatusManager.

type NodeSigner

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

NodeSigner is an implementation of the MessageSigner interface backed by the identity private key of running lnd node.

func NewNodeSigner

func NewNodeSigner(key *btcec.PrivateKey) *NodeSigner

NewNodeSigner creates a new instance of the NodeSigner backed by the target private key.

func (*NodeSigner) SignCompact

func (n *NodeSigner) SignCompact(msg []byte) ([]byte, error)

SignCompact signs a double-sha256 digest of the msg parameter under the resident node's private key. The returned signature is a pubkey-recoverable signature.

func (*NodeSigner) SignDigestCompact

func (n *NodeSigner) SignDigestCompact(hash []byte) ([]byte, error)

SignDigestCompact signs the provided message digest under the resident node's private key. The returned signature is a pubkey-recoverable signature.

func (*NodeSigner) SignMessage

func (n *NodeSigner) SignMessage(pubKey *btcec.PublicKey,
	msg []byte) (*btcec.Signature, error)

SignMessage signs a double-sha256 digest of the passed msg under the resident node's private key. If the target public key is _not_ the node's private key, then an error will be returned.

Jump to

Keyboard shortcuts

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