uptime

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: GPL-3.0, GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinSafeLookbackWindow is the minimum number allowed for lookbackWindow size
	MinSafeLookbackWindow = 3
	// MaxSafeLookbackWindow is the maximum number allowed for lookbackWindow size
	MaxSafeLookbackWindow = 720
	// BlocksToSkipAtEpochEnd represents the number of blocks to skip on the monitoring window from the end of the epoch
	// Currently we skip blocks:
	// lastBlock     => its parentSeal is on firstBlock of next epoch
	// lastBlock - 1 => parentSeal is on lastBlockOfEpoch, but validatorScore is computed with lastBlockOfEpoch and before updating scores
	// (lastBlock-1 could be counted, but much harder to implement)
	BlocksToSkipAtEpochEnd = 2
)

Variables

This section is empty.

Functions

func ComputeLookbackWindow

func ComputeLookbackWindow(epochSize uint64, defaultLookbackWindow uint64, cip21 bool, getLookbackWindow func() (uint64, error)) uint64

ComputeLookbackWindow computes the lookbackWindow based on different required parameters. getLookbackWindow represents the way to obtain lookbackWindow from the smart contract

Types

type Monitor

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

Monitor is responsible for monitoring uptime by processing blocks

func NewMonitor

func NewMonitor(store Store, epochSize, lookbackWindow uint64) *Monitor

NewMonitor creates a new uptime monitor

func (*Monitor) ComputeValidatorsUptime

func (um *Monitor) ComputeValidatorsUptime(epoch uint64, valSetSize int) ([]*big.Int, error)

ComputeValidatorsUptime retrieves the uptime score for each validator for a given epoch

func (*Monitor) MonitoringWindow

func (um *Monitor) MonitoringWindow(epoch uint64) Window

MonitoringWindow returns the monitoring window for the given epoch in the format [firstBlock, lastBlock] both inclusive

func (*Monitor) ProcessBlock

func (um *Monitor) ProcessBlock(block *types.Block) error

ProcessBlock uses the block's signature bitmap (which encodes who signed the parent block) to update the epoch's Uptime data

type Store

type Store interface {
	ReadAccumulatedEpochUptime(epoch uint64) *Uptime
	WriteAccumulatedEpochUptime(epoch uint64, uptime *Uptime)
}

Store provides a persistent storage for uptime entries

type Uptime

type Uptime struct {
	LatestBlock uint64
	Entries     []UptimeEntry
}

Uptime contains the latest block for which uptime metrics were accounted. It also contains an array of Entries where the `i`th entry represents the uptime statistics of the `i`th validator in the validator set for that epoch

type UptimeEntry

type UptimeEntry struct {
	// Numbers of blocks validator is considered UP within monitored window
	UpBlocks        uint64
	LastSignedBlock uint64
}

UptimeEntry contains the uptime score of a validator during an epoch as well as the last block they signed on

func (*UptimeEntry) String

func (u *UptimeEntry) String() string

type Window

type Window struct {
	Start uint64
	End   uint64
}

Window represents a block range related to uptime monitoring Block range goes from `Start` to `End` and it's inclusive

func MonitoringWindow

func MonitoringWindow(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64) (Window, error)

MonitoringWindow retrieves the block window where uptime is to be monitored for a given epoch.

func MustMonitoringWindow

func MustMonitoringWindow(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64) Window

MustMonitoringWindow is a MonitoringWindow variant that panics on error

func (Window) Contains

func (w Window) Contains(n uint64) bool

Contains indicates if a block number is contained within the window

func (Window) Size

func (w Window) Size() uint64

Size returns the size of the window.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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