consensus

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBStateStubKey      = "cs/ss"
	DBVoteByBlockPrefix = "cs/vbb/"
	DBEpochVotesKey     = "cs/ev"
)
View Source
const MaxValidatorCount int = 51

Variables

This section is empty.

Functions

func AssertFinalizedBlocks

func AssertFinalizedBlocks(assert *assert.Assertions, expected []string, ch chan *core.Block)

AssertFinalizedBlocks asserts finalized blocks are as expected.

func AssertFinalizedBlocksNotConflicting

func AssertFinalizedBlocksNotConflicting(assert *assert.Assertions, c1 []string, c2 []string, msg string)

AssertFinalizedBlocksNotConflicting asserts two chains are not conflicting.

func GetFinalizedBlocks

func GetFinalizedBlocks(ch chan *core.Block) []string

GetFinalizedBlocks drains the FinalizedBlocks channel and return a slice of block hashes.

func NewTestValidatorSet

func NewTestValidatorSet(addressStrs []string) *core.ValidatorSet

func SelectTopStakeHoldersAsValidators

func SelectTopStakeHoldersAsValidators(vcp *core.ValidatorCandidatePool) *core.ValidatorSet

Types

type ConsensusEngine

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

ConsensusEngine is the default implementation of the Engine interface.

func NewConsensusEngine

func NewConsensusEngine(privateKey *crypto.PrivateKey, db store.Store, chain *blockchain.Chain, dispatcher *dispatcher.Dispatcher, validatorManager core.ValidatorManager) *ConsensusEngine

NewConsensusEngine creates a instance of ConsensusEngine.

func (*ConsensusEngine) AddMessage

func (e *ConsensusEngine) AddMessage(msg interface{})

AddMessage adds a message to engine's message queue.

func (*ConsensusEngine) Chain

func (e *ConsensusEngine) Chain() *blockchain.Chain

Chain return a pointer to the underlying chain store.

func (*ConsensusEngine) FinalizedBlocks

func (e *ConsensusEngine) FinalizedBlocks() chan *core.Block

FinalizedBlocks returns a channel that will be published with finalized blocks by the engine.

func (*ConsensusEngine) GetChannelIDs

func (e *ConsensusEngine) GetChannelIDs() []common.ChannelIDEnum

GetChannelIDs implements the p2p.MessageHandler interface.

func (*ConsensusEngine) GetEpoch

func (e *ConsensusEngine) GetEpoch() uint64

GetEpoch returns the current epoch

func (*ConsensusEngine) GetLastFinalizedBlock

func (e *ConsensusEngine) GetLastFinalizedBlock() *core.ExtendedBlock

GetLastFinalizedBlock returns the last finalized block.

func (*ConsensusEngine) GetLedger

func (e *ConsensusEngine) GetLedger() core.Ledger

GetLedger returns the ledger instance attached to the consensus engine

func (*ConsensusEngine) GetSummary

func (e *ConsensusEngine) GetSummary() *StateStub

GetSummary returns a summary of consensus state.

func (*ConsensusEngine) GetTip

func (e *ConsensusEngine) GetTip(includePendingBlockingLeaf bool) *core.ExtendedBlock

GetTip return the block to be extended from.

func (*ConsensusEngine) GetTipToExtend

func (e *ConsensusEngine) GetTipToExtend() *core.ExtendedBlock

func (*ConsensusEngine) GetTipToVote

func (e *ConsensusEngine) GetTipToVote() *core.ExtendedBlock

func (*ConsensusEngine) GetValidatorManager

func (e *ConsensusEngine) GetValidatorManager() core.ValidatorManager

GetValidatorManager returns a pointer to the valiator manager.

func (*ConsensusEngine) HasSynced

func (e *ConsensusEngine) HasSynced() bool

func (*ConsensusEngine) ID

func (e *ConsensusEngine) ID() string

ID returns the identifier of current node.

func (*ConsensusEngine) PrivateKey

func (e *ConsensusEngine) PrivateKey() *crypto.PrivateKey

PrivateKey returns the private key

func (*ConsensusEngine) SetLedger

func (e *ConsensusEngine) SetLedger(ledger core.Ledger)

func (*ConsensusEngine) Start

func (e *ConsensusEngine) Start(ctx context.Context)

Start starts sub components and kick off the main loop.

func (*ConsensusEngine) State

func (e *ConsensusEngine) State() *State

func (*ConsensusEngine) Stop

func (e *ConsensusEngine) Stop()

Stop notifies all goroutines to stop without blocking.

func (*ConsensusEngine) Wait

func (e *ConsensusEngine) Wait()

Wait blocks until all goroutines stop.

type FixedValidatorManager

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

FixedValidatorManager is an implementation of ValidatorManager interface that selects a fixed validator as the proposer.

func NewFixedValidatorManager

func NewFixedValidatorManager() *FixedValidatorManager

NewFixedValidatorManager creates an instance of FixedValidatorManager.

func (*FixedValidatorManager) GetNextProposer

func (m *FixedValidatorManager) GetNextProposer(blockHash common.Hash, _ uint64) core.Validator

GetNextProposer implements ValidatorManager interface.

func (*FixedValidatorManager) GetNextValidatorSet

