Documentation
¶
Index ¶
- Constants
- Variables
- type BftService
- type Candidate
- type CandidateContext
- func (candidateContext *CandidateContext) CandidateContextHash() (*crypto.HashType, error)
- 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) 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(hash *crypto.HashType) error
- func (dpos *Dpos) StorePeriodContext() error
- func (dpos *Dpos) ValidateMiner() bool
- func (dpos *Dpos) VerifyMinerEpoch(block *types.Block) error
- func (dpos *Dpos) VerifySign(block *types.Block) (bool, error)
- type EternalBlockMsg
- type EternalBlockMsgKeyType
- 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 = 10 * 60 MinConfirmMsgNumberForEternalBlock = 2 * PeriodSize / 3 EternalBlockMsgKeySize = crypto.HashSize + 8 )
Define const.
const ( SecondInMs = int64(1000) NewBlockTimeInterval = int64(5000) MaxPackedTxTime = int64(2000) MaxBlockTimeOut = 2 PeriodSize = 6 )
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") // 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) 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) 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) 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
func (*Dpos) StorePeriodContext ¶
StorePeriodContext store period context
func (*Dpos) ValidateMiner ¶
ValidateMiner verifies whether the miner has authority to mint.
func (*Dpos) VerifyMinerEpoch ¶
VerifyMinerEpoch verifies miner epoch.
type EternalBlockMsg ¶
type EternalBlockMsg struct {
// contains filtered or unexported fields
}
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 EternalBlockMsgKeyType ¶
type EternalBlockMsgKeyType [EternalBlockMsgKeySize]byte
EternalBlockMsgKeyType is renamed EternalBlockMsgKey type
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