blocktimer

package
v0.33.24-atree-inlining Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: AGPL-3.0 Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBlockTimer = NewNoopBlockTimer()

Functions

This section is empty.

Types

type BlockTimestamp

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

BlockTimestamp is a helper structure that performs building and validation of valid timestamp for blocks that are generated by block builder and checked by hotstuff event loop. Let τ be the time stamp of the parent block and t be the current clock time of the proposer that is building the child block An honest proposer sets the Timestamp of its proposal according to the following rule: if t is within the interval [τ + minInterval, τ + maxInterval], then the proposer sets Timestamp := t otherwise, the proposer chooses the time stamp from the interval that is closest to its current time t, i.e. if t < τ + minInterval, the proposer sets Timestamp := τ + minInterval if τ + maxInterval < t, the proposer sets Timestamp := τ + maxInterval

func NewBlockTimer

func NewBlockTimer(minInterval, maxInterval time.Duration) (*BlockTimestamp, error)

NewBlockTimer creates new block timer with specific intervals and time.Now as generator

func (BlockTimestamp) Build

func (b BlockTimestamp) Build(parentTimestamp time.Time) time.Time

Build generates a timestamp based on definition of valid timestamp.

func (BlockTimestamp) Validate

func (b BlockTimestamp) Validate(parentTimestamp, currentTimestamp time.Time) error

Validate accepts parent and current timestamps and checks if current timestamp satisfies definition of valid timestamp. Timestamp is valid if: Timestamp ∈ [τ + minInterval, τ + maxInterval] Returns:

  • model.ErrInvalidBlockTimestamp - timestamp is invalid
  • nil - success

type NoopBlockTimer

type NoopBlockTimer struct{}

NoopBlockTimer implements an always valid behavior for BlockTimestamp interface. Can be used by nodes that don't perform validation of block timestamps.

func NewNoopBlockTimer

func NewNoopBlockTimer() *NoopBlockTimer

func (NoopBlockTimer) Build

func (n NoopBlockTimer) Build(time.Time) time.Time

func (NoopBlockTimer) Validate

func (n NoopBlockTimer) Validate(time.Time, time.Time) error

Jump to

Keyboard shortcuts

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