Documentation ¶
Overview ¶
Package posa implements the proof-of-stake-authority consensus engine.
Index ¶
- Variables
- func POSARLP(header *types.Header) []byte
- func SealHash(header *types.Header) (hash common.Hash)
- type API
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)
- func (api *API) Status() (*status, error)
- type POSA
- func (c *POSA) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (c *POSA) Author(header *types.Header) (common.Address, error)
- func (c *POSA) Authorize(validator common.Address, signFn ValidatorFn)
- func (c *POSA) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (c *POSA) Close() error
- func (c *POSA) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) error
- func (c *POSA) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (c *POSA) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *POSA) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (c *POSA) SealHash(header *types.Header) common.Hash
- func (c *POSA) SetStateFn(fn StateFn)
- func (c *POSA) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (c *POSA) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *POSA) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *POSA) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Snapshot
- type StateFn
- type ValidatorFn
Constants ¶
This section is empty.
Variables ¶
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") )
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 POSARLP ¶
POSARLP returns the rlp bytes which needs to be signed for the proof-of-stake-authority sealing. The RLP to sign consists of the entire header apart from the 65 byte signature contained at the end of the extra data.
Note, the method requires the extra data to be at least 65 bytes, otherwise it panics. This is done to avoid accidentally using both forms (signature present or not), which could be abused to produce different hashes for the same header.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a user facing RPC API to allow controlling the validator and voting mechanisms of the proof-of-authority scheme.
func (*API) GetSnapshot ¶
func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
GetSnapshot retrieves the state snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
func (*API) GetValidators ¶
GetValidators retrieves the list of authorized validators at the specified block.
func (*API) GetValidatorsAtHash ¶
GetValidatorsAtHash retrieves the list of authorized validators at the specified block.
type POSA ¶
type POSA struct {
// contains filtered or unexported fields
}
The proof-of-stake-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.
func New ¶
func New(chainConfig *params.ChainConfig, db ethdb.Database) *POSA
New creates a proof-of-stake-authority consensus engine with the initial validators set to the ones provided by the user.
func (*POSA) APIs ¶
func (c *POSA) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the validator voting.
func (*POSA) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*POSA) Authorize ¶
func (c *POSA) Authorize(validator common.Address, signFn ValidatorFn)
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*POSA) CalcDifficulty ¶
func (c *POSA) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have: * DIFF_NOTURN(2) if BLOCK_NUMBER % validator_COUNT != validator_INDEX * DIFF_INTURN(1) if BLOCK_NUMBER % validator_COUNT == validator_INDEX
func (*POSA) Close ¶
Close implements consensus.Engine. It's a noop for POSA as there are no background threads.
func (*POSA) Finalize ¶
func (c *POSA) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) error
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.
func (*POSA) FinalizeAndAssemble ¶
func (c *POSA) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*POSA) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*POSA) Seal ¶
func (c *POSA) Seal(chain consensus.ChainHeaderReader, 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 (*POSA) SetStateFn ¶
SetStateFn sets the function to get state.
func (*POSA) VerifyHeader ¶
func (c *POSA) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*POSA) VerifyHeaders ¶
func (c *POSA) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []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 (*POSA) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*POSA) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
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 Validators map[common.Address]struct{} `json:"validators"` // Set of authorized validators at this moment Recents map[uint64]common.Address `json:"recents"` // Set of recent validators for spam protections // contains filtered or unexported fields }
Snapshot is the state of the authorization voting at a given point in time.