Documentation ¶
Index ¶
- Variables
- func Genesis(cfg *Config, state *state.StateDB, timestamp uint64, height uint64) error
- type API
- func (api *API) AvailableStake(voter string) (*big.Int, error)
- func (api *API) AvailableStakeByHeight(height uint64, voter string) (*big.Int, error)
- func (api *API) Candidate(name string) (interface{}, error)
- func (api *API) Candidates(detail bool) (interface{}, error)
- func (api *API) Info() (interface{}, error)
- func (api *API) Irreversible() (interface{}, error)
- func (api *API) NextValidCandidates() (interface{}, error)
- func (api *API) NextValidCandidatesByHeight(height uint64) (interface{}, error)
- func (api *API) SnapShotTime() (interface{}, error)
- func (api *API) SnapShotTimeByHeight(height uint64) (interface{}, error)
- func (api *API) ValidCandidates() (interface{}, error)
- func (api *API) ValidCandidatesByHeight(height uint64) (interface{}, error)
- func (api *API) VotersByCandidate(candidate string, detail bool) (interface{}, error)
- func (api *API) VotersByCandidateByHeight(height uint64, candidate string, detail bool) (interface{}, error)
- func (api *API) VotersByVoter(voter string, detail bool) (interface{}, error)
- func (api *API) VotersByVoterByHeight(height uint64, voter string, detail bool) (interface{}, error)
- type CandidateInfo
- type CandidateInfoArray
- type CandidateType
- type Config
- type Dpos
- func (dpos *Dpos) APIs(chain consensus.IChainReader) []rpc.API
- func (dpos *Dpos) Author(header *types.Header) (common.Name, error)
- func (dpos *Dpos) BlockInterval() uint64
- func (dpos *Dpos) CalcBFTIrreversible() uint64
- func (dpos *Dpos) CalcDifficulty(chain consensus.IChainReader, time uint64, parent *types.Header) *big.Int
- func (dpos *Dpos) CalcProposedIrreversible(chain consensus.IChainReader, parent *types.Header, strict bool) uint64
- func (dpos *Dpos) Config() *Config
- func (dpos *Dpos) Engine() consensus.IEngine
- func (dpos *Dpos) Finalize(chain consensus.IChainReader, header *types.Header, txs []*types.Transaction, ...) (*types.Block, error)
- func (dpos *Dpos) GetDelegatedByTime(candidate string, timestamp uint64, state *state.StateDB) (*big.Int, *big.Int, uint64, error)
- func (dpos *Dpos) IsFirst(timestamp uint64) bool
- func (dpos *Dpos) IsValidateCandidate(chain consensus.IChainReader, parent *types.Header, timestamp uint64, ...) error
- func (dpos *Dpos) Prepare(chain consensus.IChainReader, header *types.Header, txs []*types.Transaction, ...) error
- func (dpos *Dpos) ProcessAction(height uint64, chainCfg *params.ChainConfig, state *state.StateDB, ...) ([]*types.InternalAction, error)
- func (dpos *Dpos) Seal(chain consensus.IChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (dpos *Dpos) SetConfig(config *Config)
- func (dpos *Dpos) SetSignFn(signFn SignFn)
- func (dpos *Dpos) Slot(timestamp uint64) uint64
- func (dpos *Dpos) VerifySeal(chain consensus.IChainReader, header *types.Header) error
- type GlobalState
- type IDB
- type IDatabase
- type IrreversibleRet
- type KickedCandidate
- type LDB
- func (db *LDB) CandidatesSize() (uint64, error)
- func (db *LDB) DelCandidate(name string) error
- func (db *LDB) GetAvailableQuantity(epcho uint64, voter string) (*big.Int, error)
- func (db *LDB) GetCandidate(name string) (*CandidateInfo, error)
- func (db *LDB) GetCandidates() ([]*CandidateInfo, error)
- func (db *LDB) GetDelegatedByTime(candidate string, timestamp uint64) (*big.Int, *big.Int, uint64, error)
- func (db *LDB) GetLastestEpcho() (uint64, error)
- func (db *LDB) GetState(epcho uint64) (*GlobalState, error)
- func (db *LDB) GetVoter(epcho uint64, voter string, candidate string) (*VoterInfo, error)
- func (db *LDB) GetVotersByCandidate(epcho uint64, candidate string) ([]*VoterInfo, error)
- func (db *LDB) GetVotersByVoter(epcho uint64, voter string) ([]*VoterInfo, error)
- func (db *LDB) SetAvailableQuantity(epcho uint64, voter string, quantity *big.Int) error
- func (db *LDB) SetCandidate(candidate *CandidateInfo) error
- func (db *LDB) SetLastestEpcho(epcho uint64) error
- func (db *LDB) SetState(gstate *GlobalState) error
- func (db *LDB) SetVoter(voter *VoterInfo) error
- type RegisterCandidate
- type SignFn
- type System
- func (sys *System) ExitTakeOver(epcho uint64) error
- func (sys *System) GetDelegatedByTime(candidate string, timestamp uint64) (*big.Int, *big.Int, uint64, error)
- func (sys *System) KickedCandidate(epcho uint64, candidate string, height uint64) error
- func (sys *System) RefundCandidate(epcho uint64, candidate string, height uint64) error
- func (sys *System) RegCandidate(epcho uint64, candidate string, url string, stake *big.Int, height uint64) error
- func (sys *System) UnregCandidate(epcho uint64, candidate string, height uint64) error
- func (sys *System) UpdateCandidate(epcho uint64, candidate string, url string, nstake *big.Int, height uint64) error
- func (sys *System) UpdateElectedCandidates(pepcho uint64, epcho uint64, height uint64) error
- func (sys *System) VoteCandidate(epcho uint64, voter string, candidate string, stake *big.Int, height uint64) error
- type UInt64Slice
- type UpdateCandidate
- type VoteCandidate
- type VoterInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrIllegalCandidateName = errors.New("illegal candidate name") ErrIllegalCandidatePubKey = errors.New("illegal candidate pubkey") ErrTooMuchRreversible = errors.New("too much rreversible blocks") ErrSystemTakeOver = errors.New("system account take over") )
var ( // CandidateKeyPrefix candidateInfo CandidateKeyPrefix = "p" // CandidateHead all candidate key CandidateHead = "s" // VoterKeyPrefix voterInfo VoterKeyPrefix = "v" // VoterHead head VoterHead = "v" // StateKeyPrefix globalState StateKeyPrefix = "s" // LastestStateKey lastest LastestStateKey = "lastest" // Separator Split characters Separator = "_" )
var DefaultConfig = &Config{ MaxURLLen: 512, UnitStake: big.NewInt(1000), CandidateMinQuantity: big.NewInt(10), VoterMinQuantity: big.NewInt(1), ActivatedMinQuantity: big.NewInt(100), BlockInterval: 3000, BlockFrequency: 6, CandidateScheduleSize: 3, BackupScheduleSize: 0, EpchoInterval: 540000, FreezeEpchoSize: 3, AccountName: "ftsystemdpos", SystemName: "ftsystemio", SystemURL: "www.fractalproject.com", ExtraBlockReward: big.NewInt(1), BlockReward: big.NewInt(5), Decimals: 18, AssetID: 1, ReferenceTime: 1555776000000 * uint64(time.Millisecond), }
DefaultConfig configures
var LastEpcho = uint64(math.MaxUint64)
LastEpcho latest
Functions ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API exposes dpos related methods for the RPC interface.
func (*API) AvailableStake ¶ added in v0.0.8
AvailableStake get available stake
func (*API) AvailableStakeByHeight ¶ added in v0.0.8
AvailableStakeByHeight get available stake
func (*API) Candidates ¶ added in v0.0.8
Candidates all candidates info
func (*API) Irreversible ¶
Irreversible get irreversible info
func (*API) NextValidCandidates ¶ added in v0.0.8
NextValidCandidates current valid candidates
func (*API) NextValidCandidatesByHeight ¶ added in v0.0.8
NextValidCandidatesByHeight current valid candidates
func (*API) SnapShotTime ¶ added in v0.0.8
SnapShotTime get snapshort
func (*API) SnapShotTimeByHeight ¶ added in v0.0.8
SnapShotTimeByHeight get snapshort by height
func (*API) ValidCandidates ¶ added in v0.0.8
ValidCandidates current valid candidates
func (*API) ValidCandidatesByHeight ¶ added in v0.0.8
ValidCandidatesByHeight valid candidates
func (*API) VotersByCandidate ¶ added in v0.0.8
VotersByCandidate get voters info of candidate
func (*API) VotersByCandidateByHeight ¶ added in v0.0.8
func (api *API) VotersByCandidateByHeight(height uint64, candidate string, detail bool) (interface{}, error)
VotersByCandidateByHeight get voters info of candidate
func (*API) VotersByVoter ¶ added in v0.0.8
VotersByVoter get voters info of voter
type CandidateInfo ¶ added in v0.0.8
type CandidateInfo struct { Name string `json:"name"` // candidate name URL string `json:"url"` // candidate url Quantity *big.Int `json:"quantity"` // candidate stake quantity TotalQuantity *big.Int `json:"totalQuantity"` // candidate total stake quantity Height uint64 `json:"height"` // timestamp Counter uint64 `json:"counter"` Type CandidateType `json:"type"` PrevKey string `json:"-"` NextKey string `json:"-"` }
CandidateInfo info
type CandidateInfoArray ¶ added in v0.0.8
type CandidateInfoArray []*CandidateInfo
CandidateInfoArray array of candidate
func (CandidateInfoArray) Len ¶ added in v0.0.8
func (prods CandidateInfoArray) Len() int
func (CandidateInfoArray) Less ¶ added in v0.0.8
func (prods CandidateInfoArray) Less(i, j int) bool
func (CandidateInfoArray) Swap ¶ added in v0.0.8
func (prods CandidateInfoArray) Swap(i, j int)
type CandidateType ¶ added in v0.0.8
type CandidateType uint64
const ( Normal CandidateType = iota Freeze Black Jail Unkown )
func (CandidateType) MarshalJSON ¶ added in v0.0.8
func (t CandidateType) MarshalJSON() ([]byte, error)
MarshalJSON returns the hex representation of a.
func (CandidateType) MarshalText ¶ added in v0.0.8
func (t CandidateType) MarshalText() ([]byte, error)
MarshalText returns the hex representation of a.
func (*CandidateType) UnmarshalJSON ¶ added in v0.0.8
func (t *CandidateType) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a type in syntax.
func (*CandidateType) UnmarshalText ¶ added in v0.0.8
func (t *CandidateType) UnmarshalText(input []byte) error
UnmarshalText parses a hash in syntax.
type Config ¶
type Config struct { // consensus fileds MaxURLLen uint64 `json:"maxURLLen"` // url length UnitStake *big.Int `json:"unitStake"` // state unit CandidateMinQuantity *big.Int `json:"candidateMinQuantity"` // min quantity VoterMinQuantity *big.Int `json:"voterMinQuantity"` // min quantity ActivatedMinQuantity *big.Int `json:"activatedMinQuantity"` // min active quantity BlockInterval uint64 `json:"blockInterval"` BlockFrequency uint64 `json:"blockFrequency"` CandidateScheduleSize uint64 `json:"candidateScheduleSize"` BackupScheduleSize uint64 `json:"backupScheduleSize"` EpchoInterval uint64 `json:"epchoInterval"` FreezeEpchoSize uint64 `json:"freezeEpchoSize"` AccountName string `json:"accountName"` SystemName string `json:"systemName"` SystemURL string `json:"systemURL"` ExtraBlockReward *big.Int `json:"extraBlockReward"` BlockReward *big.Int `json:"blockReward"` InitCandidateSchedule []string `json:"initCandidateSchedule"` Decimals uint64 `json:"decimals"` AssetID uint64 `json:"assetID"` ReferenceTime uint64 `json:"referenceTime"` // contains filtered or unexported fields }
Config dpos configures
type Dpos ¶
type Dpos struct {
// contains filtered or unexported fields
}
Dpos dpos engine
func New ¶
func New(config *Config, chain consensus.IChainReader) *Dpos
New creates a DPOS consensus engine
func (*Dpos) APIs ¶
func (dpos *Dpos) APIs(chain consensus.IChainReader) []rpc.API
APIs returning the user facing RPC APIs.
func (*Dpos) CalcBFTIrreversible ¶ added in v0.0.7
CalcBFTIrreversible calc irreversible
func (*Dpos) CalcDifficulty ¶
func (dpos *Dpos) CalcDifficulty(chain consensus.IChainReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty.
func (*Dpos) CalcProposedIrreversible ¶ added in v0.0.7
func (dpos *Dpos) CalcProposedIrreversible(chain consensus.IChainReader, parent *types.Header, strict bool) uint64
CalcProposedIrreversible calc irreversible
func (*Dpos) Finalize ¶
func (dpos *Dpos) Finalize(chain consensus.IChainReader, header *types.Header, txs []*types.Transaction, receipts []*types.Receipt, state *state.StateDB) (*types.Block, error)
Finalize assembles the final block.
func (*Dpos) GetDelegatedByTime ¶ added in v0.0.7
func (dpos *Dpos) GetDelegatedByTime(candidate string, timestamp uint64, state *state.StateDB) (*big.Int, *big.Int, uint64, error)
GetDelegatedByTime get delegate of candidate
func (*Dpos) IsValidateCandidate ¶ added in v0.0.8
func (dpos *Dpos) IsValidateCandidate(chain consensus.IChainReader, parent *types.Header, timestamp uint64, candidate string, pubkeys [][]byte, state *state.StateDB, force bool) error
IsValidateCandidate current candidate
func (*Dpos) Prepare ¶
func (dpos *Dpos) Prepare(chain consensus.IChainReader, header *types.Header, txs []*types.Transaction, receipts []*types.Receipt, state *state.StateDB) error
Prepare initializes the consensus fields of a block header according to the rules of a particular engine. The changes are executed inline.
func (*Dpos) ProcessAction ¶
func (dpos *Dpos) ProcessAction(height uint64, chainCfg *params.ChainConfig, state *state.StateDB, action *types.Action) ([]*types.InternalAction, error)
ProcessAction exec action
func (*Dpos) Seal ¶
func (dpos *Dpos) Seal(chain consensus.IChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
Seal generates a new block for the given input block with the local miner's seal place on top.
func (*Dpos) VerifySeal ¶
VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.
type GlobalState ¶ added in v0.0.8
type GlobalState struct { Epcho uint64 `json:"epcho"` // epcho PreEpcho uint64 `json:"preEpcho"` // epcho ActivatedCandidateSchedule []string `json:"activatedCandidateSchedule"` // candidates ActivatedTotalQuantity *big.Int `json:"activatedTotalQuantity"` // the sum of activate candidate votes TotalQuantity *big.Int `json:"totalQuantity"` // the sum of all candidate votes TakeOver bool `json:"takeOver"` // systemio take over dpos Dpos bool `json:"dpos"` // dpos status Height uint64 `json:"height"` // timestamp }
GlobalState dpos state
type IDB ¶
type IDB interface { SetCandidate(*CandidateInfo) error DelCandidate(string) error GetCandidate(string) (*CandidateInfo, error) GetCandidates() ([]*CandidateInfo, error) CandidatesSize() (uint64, error) SetAvailableQuantity(uint64, string, *big.Int) error GetAvailableQuantity(uint64, string) (*big.Int, error) SetVoter(*VoterInfo) error GetVoter(uint64, string, string) (*VoterInfo, error) GetVotersByVoter(uint64, string) ([]*VoterInfo, error) GetVotersByCandidate(uint64, string) ([]*VoterInfo, error) SetState(*GlobalState) error GetState(uint64) (*GlobalState, error) SetLastestEpcho(uint64) error GetLastestEpcho() (uint64, error) Undelegate(string, *big.Int) (*types.Action, error) IncAsset2Acct(string, string, *big.Int) (*types.Action, error) GetBalanceByTime(name string, timestamp uint64) (*big.Int, error) GetDelegatedByTime(string, uint64) (*big.Int, *big.Int, uint64, error) }
IDB dpos database
type IDatabase ¶
type IDatabase interface { Get(key string) ([]byte, error) Put(key string, value []byte) error Delete(key string) error Undelegate(string, *big.Int) (*types.Action, error) IncAsset2Acct(string, string, *big.Int) (*types.Action, error) GetBalanceByTime(name string, timestamp uint64) (*big.Int, error) GetSnapshot(key string, timestamp uint64) ([]byte, error) }
IDatabase level db
type IrreversibleRet ¶ added in v0.0.8
type IrreversibleRet struct { ProposedIrreversible uint64 `json:"proposedIrreversible"` BftIrreversible uint64 `json:"bftIrreversible"` Reversible uint64 `json:"reversible"` }
IrreversibleRet result
type KickedCandidate ¶ added in v0.0.8
type KickedCandidate struct {
Candidates []string
}
KickedCandidate kicked info
type LDB ¶
type LDB struct {
IDatabase
}
LDB dpos level db
func (*LDB) CandidatesSize ¶ added in v0.0.8
CandidatesSize candidate len
func (*LDB) DelCandidate ¶ added in v0.0.8
DelCandidate del candidate info
func (*LDB) GetAvailableQuantity ¶ added in v0.0.8
GetAvailableQuantity get quantity
func (*LDB) GetCandidate ¶ added in v0.0.8
func (db *LDB) GetCandidate(name string) (*CandidateInfo, error)
GetCandidate get candidate info by name
func (*LDB) GetCandidates ¶ added in v0.0.8
func (db *LDB) GetCandidates() ([]*CandidateInfo, error)
GetCandidates get all candidate info & sort
func (*LDB) GetDelegatedByTime ¶ added in v0.0.7
func (db *LDB) GetDelegatedByTime(candidate string, timestamp uint64) (*big.Int, *big.Int, uint64, error)
GetDelegatedByTime candidate delegate
func (*LDB) GetLastestEpcho ¶ added in v0.0.8
GetLastestEpcho get latest epcho
func (*LDB) GetState ¶
func (db *LDB) GetState(epcho uint64) (*GlobalState, error)
GetState get state info
func (*LDB) GetVotersByCandidate ¶ added in v0.0.8
GetVotersByCandidate voters info by candidate
func (*LDB) GetVotersByVoter ¶ added in v0.0.8
GetVotersByVoter voters info by voter
func (*LDB) SetAvailableQuantity ¶ added in v0.0.8
SetAvailableQuantity set quantity
func (*LDB) SetCandidate ¶ added in v0.0.8
func (db *LDB) SetCandidate(candidate *CandidateInfo) error
SetCandidate update candidate info
func (*LDB) SetLastestEpcho ¶ added in v0.0.8
SetLastestEpcho set latest epcho
func (*LDB) SetState ¶
func (db *LDB) SetState(gstate *GlobalState) error
SetState set global state info
type RegisterCandidate ¶ added in v0.0.8
type RegisterCandidate struct {
URL string
}
RegisterCandidate candidate info
type System ¶
type System struct { IDB // contains filtered or unexported fields }
System dpos internal contract
func (*System) ExitTakeOver ¶ added in v0.0.7
ExitTakeOver system exit take over
func (*System) GetDelegatedByTime ¶ added in v0.0.7
func (sys *System) GetDelegatedByTime(candidate string, timestamp uint64) (*big.Int, *big.Int, uint64, error)
GetDelegatedByTime candidate delegated
func (*System) KickedCandidate ¶ added in v0.0.8
KickedCandidate kicked
func (*System) RefundCandidate ¶ added in v0.0.8
RefundCandidate refund a candidate
func (*System) RegCandidate ¶ added in v0.0.8
func (sys *System) RegCandidate(epcho uint64, candidate string, url string, stake *big.Int, height uint64) error
RegCandidate register a candidate
func (*System) UnregCandidate ¶ added in v0.0.8
UnregCandidate unregister a candidate
func (*System) UpdateCandidate ¶ added in v0.0.8
func (sys *System) UpdateCandidate(epcho uint64, candidate string, url string, nstake *big.Int, height uint64) error
UpdateCandidate update a candidate
func (*System) UpdateElectedCandidates ¶ added in v0.0.8
UpdateElectedCandidates update
type UInt64Slice ¶
type UInt64Slice []uint64
UInt64Slice attaches the methods of sort.Interface to []uint64, sorting in increasing order.
func (UInt64Slice) Len ¶
func (s UInt64Slice) Len() int
func (UInt64Slice) Less ¶
func (s UInt64Slice) Less(i, j int) bool
func (UInt64Slice) Swap ¶
func (s UInt64Slice) Swap(i, j int)
type UpdateCandidate ¶ added in v0.0.8
type UpdateCandidate struct {
URL string
}
UpdateCandidate candidate info
type VoteCandidate ¶ added in v0.0.8
VoteCandidate vote info
type VoterInfo ¶ added in v0.0.8
type VoterInfo struct { Epcho uint64 `json:"epcho"` Name string `json:"name"` // voter name Candidate string `json:"candidate"` // candidate approved by this voter Quantity *big.Int `json:"quantity"` // stake approved by this voter Height uint64 `json:"height"` // timestamp NextKeyForVoter string `json:"-"` NextKeyForCandidate string `json:"-"` }
VoterInfo info