 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Variables
- type Builder
- func (b *Builder) Build() (*RollDPoS, error)
- func (b *Builder) RegisterProtocol(rp *rolldpos.Protocol) *Builder
- func (b *Builder) SetAddr(encodedAddr string) *Builder
- func (b *Builder) SetBlockDeserializer(deserializer *block.Deserializer) *Builder
- func (b *Builder) SetBroadcast(broadcastHandler scheme.Broadcast) *Builder
- func (b *Builder) SetChainManager(chain ChainManager) *Builder
- func (b *Builder) SetClock(clock clock.Clock) *Builder
- func (b *Builder) SetConfig(cfg BuilderConfig) *Builder
- func (b *Builder) SetDelegatesByEpochFunc(delegatesByEpochFunc NodesSelectionByEpochFunc) *Builder
- func (b *Builder) SetPriKey(priKey crypto.PrivateKey) *Builder
- func (b *Builder) SetProposersByEpochFunc(proposersByEpochFunc NodesSelectionByEpochFunc) *Builder
 
- type BuilderConfig
- type ChainManager
- type Config
- type ConsensusVote
- type ConsensusVoteTopic
- type EndorsedByMajorityFunc
- type EndorsedConsensusMessage
- func (ecm *EndorsedConsensusMessage) Document() endorsement.Document
- func (ecm *EndorsedConsensusMessage) Endorsement() *endorsement.Endorsement
- func (ecm *EndorsedConsensusMessage) Height() uint64
- func (ecm *EndorsedConsensusMessage) LoadProto(msg *iotextypes.ConsensusMessage, deserializer *block.Deserializer) error
- func (ecm *EndorsedConsensusMessage) Proto() (*iotextypes.ConsensusMessage, error)
 
- type NodesSelectionByEpochFunc
- type RDPoSCtx
- type RollDPoS
- func (r *RollDPoS) Activate(active bool)
- func (r *RollDPoS) Active() bool
- func (r *RollDPoS) Calibrate(height uint64)
- func (r *RollDPoS) CurrentState() fsm.State
- func (r *RollDPoS) HandleConsensusMsg(msg *iotextypes.ConsensusMessage) error
- func (r *RollDPoS) Metrics() (scheme.ConsensusMetrics, error)
- func (r *RollDPoS) NumPendingEvts() int
- func (r *RollDPoS) Start(ctx context.Context) error
- func (r *RollDPoS) Stop(ctx context.Context) error
- func (r *RollDPoS) ValidateBlockFooter(blk *block.Block) error
 
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNewRollDPoS indicates the error of constructing RollDPoS ErrNewRollDPoS = errors.New("error when constructing RollDPoS") // ErrZeroDelegate indicates seeing 0 delegates in the network ErrZeroDelegate = errors.New("zero delegates in the network") // ErrNotEnoughCandidates indicates there are not enough candidates from the candidate pool ErrNotEnoughCandidates = errors.New("Candidate pool does not have enough candidates") )
var DefaultConfig = Config{ FSM: consensusfsm.ConsensusTiming{ UnmatchedEventTTL: 3 * time.Second, UnmatchedEventInterval: 100 * time.Millisecond, AcceptBlockTTL: 4 * time.Second, AcceptProposalEndorsementTTL: 2 * time.Second, AcceptLockEndorsementTTL: 2 * time.Second, CommitTTL: 2 * time.Second, EventChanSize: 10000, }, ToleratedOvertime: 2 * time.Second, Delay: 5 * time.Second, ConsensusDBPath: "/var/data/consensus.db", }
DefaultConfig is the default config
var ( // ErrExpiredEndorsement indicates that the endorsement is expired ErrExpiredEndorsement = errors.New("the endorsement has been replaced or expired") )
var ErrInsufficientEndorsements = errors.New("Insufficient endorsements")
    ErrInsufficientEndorsements represents the error that not enough endorsements
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
	// contains filtered or unexported fields
}
    Builder is the builder for rollDPoS
