Documentation ¶
Index ¶
- Constants
- Variables
- type BftService
- type Candidate
- type CandidateContext
- func (candidateContext *CandidateContext) CandidateContextHash() (*crypto.HashType, error)
- func (candidateContext *CandidateContext) Copy() *CandidateContext
- func (candidateContext *CandidateContext) FromProtoMessage(message proto.Message) error
- func (candidateContext *CandidateContext) Marshal() (data []byte, err error)
- func (candidateContext *CandidateContext) ToProtoMessage() (proto.Message, error)
- func (candidateContext *CandidateContext) Unmarshal(data []byte) error
- type Config
- type ConsensusContext
- type Dpos
- func (dpos *Dpos) BroadcastBFTMsgToBookkeepers(block *types.Block, messageID uint32) error
- func (dpos *Dpos) EnableMint() bool
- func (dpos *Dpos) Finalize(tail *types.Block) error
- func (dpos *Dpos) IsBookkeeper() bool
- func (dpos *Dpos) IsCandidateExist(addr types.AddressHash) bool
- func (dpos *Dpos) LoadCandidateByBlockHash(hash *crypto.HashType) (*CandidateContext, error)
- func (dpos *Dpos) LoadCandidates() error
- func (dpos *Dpos) LoadPeriodContext() (*PeriodContext, error)
- func (dpos *Dpos) PackTxs(block *types.Block, scriptAddr []byte) error
- func (dpos *Dpos) Proc() goprocess.Process
- func (dpos *Dpos) Process(block *types.Block, db interface{}) error
- func (dpos *Dpos) RecoverMint()
- func (dpos *Dpos) Run() error
- func (dpos *Dpos) Setup() error
- func (dpos *Dpos) Stop()
- func (dpos *Dpos) StopMint()
- func (dpos *Dpos) StoreCandidateContext(block *types.Block, db storage.Table) error
- func (dpos *Dpos) StorePeriodContext() error
- func (dpos *Dpos) TryToUpdateEternalBlock(src *types.Block)
- func (dpos *Dpos) UpdateCandidateContext(block *types.Block) error
- func (dpos *Dpos) Verify(block *types.Block) error
- func (dpos *Dpos) VerifyTx(tx *types.Transaction) error
- type EternalBlockMsg
- type Period
- type PeriodContext
- func (pc *PeriodContext) FindProposerWithTimeStamp(timestamp int64) (*types.AddressHash, error)
- func (pc *PeriodContext) FromProtoMessage(message proto.Message) error
- func (pc *PeriodContext) Marshal() (data []byte, err error)
- func (pc *PeriodContext) ToProtoMessage() (proto.Message, error)
- func (pc *PeriodContext) Unmarshal(data []byte) error
Constants ¶
const ( EternalBlockMsgChBufferSize = 65536 MaxEternalBlockMsgCacheTime = 5 MinConfirmMsgNumberForEternalBlock = 2 * PeriodSize / 3 )
Define const.
const ( SecondInMs = int64(1000) BookkeeperRefreshInterval = int64(5000) MaxPackedTxTime = int64(100) PeriodSize = 6 BlockNumPerPeiod = 5 PeriodDuration = 21 * 5 * 10000 // CandidatePledge is pledge for candidate to mint. CandidatePledge = (uint64)(1e6 * core.DuPerBox) // MinNumOfVotes is Minimum number of votes MinNumOfVotes = (uint64)(100) )
Define const
Variables ¶
var ( // dpos ErrNoLegalPowerToProduce = errors.New("No legal power to produce block") ErrNotMyTurnToProduce = errors.New("Not my turn to produce block") ErrWrongTimeToProduce = errors.New("Wrong time to produce block") ErrNotFoundBookkeeper = errors.New("Failed to find bookkeeper") ErrDuplicateSignUpTx = errors.New("Duplicate sign up tx") ErrCandidateNotFound = errors.New("Candidate not found") ErrRepeatedMintAtSameTime = errors.New("Repeated produce block at same time") ErrFailedToVerifySign = errors.New("Failed to verify sign block") ErrNotBookkeeperPeer = errors.New("Invalid bookkeeper peer") ErrInvalidBookkeeperEpoch = errors.New("Invalid bookkeeper epoch") ErrInvalidCandidateHash = errors.New("Invalid candidate hash") ErrFailedToStoreCandidateContext = errors.New("Failed to store candidate context") ErrCandidateIsAlreadyExist = errors.New("The candidate is already exist") ErrInvalidRegisterCandidateOrVoteTx = errors.New("Invalid register candidate or vote tx") ErrCircleTxExistInDag = errors.New("circle tx exist in dag") // context ErrInvalidCandidateProtoMessage = errors.New("Invalid candidate proto message") ErrInvalidConsensusContextProtoMessage = errors.New("Invalid consensus context proto message") ErrInvalidCandidateContextProtoMessage = errors.New("Invalid condidate context proto message") ErrInvalidPeriodContextProtoMessage = errors.New("Invalid period contex proto message") ErrInvalidPeriodProtoMessage = errors.New("Invalid period proto message") ErrInvalidEternalBlockMsgProtoMessage = errors.New("Invalid eternalBlockMsg proto message") // bft_service ErrNoNeedToUpdateEternalBlock = errors.New("No need to update Eternal block") ErrIllegalMsg = errors.New("Illegal message from remote peer") ErrEternalBlockMsgHashIsExist = errors.New("EternalBlockMsgHash is already exist") )
Define err message
var ( // MetricsMintTurnCounter signs whose turn to mint MetricsMintTurnCounter = metrics.NewCounter("box.dpos.mint.turn") )
Functions ¶
This section is empty.
Types ¶
type BftService ¶
type BftService struct {
// contains filtered or unexported fields
}
BftService use for quick identification of eternal block.
func NewBftService ¶
func NewBftService(consensus *Dpos) (*BftService, error)
NewBftService new bft service for eternalBlockMsg.
func (*BftService) FetchIrreversibleInfo ¶ added in v0.3.0
func (bft *BftService) FetchIrreversibleInfo() *types.IrreversibleInfo
FetchIrreversibleInfo fetch Irreversible block info.
func (*BftService) Run ¶ added in v0.5.0
func (bft *BftService) Run()
Run bft service to handle eternalBlockMsg.
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate represents possible to be the miner.
func (*Candidate) FromProtoMessage ¶
FromProtoMessage converts proto message to candidate.
func (*Candidate) ToProtoMessage ¶
ToProtoMessage converts candidate to proto message.
type CandidateContext ¶
type CandidateContext struct {
// contains filtered or unexported fields
}
CandidateContext represents possible to be the bookkeepers.
func InitCandidateContext ¶
func InitCandidateContext() *CandidateContext
InitCandidateContext init candidate context
func (*CandidateContext) CandidateContextHash ¶
func (candidateContext *CandidateContext) CandidateContextHash() (*crypto.HashType, error)
CandidateContextHash calc candidate context hash.
func (*CandidateContext) Copy ¶ added in v0.3.0
func (candidateContext *CandidateContext) Copy() *CandidateContext
Copy returns a deep copy of CandidateContext
func (*CandidateContext) FromProtoMessage ¶
func (candidateContext *CandidateContext) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to candidate.
func (*CandidateContext) Marshal ¶
func (candidateContext *CandidateContext) Marshal() (data []byte, err error)
Marshal method marshal CandidateContext object to binary
func (*CandidateContext) ToProtoMessage ¶
func (candidateContext *CandidateContext) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts block header to proto message.
func (*CandidateContext) Unmarshal ¶
func (candidateContext *CandidateContext) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to CandidateContext object
type Config ¶
type Config struct { Keypath string `mapstructure:"keypath"` EnableMint bool `mapstructure:"enable_mint"` Passphrase string `mapstructure:"passphrase"` }
Config defines the configurations of dpos
type ConsensusContext ¶
type ConsensusContext struct {
// contains filtered or unexported fields
}
ConsensusContext represents consensus context info.
type Dpos ¶
type Dpos struct {
// contains filtered or unexported fields
}
Dpos define dpos struct
func NewDpos ¶
func NewDpos(parent goprocess.Process, chain *chain.BlockChain, txpool *txpool.TransactionPool, net p2p.Net, cfg *Config) (*Dpos, error)
NewDpos new a dpos implement.
func (*Dpos) BroadcastBFTMsgToBookkeepers ¶ added in v0.5.0
BroadcastBFTMsgToBookkeepers broadcast block BFT message to bookkeepers
func (*Dpos) EnableMint ¶
EnableMint return the peer mint status
func (*Dpos) IsBookkeeper ¶ added in v0.5.0
IsBookkeeper verifies whether the peer has authority to produce block.
func (*Dpos) IsCandidateExist ¶ added in v0.3.0
func (dpos *Dpos) IsCandidateExist(addr types.AddressHash) bool
IsCandidateExist check candidate is exist.
func (*Dpos) LoadCandidateByBlockHash ¶ added in v0.3.0
func (dpos *Dpos) LoadCandidateByBlockHash(hash *crypto.HashType) (*CandidateContext, error)
LoadCandidateByBlockHash load candidate by block hash
func (*Dpos) LoadCandidates ¶
LoadCandidates load candidates info.
func (*Dpos) LoadPeriodContext ¶
func (dpos *Dpos) LoadPeriodContext() (*PeriodContext, error)
LoadPeriodContext load period context
func (*Dpos) StoreCandidateContext ¶
StoreCandidateContext store candidate context The cache is not used here to avoid problems caused by revert block. So when block revert occurs, here we don't have to do revert.
func (*Dpos) StorePeriodContext ¶
StorePeriodContext store period context
func (*Dpos) TryToUpdateEternalBlock ¶ added in v0.3.0
TryToUpdateEternalBlock try to update eternal block.
func (*Dpos) UpdateCandidateContext ¶ added in v0.3.0
UpdateCandidateContext update candidate context in memory.
type EternalBlockMsg ¶
EternalBlockMsg represents eternal block msg.
func (*EternalBlockMsg) FromProtoMessage ¶
func (ebm *EternalBlockMsg) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to EternalBlockMsg.
func (*EternalBlockMsg) Marshal ¶
func (ebm *EternalBlockMsg) Marshal() (data []byte, err error)
Marshal method marshal Candidate object to binary
func (*EternalBlockMsg) ToProtoMessage ¶
func (ebm *EternalBlockMsg) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts EternalBlockMsg to proto message.
func (*EternalBlockMsg) Unmarshal ¶
func (ebm *EternalBlockMsg) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to Candidate object
type Period ¶
type Period struct {
// contains filtered or unexported fields
}
Period represents period info.
func (*Period) FromProtoMessage ¶
FromProtoMessage converts proto message to candidate.
func (*Period) ToProtoMessage ¶
ToProtoMessage converts candidate to proto message.
type PeriodContext ¶
type PeriodContext struct {
// contains filtered or unexported fields
}
PeriodContext represents period context info.
func InitPeriodContext ¶
func InitPeriodContext() (*PeriodContext, error)
InitPeriodContext initializes period context.
func (*PeriodContext) FindProposerWithTimeStamp ¶ added in v0.5.0
func (pc *PeriodContext) FindProposerWithTimeStamp(timestamp int64) (*types.AddressHash, error)
FindProposerWithTimeStamp find proposer in given timestamp
func (*PeriodContext) FromProtoMessage ¶
func (pc *PeriodContext) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to PeriodContext.
func (*PeriodContext) Marshal ¶
func (pc *PeriodContext) Marshal() (data []byte, err error)
Marshal method marshal ConsensusContext object to binary
func (*PeriodContext) ToProtoMessage ¶
func (pc *PeriodContext) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts PeriodContext to proto message.
func (*PeriodContext) Unmarshal ¶
func (pc *PeriodContext) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to ConsensusContext object