dpos

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxUnlockDuration time.Duration = 1<<63 - 1
	GenesisDynasty                         = 1
	GenesisDynastySerial                   = 0
)

const

View Source
const (
	SecondInMs               = int64(1000)
	BlockIntervalInMs        = int64(15000)
	AcceptedNetWorkDelayInMs = int64(3750)
	MaxMintDurationInMs      = int64(5250)
	MinMintDurationInMs      = int64(2250)
	DynastyIntervalInMs      = int64(3150000)
	DynastySize              = 21
	ConsensusSize            = DynastySize*2/3 + 1
)

Consensus Related Constants

Variables

View Source
var (
	ErrInvalidBlockTimestamp      = errors.New("invalid block timestamp, should be same as consensus's timestamp")
	ErrInvalidBlockInterval       = errors.New("invalid block interval")
	ErrMissingConfigForDpos       = errors.New("missing configuration for Dpos")
	ErrInvalidBlockProposer       = errors.New("invalid block proposer")
	ErrCannotMintWhenPending      = errors.New("cannot mint block now, waiting for cancel pending again")
	ErrCannotMintWhenDisable      = errors.New("cannot mint block now, waiting for enable it again")
	ErrWaitingBlockInLastSlot     = errors.New("cannot mint block now, waiting for last block")
	ErrBlockMintedInNextSlot      = errors.New("cannot mint block now, there is a block minted in current slot")
	ErrGenerateNextConsensusState = errors.New("Failed to generate next consensus state")
	ErrDoubleBlockMinted          = errors.New("double block minted")
	ErrAppendNewBlockFailed       = errors.New("failed to append new block to real chain")
	ErrInvalidArgument            = errors.New("invalid argument")
)

Errors in PoW Consensus

View Source
var (
	ErrTooFewCandidates        = errors.New("the size of candidates in consensus is un-safe, should be greater than or equal " + strconv.Itoa(ConsensusSize))
	ErrInitialDynastyNotEnough = errors.New("the size of initial dynasty in genesis block is un-safe, should be greater than or equal " + strconv.Itoa(ConsensusSize))
	ErrInvalidDynasty          = errors.New("the size of initial dynasty in genesis block is invalid, should be equal " + strconv.Itoa(DynastySize))
	ErrCloneDynastyTrie        = errors.New("Failed to clone dynasty trie")
	ErrCloneNextDynastyTrie    = errors.New("Failed to clone next dynasty trie")
	ErrCloneDelegateTrie       = errors.New("Failed to clone delegate trie")
	ErrCloneCandidatesTrie     = errors.New("Failed to clone candidates trie")
	ErrCloneVoteTrie           = errors.New("Failed to clone vote trie")
	ErrCloneMintCntTrie        = errors.New("Failed to clone mint count trie")
	ErrNotBlockForgTime        = errors.New("now is not time to forg block")
	ErrFoundNilProposer        = errors.New("found a nil proposer")
)

Errors in dpos state

View Source
var (
	ErrFailedToLoadDynasty     = errors.New("Failed to load dynasty file.")
	ErrFailedToParseDynasty    = errors.New("Failed to parse dynasty.conf.")
	ErrCheckDynastyChainID     = errors.New("ChainId in dynasty.conf differs from that in genesis.conf.")
	ErrCheckDynastyMinersCount = errors.New("Miners count in dynasty.conf differs from that in genesis.conf.")
)

Error in dynasty

Functions

func FindProposer

func FindProposer(now int64, miners []byteutils.Hash) (proposer byteutils.Hash, err error)

FindProposer for now in given dynasty

func TraverseDynasty

func TraverseDynasty(dynasty *trie.Trie) ([]byteutils.Hash, error)

TraverseDynasty return all members in the dynasty

Types

type Dpos

type Dpos struct {
	// contains filtered or unexported fields
}

Dpos Delegate Proof-of-Stake

func NewDpos

func NewDpos() *Dpos

