dpos

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 24 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)
	MinerRefreshInterval = int64(5000)
	MaxPackedTxTime      = int64(100)
	PeriodSize           = 15
	BlockNumPerPeiod     = 5
)

Define const

Variables

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

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) 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

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

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

BroadcastEternalMsgToMiners broadcast eternal message to miners

func (*Dpos) EnableMint

func (dpos *Dpos) EnableMint() bool

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

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) RecoverMint

func (dpos *Dpos) RecoverMint()

RecoverMint resumes generating 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 generating blocks.

func (*Dpos) StoreCandidateContext

func (dpos *Dpos) StoreCandidateContext(block *types.Block, batch storage.Batch) 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) ValidateMiner

func (dpos *Dpos) ValidateMiner() bool

ValidateMiner verifies whether the miner has authority to mint.

func (*Dpos) VerifyCandidates added in v0.3.0

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

VerifyCandidates vefiry if the block candidates hash is right.

func (*Dpos) VerifyMinerEpoch

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

VerifyMinerEpoch verifies miner epoch.

func (*Dpos) VerifySign

func (dpos *Dpos) VerifySign(block *types.Block) (bool, error)

VerifySign consensus verifies signature info.

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) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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