Documentation ¶
Overview ¶
Package posv implements the proof-of-stake-voting consensus engine.
Index ¶
- Variables
- func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int
- func YourTurn(masternodes []common.Address, snap *Snapshot, header *types.Header, ...) (int, int, bool, error)
- type API
- func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error)
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) Proposals() map[common.Address]bool
- type Masternode
- type Posv
- func (c *Posv) APIs(chain consensus.ChainReader) []rpc.API
- func (c *Posv) Author(header *types.Header) (common.Address, error)
- func (c *Posv) Authorize(signer common.Address, signFn clique.SignerFn)
- func (c *Posv) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (c *Posv) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address
- func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Header, n, e uint64) []common.Address
- func (c *Posv) GetPeriod() uint64
- func (c *Posv) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*Snapshot, error)
- func (c *Posv) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (c *Posv) RecoverSigner(header *types.Header) (common.Address, error)
- func (c *Posv) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (c *Posv) StoreSnapshot(snap *Snapshot) error
- func (c *Posv) UpdateMasternodes(chain consensus.ChainReader, header *types.Header, ms []Masternode) error
- func (c *Posv) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (c *Posv) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *Posv) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (c *Posv) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Snapshot
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 CalcDifficulty ¶
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.
Types ¶
type API ¶
type API struct {
// 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 ¶
GetSigners retrieves the list of authorized signers at the specified block.
func (*API) GetSignersAtHash ¶
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 ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
type Masternode ¶
type Posv ¶
type Posv struct { HookReward func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error // contains filtered or unexported fields }
Posv is the proof-of-stake-voting consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.
func New ¶
func New(config *params.PosvConfig, db ethdb.Database) *Posv
New creates a Posv proof-of-stake-voting consensus engine with the initial signers set to the ones provided by the user.
func (*Posv) APIs ¶
func (c *Posv) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*Posv) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*Posv) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Posv) CalcDifficulty ¶
func (c *Posv) 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 (*Posv) Finalize ¶
func (c *Posv) 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 (*Posv) GetMasternodes ¶
func (*Posv) GetMasternodesFromCheckpointHeader ¶
func (c *Posv) GetMasternodesFromCheckpointHeader(preCheckpointHeader *types.Header, n, e uint64) []common.Address
Get master nodes over extra data of previous checkpoint block.
func (*Posv) GetSnapshot ¶
func (*Posv) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Posv) RecoverSigner ¶
func (*Posv) Seal ¶
func (c *Posv) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Posv) StoreSnapshot ¶
func (*Posv) UpdateMasternodes ¶
func (c *Posv) UpdateMasternodes(chain consensus.ChainReader, header *types.Header, ms []Masternode) error
func (*Posv) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Posv) VerifyHeaders ¶
func (c *Posv) VerifyHeaders(chain consensus.ChainReader, 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 (*Posv) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Posv) 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 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.