func NewRollDPoSBuilder ¶
func NewRollDPoSBuilder() *Builder
NewRollDPoSBuilder instantiates a Builder instance
func (*Builder) RegisterProtocol ¶
RegisterProtocol sets the rolldpos protocol
func (*Builder) SetBlockDeserializer ¶
func (b *Builder) SetBlockDeserializer(deserializer *block.Deserializer) *Builder
SetBlockDeserializer set block deserializer
func (*Builder) SetBroadcast ¶
SetBroadcast sets the broadcast callback
func (*Builder) SetChainManager ¶
func (b *Builder) SetChainManager(chain ChainManager) *Builder
SetChainManager sets the blockchain APIs
func (*Builder) SetConfig ¶
func (b *Builder) SetConfig(cfg BuilderConfig) *Builder
SetConfig sets config
func (*Builder) SetDelegatesByEpochFunc ¶
func (b *Builder) SetDelegatesByEpochFunc( delegatesByEpochFunc NodesSelectionByEpochFunc, ) *Builder
SetDelegatesByEpochFunc sets delegatesByEpochFunc
func (*Builder) SetPriKey ¶
func (b *Builder) SetPriKey(priKey crypto.PrivateKey) *Builder
SetPriKey sets the private key
func (*Builder) SetProposersByEpochFunc ¶
func (b *Builder) SetProposersByEpochFunc( proposersByEpochFunc NodesSelectionByEpochFunc, ) *Builder
SetProposersByEpochFunc sets proposersByEpochFunc
type BuilderConfig ¶
type BuilderConfig struct {
	Chain              blockchain.Config
	Consensus          Config
	Scheme             string
	DardanellesUpgrade consensusfsm.DardanellesUpgrade
	DB                 db.Config
	Genesis            genesis.Genesis
	SystemActive       bool
}
    BuilderConfig returns the configuration of the builder
type ChainManager ¶
type ChainManager interface {
	// BlockProposeTime return propose time by height
	BlockProposeTime(uint64) (time.Time, error)
	// BlockCommitTime return commit time by height
	BlockCommitTime(uint64) (time.Time, error)
	// MintNewBlock creates a new block with given actions
	// Note: the coinbase transfer will be added to the given transfers when minting a new block
	MintNewBlock(timestamp time.Time) (*block.Block, error)
	// CommitBlock validates and appends a block to the chain
	CommitBlock(blk *block.Block) error
	// ValidateBlock validates a new block before adding it to the blockchain
	ValidateBlock(blk *block.Block) error
	// TipHeight returns tip block's height
	TipHeight() uint64
	// ChainAddress returns chain address on parent chain, the root chain return empty.
	ChainAddress() string
}
    ChainManager defines the blockchain interface
func NewChainManager ¶
func NewChainManager(bc blockchain.Blockchain) ChainManager
NewChainManager creates a chain manager
type Config ¶
type Config struct {
	FSM               consensusfsm.ConsensusTiming `yaml:"fsm"`
	ToleratedOvertime time.Duration                `yaml:"toleratedOvertime"`
	Delay             time.Duration                `yaml:"delay"`
	ConsensusDBPath   string                       `yaml:"consensusDBPath"`
}
    Config is the config struct for RollDPoS consensus package
type ConsensusVote ¶
type ConsensusVote struct {
	// contains filtered or unexported fields
}
    ConsensusVote is a vote on a given topic for a block on a specific height