NewDpos create Dpos instance.

func (*Dpos) CheckDoubleMint added in v1.0.1

func (dpos *Dpos) CheckDoubleMint(block *core.Block) bool

CheckDoubleMint if double mint exists

func (*Dpos) CheckTimeout

func (dpos *Dpos) CheckTimeout(block *core.Block) bool

CheckTimeout check whether the block is timeout

func (*Dpos) DisableMining

func (dpos *Dpos) DisableMining() error

DisableMining stop the consensus

func (*Dpos) Enable

func (dpos *Dpos) Enable() bool

Enable returns is mining

func (*Dpos) EnableMining

func (dpos *Dpos) EnableMining(passphrase string) error

EnableMining start the consensus

func (*Dpos) ForkChoice

func (dpos *Dpos) ForkChoice() error

ForkChoice select new tail

func (*Dpos) GenesisConsensusState

func (dpos *Dpos) GenesisConsensusState(chain *core.BlockChain, conf *corepb.Genesis) (state.ConsensusState, error)

GenesisConsensusState create a new genesis dpos state

func (*Dpos) NewState

func (dpos *Dpos) NewState(root *consensuspb.ConsensusRoot, stor storage.Storage, needChangeLog bool) (state.ConsensusState, error)

NewState create a new dpos state

func (*Dpos) NumberOfBlocksInDynasty added in v1.0.2

func (dpos *Dpos) NumberOfBlocksInDynasty() uint64

NumberOfBlocksInDynasty number of blocks in one dynasty

func (*Dpos) Pending

func (dpos *Dpos) Pending() bool

Pending return if consensus can do mining now

func (*Dpos) ResumeMining

func (dpos *Dpos) ResumeMining()

ResumeMining continue dpos mining

func (*Dpos) Setup

func (dpos *Dpos) Setup(neblet core.Neblet) error

Setup a dpos consensus handler

func (*Dpos) Start

func (dpos *Dpos) Start()

Start start pow service.

func (*Dpos) Stop

func (dpos *Dpos) Stop()

Stop stop pow service.

func (*Dpos) SuspendMining

func (dpos *Dpos) SuspendMining()

SuspendMining pend dpos mining

func (*Dpos) UpdateLIB

func (dpos *Dpos) UpdateLIB()

UpdateLIB update the latest irrversible block

func (*Dpos) VerifyBlock

func (dpos *Dpos) VerifyBlock(block *core.Block) error

VerifyBlock verify the block

type Dynasty

type Dynasty struct {
	// contains filtered or unexported fields
}

Dynasty dpos dynasty

func NewDynasty

func NewDynasty(neb core.Neblet) (*Dynasty, error)

NewDynasty create dynasty

type State

type State struct {
	// contains filtered or unexported fields
}

State carry context in dpos consensus

func (*State) Clone

func (ds *State) Clone() (state.ConsensusState, error)

Clone a dpos context

func (*State) Dynasty

func (ds *State) Dynasty() ([]byteutils.Hash, error)

Dynasty return the current dynasty

func (*State) DynastyRoot

func (ds *State) DynastyRoot() byteutils.Hash

DynastyRoot return the roothash of current dynasty

func (*State) NextConsensusState

func (ds *State) NextConsensusState(elapsedSecond int64, worldState state.WorldState) (state.ConsensusState, error)

NextConsensusState return the new state after some seconds elapsed

func (*State) Proposer

func (ds *State) Proposer() byteutils.Hash

Proposer return the current proposer

func (*State) Replay

func (ds *State) Replay(done state.ConsensusState) error

Replay a dpos

func (*State) RootHash

func (ds *State) RootHash() *consensuspb.ConsensusRoot

RootHash hash dpos state

func (*State) String

func (ds *State) String() string

func (*State) TimeStamp

func (ds *State) TimeStamp() int64

TimeStamp return the current timestamp

Jump to

Keyboard shortcuts

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