Documentation ¶
Index ¶
- Constants
- func AssertFinalizedBlocks(assert *assert.Assertions, expected []string, ch chan *core.Block)
- func AssertFinalizedBlocksNotConflicting(assert *assert.Assertions, c1 []string, c2 []string, msg string)
- func GetFinalizedBlocks(ch chan *core.Block) []string
- func NewTestValidatorSet(addressStrs []string) *core.ValidatorSet
- func SelectTopStakeHoldersAsValidators(vcp *core.ValidatorCandidatePool) *core.ValidatorSet
- type ConsensusEngine
- func (e *ConsensusEngine) AddMessage(msg interface{})
- func (e *ConsensusEngine) Chain() *blockchain.Chain
- func (e *ConsensusEngine) FinalizedBlocks() chan *core.Block
- func (e *ConsensusEngine) GetChannelIDs() []common.ChannelIDEnum
- func (e *ConsensusEngine) GetEpoch() uint64
- func (e *ConsensusEngine) GetLastFinalizedBlock() *core.ExtendedBlock
- func (e *ConsensusEngine) GetLedger() core.Ledger
- func (e *ConsensusEngine) GetSummary() *StateStub
- func (e *ConsensusEngine) GetTip(includePendingBlockingLeaf bool) *core.ExtendedBlock
- func (e *ConsensusEngine) GetTipToExtend() *core.ExtendedBlock
- func (e *ConsensusEngine) GetTipToVote() *core.ExtendedBlock
- func (e *ConsensusEngine) GetValidatorManager() core.ValidatorManager
- func (e *ConsensusEngine) HasSynced() bool
- func (e *ConsensusEngine) ID() string
- func (e *ConsensusEngine) PrivateKey() *crypto.PrivateKey
- func (e *ConsensusEngine) SetLedger(ledger core.Ledger)
- func (e *ConsensusEngine) Start(ctx context.Context)
- func (e *ConsensusEngine) State() *State
- func (e *ConsensusEngine) Stop()
- func (e *ConsensusEngine) Wait()
- type FixedValidatorManager
- func (m *FixedValidatorManager) GetNextProposer(blockHash common.Hash, _ uint64) core.Validator
- func (m *FixedValidatorManager) GetNextValidatorSet(blockHash common.Hash) *core.ValidatorSet
- func (m *FixedValidatorManager) GetProposer(blockHash common.Hash, _ uint64) core.Validator
- func (m *FixedValidatorManager) GetValidatorSet(blockHash common.Hash) *core.ValidatorSet
- func (m *FixedValidatorManager) SetConsensusEngine(consensus core.ConsensusEngine)
- type GuardianEngine
- func (g *GuardianEngine) GetBestVote() *core.AggregatedVotes
- func (g *GuardianEngine) GetVoteToBroadcast() *core.AggregatedVotes
- func (g *GuardianEngine) HandleVote(vote *core.AggregatedVotes)
- func (g *GuardianEngine) Start(ctx context.Context)
- func (g *GuardianEngine) StartNewBlock(block common.Hash)
- func (g *GuardianEngine) StartNewRound()
- type RotatingValidatorManager
- func (m *RotatingValidatorManager) GetNextProposer(blockHash common.Hash, epoch uint64) core.Validator
- func (m *RotatingValidatorManager) GetNextValidatorSet(blockHash common.Hash) *core.ValidatorSet
- func (m *RotatingValidatorManager) GetProposer(blockHash common.Hash, epoch uint64) core.Validator
- func (m *RotatingValidatorManager) GetValidatorSet(blockHash common.Hash) *core.ValidatorSet
- func (m *RotatingValidatorManager) SetConsensusEngine(consensus core.ConsensusEngine)
- type State
- func (s *State) AddEpochVote(vote *core.Vote) error
- func (s *State) AddVote(vote *core.Vote) error
- func (s *State) GetEpoch() uint64
- func (s *State) GetEpochVotes() (*core.VoteSet, error)
- func (s *State) GetHighestCCBlock() *core.ExtendedBlock
- func (s *State) GetLastFinalizedBlock() *core.ExtendedBlock
- func (s *State) GetLastProposal() core.Proposal
- func (s *State) GetLastVote() core.Vote
- func (s *State) GetSummary() *StateStub
- func (s *State) Load() (err error)
- func (s *State) SetEpoch(epoch uint64) error
- func (s *State) SetHighestCCBlock(block *core.ExtendedBlock) error
- func (s *State) SetLastFinalizedBlock(block *core.ExtendedBlock) error
- func (s *State) SetLastProposal(p core.Proposal) error
- func (s *State) SetLastVote(v core.Vote) error
- func (s *State) String() string
- type StateStub
Constants ¶
const ( DBStateStubKey = "cs/ss" DBVoteByBlockPrefix = "cs/vbb/" DBEpochVotesKey = "cs/ev" )
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 ¶
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 ¶
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 ¶
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 GuardianEngine ¶
type GuardianEngine struct {
// contains filtered or unexported fields
}
func NewGuardianEngine ¶
func NewGuardianEngine(c *ConsensusEngine, privateKey *bls.SecretKey) *GuardianEngine
func (*GuardianEngine) GetBestVote ¶
func (g *GuardianEngine) GetBestVote() *core.AggregatedVotes
func (*GuardianEngine) GetVoteToBroadcast ¶
func (g *GuardianEngine) GetVoteToBroadcast() *core.AggregatedVotes
func (*GuardianEngine) HandleVote ¶
func (g *GuardianEngine) HandleVote(vote *core.AggregatedVotes)
func (*GuardianEngine) Start ¶
func (g *GuardianEngine) Start(ctx context.Context)
func (*GuardianEngine) StartNewBlock ¶
func (g *GuardianEngine) StartNewBlock(block common.Hash)
func (*GuardianEngine) StartNewRound ¶
func (g *GuardianEngine) StartNewRound()
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 ¶
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 State ¶
type State struct { LastProposal core.Proposal LastVote core.Vote // contains filtered or unexported fields }
func (*State) GetHighestCCBlock ¶
func (s *State) GetHighestCCBlock() *core.ExtendedBlock
func (*State) GetLastFinalizedBlock ¶
func (s *State) GetLastFinalizedBlock() *core.ExtendedBlock
func (*State) GetLastProposal ¶
func (*State) GetLastVote ¶
func (*State) GetSummary ¶
func (*State) SetHighestCCBlock ¶
func (s *State) SetHighestCCBlock(block *core.ExtendedBlock) error
func (*State) SetLastFinalizedBlock ¶
func (s *State) SetLastFinalizedBlock(block *core.ExtendedBlock) error