XDPoS

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package XDPoS implements the proof-of-stake-voting consensus engine.

Index

Constants

View Source
const (
	M2ByteLength = 4
)

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

	ErrInvalidCheckpointValidators = errors.New("invalid validators list on checkpoint block")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

Functions

func ExtractValidatorsFromBytes

func ExtractValidatorsFromBytes(byteValidators []byte) []int64

Extract validators from byte array.

func GetM1M2FromCheckpointHeader

func GetM1M2FromCheckpointHeader(checkpointHeader *types.Header, currentHeader *types.Header, config *params.ChainConfig) (map[common.Address]common.Address, error)

Get m2 list from checkpoint block.

func GetMasternodesFromCheckpointHeader

func GetMasternodesFromCheckpointHeader(checkpointHeader *types.Header) []common.Address

Get masternodes address from checkpoint Header.

func Hop

func Hop(len, pre, cur int) int

func RemovePenaltiesFromBlock

func RemovePenaltiesFromBlock(chain consensus.ChainReader, masternodes []common.Address, epochNumber uint64) []common.Address

Extract validators from byte array.

func SigHash

func SigHash(header *types.Header) (hash common.Hash)

Types

type API

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

API is a user facing RPC API to allow controlling the signer and voting mechanisms of the proof-of-authority scheme.

func (*API) GetSigners

func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block.

func (*API) GetSignersAtHash

func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error)

GetSignersAtHash retrieves the state snapshot at a given block.

func (*API) GetSnapshot

func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

func (*API) Proposals

func (api *API) Proposals() map[common.Address]bool

Proposals returns the current proposals the node tries to uphold and vote on.

type Masternode

type Masternode struct {
	Address common.Address
	Stake   *big.Int
}

type Snapshot

type Snapshot struct {
	Number  uint64                          `json:"number"`  // Block number where the snapshot was created
	Hash    common.Hash                     `json:"hash"`    // Block hash where the snapshot was created
	Signers map[common.Address]struct{}     `json:"signers"` // Set of authorized signers at this moment
	Recents map[uint64]common.Address       `json:"recents"` // Set of recent signers for spam protections
	Votes   []*clique.Vote                  `json:"votes"`   // List of votes cast in chronological order
	Tally   map[common.Address]clique.Tally `json:"tally"`   // Current vote tally to avoid recalculating
	// contains filtered or unexported fields
}

Snapshot is the state of the authorization voting at a given point in time.

func (*Snapshot) GetSigners

func (s *Snapshot) GetSigners() []common.Address

signers retrieves the list of authorized signers in ascending order.

type XDPoS

type XDPoS struct {
	BlockSigners          *lru.Cache
	HookReward            func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) (error, map[string]interface{})
	HookPenalty           func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error)
	HookPenaltyTIPSigning func(chain consensus.ChainReader, header *types.Header, candidate []common.Address) ([]common.Address, error)
	HookValidator         func(header *types.Header, signers []common.Address) ([]byte, error)
	HookVerifyMNs         func(header *types.Header, signers []common.Address) error
	// contains filtered or unexported fields
}

XDPoS is the proof-of-stake-voting consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.

func New

func New(config *params.XDPoSConfig, db ethdb.Database) *XDPoS

New creates a XDPoS proof-of-stake-voting consensus engine with the initial signers set to the ones provided by the user.

func (*XDPoS) APIs

func (c *XDPoS) APIs(chain consensus.ChainReader) []rpc.API

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

func (*XDPoS) Author

func (c *XDPoS) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.

func (*XDPoS) Authorize

func (c *XDPoS) Authorize(signer common.Address, signFn clique.SignerFn)

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

func (*XDPoS) CacheData

func (c *XDPoS) CacheData(header *types.Header, txs []*types.Transaction, receipts []*types.Receipt) []*types.Transaction

func (*XDPoS) CacheSigner

func (c *XDPoS) CacheSigner(hash common.Hash, txs []*types.Transaction) []*types.Transaction

func (*XDPoS) CalcDifficulty

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

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.

func (*XDPoS) Close added in v1.1.0

func (c *XDPoS) Close() error

Close implements consensus.Engine. It's a noop for XDPoS as there are no background threads.

func (*XDPoS) Finalize

func (c *XDPoS) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.

func (*XDPoS) GetDb

func (c *XDPoS) GetDb() ethdb.Database

func (*XDPoS) GetMasternodes

func (c *XDPoS) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address

func (*XDPoS) GetMasternodesFromCheckpointHeader

func (c *XDPoS) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Header, n, e uint64) []common.Address

Get master nodes over extra data of previous checkpoint block.

func (*XDPoS) GetPeriod

func (c *XDPoS) GetPeriod() uint64

func (*XDPoS) GetSnapshot

func (c *XDPoS) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*Snapshot, error)

func (*XDPoS) GetValidator

func (c *XDPoS) GetValidator(creator common.Address, chain consensus.ChainReader, header *types.Header) (common.Address, error)

func (*XDPoS) Prepare

func (c *XDPoS) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*XDPoS) RecoverSigner

func (c *XDPoS) RecoverSigner(header *types.Header) (common.Address, error)

func (*XDPoS) RecoverValidator

func (c *XDPoS) RecoverValidator(header *types.Header) (common.Address, error)

func (*XDPoS) Seal

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

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.

func (*XDPoS) SealHash added in v1.1.0

func (c *XDPoS) SealHash(header *types.Header) common.Hash

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

func (*XDPoS) StoreSnapshot

func (c *XDPoS) StoreSnapshot(snap *Snapshot) error

func (*XDPoS) UpdateMasternodes

func (c *XDPoS) UpdateMasternodes(chain consensus.ChainReader, header *types.Header, ms []Masternode) error

func (*XDPoS) VerifyHeader

func (c *XDPoS) VerifyHeader(chain consensus.ChainReader, header *types.Header, fullVerify bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*XDPoS) VerifyHeaders

func (c *XDPoS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, fullVerifies []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. 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 (*XDPoS) VerifySeal

func (c *XDPoS) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*XDPoS) VerifyUncles

func (c *XDPoS) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.

func (*XDPoS) YourTurn

func (c *XDPoS) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (int, int, int, bool, error)

Jump to

Keyboard shortcuts

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