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) BroadcastEternalMsgToMiners(block *types.Block) error
- func (dpos *Dpos) EnableMint() 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) 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, batch storage.Batch) error
- func (dpos *Dpos) StorePeriodContext() error
- func (dpos *Dpos) TryToUpdateEternalBlock(src *types.Block)
- func (dpos *Dpos) UpdateCandidateContext(block *types.Block) error
- func (dpos *Dpos) ValidateMiner() bool
- func (dpos *Dpos) VerifyCandidates(block *types.Block) error
- func (dpos *Dpos) VerifyMinerEpoch(block *types.Block) error
- func (dpos *Dpos) VerifySign(block *types.Block) (bool, error)
- type EternalBlockMsg
- type Period
- type PeriodContext
- func (pc *PeriodContext) FindMinerWithTimeStamp(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) MinerRefreshInterval = int64(5000) MaxPackedTxTime = int64(100) PeriodSize = 15 BlockNumPerPeiod = 5 )
Define const
Variables ¶
var ( // dpos ErrNoLegalPowerToMint = errors.New("No legal power to mint") ErrNotMyTurnToMint = errors.New("Not my turn to mint") ErrWrongTimeToMint = errors.New("Wrong time to mint") ErrNotFoundMiner = errors.New("Failed to find miner") ErrDuplicateSignUpTx = errors.New("Duplicate sign up tx") ErrCandidateNotFound = errors.New("Candidate not found") ErrRepeatedMintAtSameTime = errors.New("Repeated mint at same time") ErrFailedToVerifySign = errors.New("Failed to verify sign block") ErrNotMintPeer = errors.New("Invalid mint peer") ErrInvalidMinerEpoch = errors.New("Invalid miner epoch") ErrInvalidCandidateHash = errors.New("Invalid candidate hash") ErrFailedToStoreCandidateContext = errors.New("Failed to store candidate context") // 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) Start ¶
func (bft *BftService) Start()
Start 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 miner.
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) BroadcastEternalMsgToMiners ¶
BroadcastEternalMsgToMiners broadcast eternal message to miners
func (*Dpos) EnableMint ¶
EnableMint return the peer mint status
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.
func (*Dpos) ValidateMiner ¶
ValidateMiner verifies whether the miner has authority to mint.
func (*Dpos) VerifyCandidates ¶ added in v0.3.0
VerifyCandidates vefiry if the block candidates hash is right.
func (*Dpos) VerifyMinerEpoch ¶
VerifyMinerEpoch verifies miner epoch.
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) FindMinerWithTimeStamp ¶
func (pc *PeriodContext) FindMinerWithTimeStamp(timestamp int64) (*types.AddressHash, error)
FindMinerWithTimeStamp find miner 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