Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeLookbackWindow(epochSize uint64, defaultLookbackWindow uint64, cip21 bool, ...) uint64
- type Builder
- type FixableBuilder
- type Monitor
- func (um *Monitor) Clear()
- func (um *Monitor) ComputeUptime(header *types.Header) ([]*big.Int, error)
- func (um *Monitor) Copy() FixableBuilder
- func (um *Monitor) GetEpoch() uint64
- func (um *Monitor) GetEpochSize() uint64
- func (um *Monitor) GetLastProcessedHeader() *types.Header
- func (um *Monitor) ProcessHeader(header *types.Header) error
- type Uptime
- type UptimeEntry
- type Window
- func MonitoringWindow(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64) (Window, error)
- func MonitoringWindowUntil(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64, ...) (Window, error)
- func MustMonitoringWindow(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64) Window
Constants ¶
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 ¶
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 ¶
NewMonitor creates a new uptime monitor
func (*Monitor) ComputeUptime ¶
ComputeValidatorsUptime retrieves the uptime score for each validator for a given epoch
func (*Monitor) Copy ¶
func (um *Monitor) Copy() FixableBuilder
func (*Monitor) GetEpochSize ¶
func (*Monitor) GetLastProcessedHeader ¶
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
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 ¶
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 ¶
MustMonitoringWindow is a MonitoringWindow variant that panics on error