consensus

package
v0.0.7-alphanet Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EpochDuration = time.Hour * 24
)
View Source
var (
	ErrElectionBeforeGenesis = errors.New("election time/tick before genesis timestamp")
)

Functions

func NewElectionAlgorithm

func NewElectionAlgorithm(group *Context) *electionAlgorithm

Types

type API

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

func (*API) EpochStats

func (obj *API) EpochStats(epoch uint64) (*api.EpochStats, error)

func (*API) EpochTicker

func (obj *API) EpochTicker() common.Ticker

func (*API) GetPillarDelegationsByEpoch

func (obj *API) GetPillarDelegationsByEpoch(epoch uint64) (map[string]*types.PillarDelegationDetail, error)

func (*API) GetPillarWeights

func (obj *API) GetPillarWeights() (map[string]*big.Int, error)

type AlgorithmConfig

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

func NewAlgorithmContext

func NewAlgorithmContext(delegations []*types.PillarDelegation, hashH *types.HashHeight) *AlgorithmConfig

type ChainTicker

type ChainTicker interface {
	common.Ticker
	IsFinished(tick uint64) bool
	HasStarted(tick uint64) bool
	GetEndBlock(tick uint64) (*nom.Momentum, error)
	GetContent(tick uint64) ([]*nom.Momentum, error)
}

type Consensus

type Consensus interface {
	Verifier
	EventManager

	Init() error
	Start() error
	Stop() error

	GetMomentumProducer(timestamp time.Time) (*types.Address, error)

	FrontierPillarReader() api.PillarReader
	FixedPillarReader(types.HashHeight) api.PillarReader
}

Consensus include all interface for consensus

func NewConsensus

func NewConsensus(db db.DB, chain chain.Chain, testing bool) Consensus

NewConsensus instantiates a new consensus object

type Context

type Context struct {
	common.Ticker
	constants.Consensus
	GenesisTime time.Time
}

func NewConsensusContext

func NewConsensusContext(genesisTime time.Time) *Context

type ElectionAlgorithm

type ElectionAlgorithm interface {
	SelectProducers(context *AlgorithmConfig) []*types.PillarDelegation
}

type ElectionReader

type ElectionReader interface {
	common.Ticker
	ElectionByTime(t time.Time) (*electionResult, error)
	ElectionByTick(tick uint64) (*electionResult, error)
	DelegationsByTick(tick uint64) ([]*types.PillarDelegationDetail, error)
}

type EventListener

type EventListener interface {
	NewProducerEvent(ProducerEvent)
}

type EventManager

type EventManager interface {
	Register(callback EventListener)
	UnRegister(callback EventListener)
}

type Points

type Points interface {
	// MomentumEventListener is used to precompute points as momentums come, so API calls have hot data
	chain.MomentumEventListener
	GetPeriodPoints() PointsReader
	GetEpochPoints() PointsReader
}

type PointsReader

type PointsReader interface {
	common.Ticker
	// Returns nil, nil for points which are in the future
	GetPoint(tick uint64) (*storage.Point, error)
}

PointsReader can read pillar statistics of epoch or period

type ProducerEvent

type ProducerEvent struct {
	StartTime time.Time
	EndTime   time.Time
	Producer  types.Address
	Name      string
}

type Verifier

type Verifier interface {
	VerifyMomentumProducer(momentum *nom.Momentum) (bool, error)
}

Verifier is the interface that can verify block consensus.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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