dpos

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2019 License: GPL-3.0 Imports: 24 Imported by: 7

README

dpos生成者注册及投票者投票

参数说明

  • UnitStake 一票所代表的权益
  • MaxURLLen 生产者URL最大长度
  • ProducerMinQuantity 生成者需要抵押的最低票数
  • VoterMinQuantity 投票者需要抵押的最低票数
  • ActivatedMinQuantity dpos启动需要的最低票数
  • BlockInterval 每轮生产者出块间隔
  • BlockFrequency 每轮生产者连续出块个数
  • ProducerScheduleSize: 每轮生成者最大个数

dpos启动

  • 网络投票总数 >= ActivatedMinQuantity && 已注册的生成者个数 >= ProducerScheduleSize * 2 / 3 + 1
  • 启动后, 启动条件必须一直满足

注册生产者/更新生产者

RegProducer(producer string, address string, url string, stake *big.Int) error

  • 账户名必须存在
  • 账户名与提供的公钥匹配
  • 提供的URL长度 <= MaxURLLen
  • 抵押stake 需满足UnitStake的整数倍, 且商 >= ProducerMinQuantity
  • 未投票

注销生成者

UnregProducer(producer string) error

  • 有效生产者
  • 注销后,已注册生产者个数 >= ProducerScheduleSize * 2 / 3 + 1
  • 注销后,网络投票总数 >= ActivatedMinQuantity
  • 未存在投票者投票

投票者投票

VoteProducer(voter string, producer string, stake *big.Int) error

  • 账户名必须存在
  • 抵押stake 需满足UnitStake的整数倍, 且商 >= VoterMinQuantity
  • 未注册生产者
  • 未投票
  • 有效的生产者

投票者改票

ChangeProducer(voter string, producer string) error

  • 已投票
  • 不是相同的生产者
  • 有效的生产者

投票者取消投票

UnvoteProducer(voter string) error

  • 已投票
  • 取消后,网络投票总数 >= ActivatedMinQuantity

生产者取消投票者的投票

UnvoteVoter(producer string, voter string) error

  • 投票者已投票
  • 投票的生产者确实是该生产者
  • 取消后,网络投票总数 >= ActivatedMinQuantity

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIllegalProducerName   = errors.New("illegal producer name")
	ErrIllegalProducerPubKey = errors.New("illegal producer pubkey")
)
View Source
var (
	// ProducerKeyPrefix producer name --> producerInfo
	ProducerKeyPrefix = "prod"
	// VoterKeyPrefix voter name ---> voterInfo
	VoterKeyPrefix = "vote"
	// // DelegatorKeyPrfix producer name ----> voter names
	// DelegatorKeyPrfix = "dele"
	// ProducersKeyPrefix produces ----> producer names
	ProducersKeyPrefix = "prods"
	// StateKeyPrefix height --> globalState
	StateKeyPrefix = "state"
	// Separator Split characters
	Separator = "_"

	// ProducersKey producers
	ProducersKey = "prods"
	// ProducersSizeKey producers size
	ProducersSizeKey = "prodsize"
	// LastestStateKey lastest
	LastestStateKey = "lastest"
)
View Source
var DefaultConfig = &Config{
	MaxURLLen:            512,
	UnitStake:            big.NewInt(1000),
	ProducerMinQuantity:  big.NewInt(10),
	VoterMinQuantity:     big.NewInt(1),
	ActivatedMinQuantity: big.NewInt(100),
	BlockInterval:        3000,
	BlockFrequency:       6,
	ProducerScheduleSize: 3,
	DelayEcho:            2,
	AccountName:          "ftsystemdpos",
	SystemName:           "ftsystemio",
	SystemURL:            "www.fractalproject.com",
	ExtraBlockReward:     big.NewInt(1),
	BlockReward:          big.NewInt(5),
	Decimals:             18,
}

DefaultConfig configures

View Source
var (
	// LastBlockHeight latest
	LastBlockHeight = uint64(math.MaxUint64)
)

Functions

func Genesis

func Genesis(cfg *Config, state *state.StateDB, height uint64) error

Types

type API

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

API exposes dpos related methods for the RPC interface.

func (*API) Account

func (api *API) Account(name string) (interface{}, error)

func (*API) Epcho

func (api *API) Epcho(height uint64) (interface{}, error)

func (*API) Info

func (api *API) Info() (interface{}, error)

func (*API) Irreversible

func (api *API) Irreversible() (interface{}, error)

func (*API) LatestEpcho

func (api *API) LatestEpcho() (interface{}, error)

func (*API) Producers

func (api *API) Producers() ([]map[string]interface{}, error)

func (*API) ValidateEpcho

func (api *API) ValidateEpcho() (interface{}, error)

type ChangeProducer

type ChangeProducer struct {
	Producer string
}

type Config

type Config struct {
	// consensus fileds
	MaxURLLen            uint64   // url length
	UnitStake            *big.Int // state unit
	ProducerMinQuantity  *big.Int // min quantity
	VoterMinQuantity     *big.Int // min quantity
	ActivatedMinQuantity *big.Int // min active quantity
	BlockInterval        uint64
	BlockFrequency       uint64
	ProducerScheduleSize uint64
	DelayEcho            uint64
	AccountName          string
	SystemName           string
	SystemURL            string
	ExtraBlockReward     *big.Int
	BlockReward          *big.Int
	Decimals             uint64
	// contains filtered or unexported fields
}

Config dpos configures

func (*Config) DecodeRLP

func (cfg *Config) DecodeRLP(data []byte) error

DecodeRLP decoding the consensus fields.

func (*Config) EncodeRLP

func (cfg *Config) EncodeRLP() ([]byte, error)

EncodeRLP encoding the consensus fileds.

func (*Config) Read

func (cfg *Config) Read(db fdb.Database, key []byte) error

Read retrieves the consensus settings from the database.

func (*Config) Write

func (cfg *Config) Write(db fdb.Database, key []byte) error

Write writes the dpos config settings to the database.

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

func (dpos *Dpos) Author(header *types.Header) (common.Name, error)

Author implements consensus.Engine, returning the header's coinbase

func (*Dpos) BlockInterval

func (dpos *Dpos) BlockInterval() uint64

BlockInterval block interval

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

func (dpos *Dpos) Config() *Config

Config return dpos config

func (*Dpos) Engine

func (dpos *Dpos) Engine() consensus.IEngine

Engine an engine

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

func (dpos *Dpos) IsFirst(timestamp uint64) bool

func (*Dpos) IsValidateProducer

func (dpos *Dpos) IsValidateProducer(chain consensus.IChainReader, height uint64, timestamp uint64, producer string, pubkeys [][]byte, state *state.StateDB) error

IsValidateProducer current producer

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(chainCfg *params.ChainConfig, state *state.StateDB, action *types.Action) error

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

func (dpos *Dpos) SetConfig(config *Config)

SetConfig set dpos config

func (*Dpos) SetSignFn

func (dpos *Dpos) SetSignFn(signFn SignFn)

SetSignFn set signature function

func (*Dpos) Slot

func (dpos *Dpos) Slot(timestamp uint64) uint64

func (*Dpos) VerifySeal

func (dpos *Dpos) VerifySeal(chain consensus.IChainReader, header *types.Header) error

VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.

type IDB

type IDB interface {
	SetProducer(*producerInfo) error
	DelProducer(string) error
	GetProducer(string) (*producerInfo, error)
	Producers() ([]*producerInfo, error)
	ProducersSize() (uint64, error)

	SetVoter(*voterInfo) error
	DelVoter(string, string) error
	GetVoter(string) (*voterInfo, error)

	SetState(*globalState) error
	DelState(uint64) error
	GetState(uint64) (*globalState, error)

	Delegate(string, *big.Int) error
	Undelegate(string, *big.Int) error
	IncAsset2Acct(string, string, *big.Int) error
}

IDB dpos database

type IDatabase

type IDatabase interface {
	Get(key string) ([]byte, error)
	Put(key string, value []byte) error
	Delete(key string) error

	Delegate(string, *big.Int) error
	Undelegate(string, *big.Int) error
	IncAsset2Acct(string, string, *big.Int) error
}

IDatabase level db

type Irreversible_Ret

type Irreversible_Ret struct {
	ProposedIrreversible uint64
	LastIrreversible     uint64
	BftIrreversible      uint64
}

type LDB

type LDB struct {
	IDatabase
}

LDB dpos level db

func NewLDB

func NewLDB(db IDatabase) (*LDB, error)

func (*LDB) DelProducer

func (db *LDB) DelProducer(name string) error

func (*LDB) DelState

func (db *LDB) DelState(height uint64) error

func (*LDB) DelVoter

func (db *LDB) DelVoter(name string, producer string) error

func (*LDB) GetProducer

func (db *LDB) GetProducer(name string) (*producerInfo, error)

func (*LDB) GetState

func (db *LDB) GetState(height uint64) (*globalState, error)

func (*LDB) GetVoter

func (db *LDB) GetVoter(name string) (*voterInfo, error)

func (*LDB) Producers

func (db *LDB) Producers() ([]*producerInfo, error)

func (*LDB) ProducersSize

func (db *LDB) ProducersSize() (uint64, error)

func (*LDB) SetProducer

func (db *LDB) SetProducer(producer *producerInfo) error

func (*LDB) SetState

func (db *LDB) SetState(gstate *globalState) error

func (*LDB) SetVoter

func (db *LDB) SetVoter(voter *voterInfo) error

type RegisterProducer

type RegisterProducer struct {
	Url   string
	Stake *big.Int
}

type RemoveVoter

type RemoveVoter struct {
	Voter string
}

type SignFn

type SignFn func([]byte, *state.StateDB) ([]byte, error)

SignFn signature function

type System

type System struct {
	IDB
	// contains filtered or unexported fields
}

func (*System) ChangeProducer

func (sys *System) ChangeProducer(voter string, producer string) error

ChangeProducer change a producer

func (*System) RegProducer

func (sys *System) RegProducer(producer string, url string, stake *big.Int) error

RegProducer register a producer

func (*System) UnregProducer

func (sys *System) UnregProducer(producer string) error

UnregProducer unregister a producer

func (*System) UnvoteProducer

func (sys *System) UnvoteProducer(voter string) error

UnvoteProducer cancel vote

func (*System) UnvoteVoter

func (sys *System) UnvoteVoter(producer string, voter string) error

UnvoteVoter cancel voter

func (*System) UpdateProducer

func (sys *System) UpdateProducer(producer string, url string, stake *big.Int) error

UpdateProducer update a producer

func (*System) VoteProducer

func (sys *System) VoteProducer(voter string, producer string, stake *big.Int) error

VoteProducer vote a producer

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 UpdateProducer

type UpdateProducer struct {
	Url   string
	Stake *big.Int
}

type VoteProducer

type VoteProducer struct {
	Producer string
	Stake    *big.Int
}

Jump to

Keyboard shortcuts

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