uptime

package
v0.0.0-...-697f13e Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: GPL-3.0 Imports: 7 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
)

Check CIP-21 Spec (https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0021.md)

Variables

View Source
var (
	// ErrMissingPreviousHeaders is returned when the builder cannot continue due
	// to the missing headers from the epoch.
	ErrMissingPreviousHeaders = errors.New("missing previous headers to compute uptime")

	// ErrHeaderNumberAlreadyUsed is returned when the builder receives a header number
	// that was alredy processed
	ErrHeaderNumberAlreadyUsed = errors.New("header number already processed")

	// ErrHeaderRewinded is returned when the builder cannot continue due to the uptime chain.
	// being rewinded.
	ErrHeaderRewinded = errors.New("header provided is behind current tip in uptime builder")

	// ErrWrongEpoch is returned when a header is provided to a Builder from the wrong epoch.
	ErrWrongEpoch = errors.New("header provided was from the wrong epoch")

	// ErrUnpreparedCompute is returned if ComputeUptime is called without enough preparation for the instance.
	ErrUnpreparedCompute = errors.New("compute uptime is not ready due to missing preparation")
)

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 Builder

type Builder interface {
	// ProcessHeader adds a header to the Builder. Headers must be provided in order.
	// Some implementations may return ErrHeaderRewinded if a header is given that
	// is behind a previous header provided.
	// Some implementations may return a ErrMissingPreviousHeaders if that specific implementation
	// required additional setup before calling Compute
	ProcessHeader(header *types.Header) error

	// ComputeUptime computes the validators uptime score and returns it as an array.
	// The last header of the epoch must be provided, to ensure that the score is calculated from the
	// correct subchain.
	ComputeUptime(epochLastHeader *types.Header) ([]*big.Int, error)

	// GetEpoch returns the epoch for this uptime Builder.
	GetEpoch() uint64
}

func NewAutoFixBuilder

func NewAutoFixBuilder(builder FixableBuilder, provider istanbul.EpochHeadersProvider) Builder

type FixableBuilder

type FixableBuilder interface {
	Builder

	// Clear resets this builder
	Clear()

	// GetLastProcessedHeader returns the last processed header by this Builder.
	GetLastProcessedHeader() *types.Header

	// GetEpochSize returns the epoch size for the current epoch in this Builder.
	GetEpochSize() uint64

	// Copy returns a deepCopy of the builder
	Copy() FixableBuilder
}

type Monitor

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

Monitor is responsible for monitoring uptime by processing blocks

func NewMonitor

func NewMonitor(epochSize, epoch, lookbackWindow uint64, valSetSize int) *Monitor

NewMonitor creates a new uptime monitor

func (*Monitor) Clear

func (um *Monitor) Clear()

func (*Monitor) ComputeUptime

func (um *Monitor) ComputeUptime(header *types.Header) ([]*big.Int, error)

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

func (*Monitor) Copy

func (um *Monitor) Copy() FixableBuilder

func (*Monitor) GetEpoch

func (um *Monitor) GetEpoch() uint64

func (*Monitor) GetEpochSize

func (um *Monitor) GetEpochSize() uint64

func (*Monitor) GetLastProcessedHeader

func (um *Monitor) GetLastProcessedHeader() *types.Header

func (*Monitor) ProcessHeader

func (um *Monitor) ProcessHeader(header *types.Header) error

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

type Uptime

type Uptime struct {
	LatestHeader *types.Header
	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

func (*Uptime) Copy

func (u *Uptime) Copy() *Uptime

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 MonitoringWindowUntil

func MonitoringWindowUntil(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64, untilBlockNumber 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.

Jump to

Keyboard shortcuts

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