chanfitness

package
v0.15.5-beta Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package chanfitness monitors the behaviour of channels to provide insight into the health and performance of a channel. This is achieved by maintaining an event store which tracks events for each channel.

Lifespan: the period that the channel has been known to the scoring system. Note that lifespan may not equal the channel's full lifetime because data is not currently persisted.

Uptime: the total time within a given period that the channel's remote peer has been online.

Index

Constants

View Source
const (
	// FlapCountFlushRate determines how often we write peer total flap
	// count to disk.
	FlapCountFlushRate = time.Hour
)
View Source
const Subsystem = "CHFT"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (

	// ErrChannelNotFound is returned when a query is made for a channel
	// that the event store does not have knowledge of.
	ErrChannelNotFound = errors.New("channel not found in event store")

	// ErrPeerNotFound is returned when a query is made for a channel
	// that has a peer that the event store is not currently tracking.
	ErrPeerNotFound = errors.New("peer not found in event store")
)

Functions

func DisableLog

func DisableLog()

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

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 ChannelEventStore

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

ChannelEventStore maintains a set of event logs for the node's channels to provide insight into the performance and health of channels.

func NewChannelEventStore

func NewChannelEventStore(config *Config) *ChannelEventStore

NewChannelEventStore initializes an event store with the config provided. Note that this function does not start the main event loop, Start() must be called.

func (*ChannelEventStore) FlapCount

func (c *ChannelEventStore) FlapCount(peer route.Vertex) (int, *time.Time,
	error)

FlapCount returns the flap count we have for a peer and the timestamp of its last flap. If we do not have any flaps recorded for the peer, the last flap timestamp will be nil.

func (*ChannelEventStore) GetChanInfo

func (c *ChannelEventStore) GetChanInfo(channelPoint wire.OutPoint,
	peer route.Vertex) (*ChannelInfo, error)

GetChanInfo gets all the information we have on a channel in the event store.

func (*ChannelEventStore) Start

func (c *ChannelEventStore) Start() error

Start adds all existing open channels to the event store and starts the main loop which records channel and peer events, and serves requests for information from the store. If this function fails, it cancels its existing subscriptions and returns an error.

func (*ChannelEventStore) Stop

func (c *ChannelEventStore) Stop()

Stop terminates all goroutines started by the event store.

type ChannelInfo

type ChannelInfo struct {
	// Lifetime is the total amount of time we have monitored the channel
	// for.
	Lifetime time.Duration

	// Uptime is the total amount of time that the channel peer has been
	// observed as online during the monitored lifespan.
	Uptime time.Duration
}

ChannelInfo provides the set of information that the event store has recorded for a channel.

type Config

type Config struct {
	// SubscribeChannelEvents provides a subscription client which provides
	// a stream of channel events.
	SubscribeChannelEvents func() (subscribe.Subscription, error)

	// SubscribePeerEvents provides a subscription client which provides a
	// stream of peer online/offline events.
	SubscribePeerEvents func() (subscribe.Subscription, error)

	// GetOpenChannels provides a list of existing open channels which is
	// used to populate the ChannelEventStore with a set of channels on
	// startup.
	GetOpenChannels func() ([]*channeldb.OpenChannel, error)

	// Clock is the time source that the subsystem uses, provided here
	// for ease of testing.
	Clock clock.Clock

	// WriteFlapCounts records the flap count for a set of peers on disk.
	WriteFlapCount func(map[route.Vertex]*channeldb.FlapCount) error

	// ReadFlapCount gets the flap count for a peer on disk.
	ReadFlapCount func(route.Vertex) (*channeldb.FlapCount, error)

	// FlapCountTicker is a ticker which controls how often we flush our
	// peer's flap count to disk.
	FlapCountTicker ticker.Ticker
}

Config provides the event store with functions required to monitor channel activity. All elements of the config must be non-nil for the event store to operate.

Jump to

Keyboard shortcuts

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