func (m *FixedValidatorManager) GetNextValidatorSet(blockHash common.Hash) *core.ValidatorSet

GetNextValidatorSet returns the validator set for given block hash's next block.

func (*FixedValidatorManager) GetProposer

func (m *FixedValidatorManager) GetProposer(blockHash common.Hash, _ uint64) core.Validator

GetProposer implements ValidatorManager interface.

func (*FixedValidatorManager) GetValidatorSet

func (m *FixedValidatorManager) GetValidatorSet(blockHash common.Hash) *core.ValidatorSet

GetValidatorSet returns the validator set for given block hash.

func (*FixedValidatorManager) SetConsensusEngine

func (m *FixedValidatorManager) SetConsensusEngine(consensus core.ConsensusEngine)

SetConsensusEngine mplements ValidatorManager interface.

type RotatingValidatorManager

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

RotatingValidatorManager is an implementation of ValidatorManager interface that selects a random validator as the proposer using validator's stake as weight.

func NewRotatingValidatorManager

func NewRotatingValidatorManager() *RotatingValidatorManager

NewRotatingValidatorManager creates an instance of RotatingValidatorManager.

func (*RotatingValidatorManager) GetNextProposer

func (m *RotatingValidatorManager) GetNextProposer(blockHash common.Hash, epoch uint64) core.Validator

GetNextProposer implements ValidatorManager interface.

func (*RotatingValidatorManager) GetNextValidatorSet

func (m *RotatingValidatorManager) GetNextValidatorSet(blockHash common.Hash) *core.ValidatorSet

GetNextValidatorSet returns the validator set for given block's next block.

func (*RotatingValidatorManager) GetProposer

func (m *RotatingValidatorManager) GetProposer(blockHash common.Hash, epoch uint64) core.Validator

GetProposer implements ValidatorManager interface.

func (*RotatingValidatorManager) GetValidatorSet

func (m *RotatingValidatorManager) GetValidatorSet(blockHash common.Hash) *core.ValidatorSet

GetValidatorSet returns the validator set for given block.

func (*RotatingValidatorManager) SetConsensusEngine

func (m *RotatingValidatorManager) SetConsensusEngine(consensus core.ConsensusEngine)

SetConsensusEngine mplements ValidatorManager interface.

type SentryEngine added in v1.0.0

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

func NewSentryEngine added in v1.0.0

func NewSentryEngine(c *ConsensusEngine, privateKey *bls.SecretKey) *SentryEngine

func (*SentryEngine) GetBestVote added in v1.0.0

func (g *SentryEngine) GetBestVote() *core.AggregatedVotes

func (*SentryEngine) GetVoteToBroadcast added in v1.0.0

func (g *SentryEngine) GetVoteToBroadcast() *core.AggregatedVotes

func (*SentryEngine) HandleVote added in v1.0.0

func (g *SentryEngine) HandleVote(vote *core.AggregatedVotes)

func (*SentryEngine) Start added in v1.0.0

func (g *SentryEngine) Start(ctx context.Context)

func (*SentryEngine) StartNewBlock added in v1.0.0

func (g *SentryEngine) StartNewBlock(block common.Hash)

func (*SentryEngine) StartNewRound added in v1.0.0

func (g *SentryEngine) StartNewRound()

type State

type State struct {
	LastProposal core.Proposal
	LastVote     core.Vote
	// contains filtered or unexported fields
}

func NewState

func NewState(db store.Store, chain *blockchain.Chain) *State

func (*State) AddEpochVote

func (s *State) AddEpochVote(vote *core.Vote) error

func (*State) AddVote

func (s *State) AddVote(vote *core.Vote) error

func (*State) GetEpoch

func (s *State) GetEpoch() uint64

func (*State) GetEpochVotes

func (s *State) GetEpochVotes() (*core.VoteSet, error)

func (*State) GetHighestCCBlock

func (s *State) GetHighestCCBlock() *core.ExtendedBlock

func (*State) GetLastFinalizedBlock

func (s *State) GetLastFinalizedBlock() *core.ExtendedBlock

func (*State) GetLastProposal

func (s *State) GetLastProposal() core.Proposal

func (*State) GetLastVote

func (s *State) GetLastVote() core.Vote

func (*State) GetSummary

func (s *State) GetSummary() *StateStub

func (*State) Load

func (s *State) Load() (err error)

func (*State) SetEpoch

func (s *State) SetEpoch(epoch uint64) error

func (*State) SetHighestCCBlock

func (s *State) SetHighestCCBlock(block *core.ExtendedBlock) error

func (*State) SetLastFinalizedBlock

func (s *State) SetLastFinalizedBlock(block *core.ExtendedBlock) error

func (*State) SetLastProposal

func (s *State) SetLastProposal(p core.Proposal) error

func (*State) SetLastVote

func (s *State) SetLastVote(v core.Vote) error

func (*State) String

func (s *State) String() string

type StateStub

type StateStub struct {
	Root               common.Hash
	HighestCCBlock     common.Hash
	LastFinalizedBlock common.Hash
	LastProposal       core.Proposal
	LastVote           core.Vote
	Epoch              uint64
}

Jump to

Keyboard shortcuts

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