dpos

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EternalBlockMsgChBufferSize        = 65536
	MaxEternalBlockMsgCacheTime        = 5
	MinConfirmMsgNumberForEternalBlock = 2 * PeriodSize / 3
)

Define const.

View Source
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

View Source
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

View Source
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

func (candidate *Candidate) FromProtoMessage(message proto.Message) error

FromProtoMessage converts proto message to candidate.

func (*Candidate) Marshal

func (candidate *Candidate) Marshal() (data []byte, err error)

Marshal method marshal Candidate object to binary

func (*Candidate) ToProtoMessage

func (candidate *Candidate) ToProtoMessage() (proto.Message, error)

ToProtoMessage converts candidate to proto message.

func (*Candidate) Unmarshal

func (candidate *Candidate) Unmarshal(data []byte) error

Unmarshal method unmarshal binary data to Candidate object

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

func (dpos *Dpos) BroadcastBFTMsgToBookkeepers(block *types.Block, messageID uint32) error

BroadcastBFTMsgToBookkeepers broadcast block BFT message to bookkeepers

func (*Dpos) EnableMint

func (dpos *Dpos) EnableMint() bool

EnableMint return the peer mint status

func (*Dpos) Finalize added in v0.5.0

func (dpos *Dpos) Finalize(tail *types.Block) error

Finalize notify consensus to change new tail.

func (*Dpos) IsBookkeeper added in v0.5.0

func (dpos *Dpos) IsBookkeeper() bool

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

func (dpos *Dpos) LoadCandidates() error

LoadCandidates load candidates info.

func (*Dpos) LoadPeriodContext

func (dpos *Dpos) LoadPeriodContext() (*PeriodContext, error)

LoadPeriodContext load period context

func (*Dpos) PackTxs

func (dpos *Dpos) PackTxs(block *types.Block, scriptAddr []byte) error

PackTxs packed txs and add them to block.

func (*Dpos) Proc

func (dpos *Dpos) Proc() goprocess.Process

Proc returns the goprocess running the service

func (*Dpos) Process added in v0.5.0

func (dpos *Dpos) Process(block *types.Block, db interface{}) error

Process notify consensus to process new block.

func (*Dpos) RecoverMint

func (dpos *Dpos) RecoverMint()

RecoverMint resumes producing blocks.

func (*Dpos) Run

func (dpos *Dpos) Run() error

Run start dpos

func (*Dpos) Setup

func (dpos *Dpos) Setup() error

Setup setup dpos

func (*Dpos) Stop

func (dpos *Dpos) Stop()

Stop dpos

func (*Dpos) StopMint

func (dpos *Dpos) StopMint()

StopMint stops producing blocks.

func (*Dpos) StoreCandidateContext

func (dpos *Dpos) StoreCandidateContext(block *types.Block, db storage.Table) error

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

func (dpos *Dpos) StorePeriodContext() error

StorePeriodContext store period context

func (*Dpos) TryToUpdateEternalBlock added in v0.3.0

func (dpos *Dpos) TryToUpdateEternalBlock(src *types.Block)

TryToUpdateEternalBlock try to update eternal block.

func (*Dpos) UpdateCandidateContext added in v0.3.0

func (dpos *Dpos) UpdateCandidateContext(block *types.Block) error

UpdateCandidateContext update candidate context in memory.

func (*Dpos) Verify added in v0.5.0

func (dpos *Dpos) Verify(block *types.Block) error

Verify check the legality of the block.

func (*Dpos) VerifyTx added in v0.5.0

func (dpos *Dpos) VerifyTx(tx *types.Transaction) error

VerifyTx notify consensus to verify new tx.

type EternalBlockMsg

type EternalBlockMsg struct {
	Hash      crypto.HashType
	Signature []byte
	Timestamp int64
}

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

func (period *Period) FromProtoMessage(message proto.Message) error

FromProtoMessage converts proto message to candidate.

func (*Period) Marshal

func (period *Period) Marshal() (data []byte, err error)

Marshal method marshal Period object to binary

func (*Period) ToProtoMessage

func (period *Period) ToProtoMessage() (proto.Message, error)

ToProtoMessage converts candidate to proto message.

func (*Period) Unmarshal

func (period *Period) Unmarshal(data []byte) error

Unmarshal method unmarshal binary data to Period object

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL