dpos

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The account wants to be witness and will be considered for block producer
	// by stake delegation
	ElectEnabledFlag uint64 = 1
)

Variables

View Source
var (

	// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
	// the previous block's timestamp + the minimum block period.
	ErrInvalidTimestamp = errors.New("invalid timestamp")

	ErrInvalidDelegateUpdateBlock = errors.New("Delegates updated at wrong block")

	// ErrProductionAborted is returned when the producer is instructed to prepaturely abort
	ErrProductionAborted = errors.New("Production aborted")
)

Functions

func GetDelegates

func GetDelegates(header *types.Header, snap *ebakusdb.Snapshot, maxWitnesses uint64, maxBonusWitnesses uint64, turnBlockCount uint64) vm.WitnessArray

func RLP

func RLP(header *types.Header) []byte

RLP returns the rlp bytes which needs to be signed for the proof-of-authority sealing.

Types

type API

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

API is a user facing RPC API to allow controlling the voting mechanisms of the delegeted proof-of-stake scheme.

func (*API) GetBlockDensity

func (api *API) GetBlockDensity(ctx context.Context, number rpc.BlockNumber, lookbackTime uint64) (map[string]interface{}, error)

func (*API) GetDelegates

func (api *API) GetDelegates(ctx context.Context, number rpc.BlockNumber) ([]interface{}, error)

GetDelegates retrieves the list of delegates at the specified block.

type DPOS

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

DPOS is the delegate proof-of-stake consensus engine

func New

func New(config *params.DPOSConfig, db ethdb.Database, ebakusDb *ebakusdb.DB, genesis *core.Genesis) *DPOS

New creates a Delegated Proof of Stake consensus engine

func (*DPOS) APIs

func (d *DPOS) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the delegate voting etc.

func (*DPOS) AccumulateRewards

func (d *DPOS) AccumulateRewards(config *params.DPOSConfig, state *state.StateDB, header *types.Header, coinbase common.Address)

AccumulateRewards credits the coinbase of the given block with the reward

func (*DPOS) Author

func (d *DPOS) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Ebakus address recovered from the signature in the header

func (*DPOS) Authorize

func (d *DPOS) Authorize(signer common.Address, signFn SignerFn)

Authorize injects a private key into the consensus engine to mint new blocks with.

func (*DPOS) CalcDifficulty

func (d *DPOS) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int

CalcDifficulty is essentialy dummy in ebakus

func (*DPOS) Close

func (d *DPOS) Close() error

Close terminates any background threads maintained by the consensus engine (we don't have any).

func (*DPOS) Finalize

func (d *DPOS) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ebakusState *ebakusdb.Snapshot, coinbase common.Address, txs []*types.Transaction)

Finalize runs any post-transaction state modifications (e.g. block rewards) and assembles the final block. Note: The block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).

func (*DPOS) FinalizeAndAssemble

func (d *DPOS) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ebakusState *ebakusdb.Snapshot, coinbase common.Address, txs []*types.Transaction,
	receipts []*types.Receipt) (*types.Block, error)

FinalizeAndAssemble implements consensus.Engine, accumulating the block and setting the final state and assembling the block.

func (*DPOS) Prepare

func (d *DPOS) Prepare(chain consensus.ChainReader, stop <-chan struct{}) (*types.Block, *types.Header, 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) Seal

func (d *DPOS) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal generates a new block for the given input block with the local miner's seal place on top.

func (*DPOS) SealHash

func (d *DPOS) SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

func (*DPOS) SetBlockchain

func (d *DPOS) SetBlockchain(bc *core.BlockChain)

func (*DPOS) VerifyBlock

func (d *DPOS) VerifyBlock(chain consensus.ChainReader, block *types.Block) error

VerifyBlock verifies that the given block conform to the consensus rules of a given engine.

func (*DPOS) VerifyHeader

func (d *DPOS) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules of a given engine. Verifying the seal may be done optionally here, or explicitly via the VerifySeal method.

func (*DPOS) VerifyHeaders

func (d *DPOS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*DPOS) VerifySeal

func (d *DPOS) VerifySeal(chain consensus.ChainReader, 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 SignerFn

type SignerFn func(accounts.Account, string, []byte) ([]byte, error)

SignerFn is a signer callback function to request a hash to be signed by a backing account.

type State

type State struct {
	BlockNum  uint64
	Hash      common.Hash
	Witnesses map[common.Address]*Witness
	// contains filtered or unexported fields
}

State holds the information for the current delegate sealing procedure at a specific point in time

type Witness

type Witness struct {
	Addr      common.Address
	Flags     uint64
	Stake     *big.Int
	VoteCount uint64
}

type WitnessArray

type WitnessArray []*Witness

func (WitnessArray) Diff

func (WitnessArray) Len

func (s WitnessArray) Len() int

func (WitnessArray) Less

func (s WitnessArray) Less(i, j int) bool

func (WitnessArray) Swap

func (s WitnessArray) Swap(i, j int)

Jump to

Keyboard shortcuts

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