func NewConsensusVote ¶
func NewConsensusVote( blkHash []byte, topic ConsensusVoteTopic, ) *ConsensusVote
NewConsensusVote creates a consensus vote
func (*ConsensusVote) BlockHash ¶
func (v *ConsensusVote) BlockHash() []byte
BlockHash returns the block hash of the consensus vote
func (*ConsensusVote) Hash ¶
func (v *ConsensusVote) Hash() ([]byte, error)
Hash returns the hash of this vote
func (*ConsensusVote) LoadProto ¶
func (v *ConsensusVote) LoadProto(msg *iotextypes.ConsensusVote) error
LoadProto loads from a protobuf message
func (*ConsensusVote) Proto ¶
func (v *ConsensusVote) Proto() (*iotextypes.ConsensusVote, error)
Proto converts to a protobuf message
func (*ConsensusVote) Topic ¶
func (v *ConsensusVote) Topic() ConsensusVoteTopic
Topic returns the topic of the consensus vote
type ConsensusVoteTopic ¶
type ConsensusVoteTopic uint8
ConsensusVoteTopic defines the topic of an consensus vote
const ( // PROPOSAL stands for an consensus vote to endorse a block proposal PROPOSAL ConsensusVoteTopic = 0 // LOCK stands for an consensus vote to endorse a lock on a proposed block LOCK ConsensusVoteTopic = 1 // COMMIT stands for an consensus vote to endorse a block commit COMMIT ConsensusVoteTopic = 2 )
type EndorsedByMajorityFunc ¶
type EndorsedByMajorityFunc func(blockHash []byte, topics []ConsensusVoteTopic) bool
EndorsedByMajorityFunc defines a function to give an information of consensus status
type EndorsedConsensusMessage ¶
type EndorsedConsensusMessage struct {
	// contains filtered or unexported fields
}
    EndorsedConsensusMessage is an endorsement on document
func NewEndorsedConsensusMessage ¶
func NewEndorsedConsensusMessage( height uint64, message endorsement.Document, endorsement *endorsement.Endorsement, ) *EndorsedConsensusMessage
NewEndorsedConsensusMessage creates an EndorsedConsensusMessage for an consensus vote
func (*EndorsedConsensusMessage) Document ¶
func (ecm *EndorsedConsensusMessage) Document() endorsement.Document
Document returns the endorsed consensus message
func (*EndorsedConsensusMessage) Endorsement ¶
func (ecm *EndorsedConsensusMessage) Endorsement() *endorsement.Endorsement
Endorsement returns the endorsement
func (*EndorsedConsensusMessage) Height ¶
func (ecm *EndorsedConsensusMessage) Height() uint64
Height returns the height of this message
func (*EndorsedConsensusMessage) LoadProto ¶
func (ecm *EndorsedConsensusMessage) LoadProto(msg *iotextypes.ConsensusMessage, deserializer *block.Deserializer) error
LoadProto creates an endorsement message from protobuf message
func (*EndorsedConsensusMessage) Proto ¶
func (ecm *EndorsedConsensusMessage) Proto() (*iotextypes.ConsensusMessage, error)
Proto converts an endorsement to endorse proto
type NodesSelectionByEpochFunc ¶
NodesSelectionByEpochFunc defines a function to select nodes
type RDPoSCtx ¶
type RDPoSCtx interface {
	consensusfsm.Context
	Chain() ChainManager
	BlockDeserializer() *block.Deserializer
	RoundCalculator() *roundCalculator
	Clock() clock.Clock
	CheckBlockProposer(uint64, *blockProposal, *endorsement.Endorsement) error
	CheckVoteEndorser(uint64, *ConsensusVote, *endorsement.Endorsement) error
}
    RDPoSCtx is the context of RollDPoS
func NewRollDPoSCtx ¶
func NewRollDPoSCtx( cfg consensusfsm.ConsensusConfig, consensusDBConfig db.Config, active bool, toleratedOvertime time.Duration, timeBasedRotation bool, chain ChainManager, blockDeserializer *block.Deserializer, rp *rolldpos.Protocol, broadcastHandler scheme.Broadcast, delegatesByEpochFunc NodesSelectionByEpochFunc, proposersByEpochFunc NodesSelectionByEpochFunc, encodedAddr string, priKey crypto.PrivateKey, clock clock.Clock, beringHeight uint64, ) (RDPoSCtx, error)
NewRollDPoSCtx returns a context of RollDPoSCtx
type RollDPoS ¶
type RollDPoS struct {
	// contains filtered or unexported fields
}
    RollDPoS is Roll-DPoS consensus main entrance
func (*RollDPoS) Activate ¶
Activate activates or pauses the roll-DPoS consensus. When it is deactivated, the node will finish the current consensus round if it is doing the work and then return the the initial state
func (*RollDPoS) Active ¶
Active is true if the roll-DPoS consensus is active, or false if it is stand-by
func (*RollDPoS) CurrentState ¶
func (r *RollDPoS) CurrentState() fsm.State
CurrentState returns the current state
func (*RollDPoS) HandleConsensusMsg ¶
func (r *RollDPoS) HandleConsensusMsg(msg *iotextypes.ConsensusMessage) error
HandleConsensusMsg handles incoming consensus message
func (*RollDPoS) Metrics ¶
func (r *RollDPoS) Metrics() (scheme.ConsensusMetrics, error)
Metrics returns RollDPoS consensus metrics
func (*RollDPoS) NumPendingEvts ¶
NumPendingEvts returns the number of pending events