Documentation ¶
Overview ¶
Package posv implements the Proof-of-Stake Voting consensus engine.
Index ¶
- func CalcReward(cfg *params.PoSVConfig, checkpoint uint64) *big.Int
- func CliqueRLP(header *types.Header) []byte
- func SealHash(header *types.Header) (hash common.Hash)
- type API
- func (api *API) GetEpoch(number *rpc.BlockNumber) ([]byte, error)
- func (api *API) GetSigner(rlpOrBlockNr *blockNumberOrHashOrRLP) (common.Address, error)
- func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error)
- type Epoch
- func (e *Epoch) FromBytes(b []byte) error
- func (e *Epoch) IsM1(address common.Address) bool
- func (e *Epoch) IsM2(address common.Address) bool
- func (e *Epoch) M1(epochLength uint64, number uint64) common.Address
- func (e *Epoch) M1Index(signer common.Address) int
- func (e *Epoch) M1Length() int
- func (e *Epoch) M1NextTurn(epochLength uint64, number uint64, m1 common.Address) uint64
- func (e *Epoch) M1Slice() []common.Address
- func (e *Epoch) M2(epochLength uint64, number uint64) []common.Address
- func (e *Epoch) M2Length() int
- func (e *Epoch) M2Slice() []common.Address
- func (e *Epoch) String() string
- func (e *Epoch) ToBytes() []byte
- type Extra
- type MasterNode
- type MasterNodes
- type PoSV
- func (c *PoSV) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (c *PoSV) Author(header *types.Header) (common.Address, error)
- func (c *PoSV) Authorize(signer common.Address, signFn SignerFn)
- func (c *PoSV) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (c *PoSV) Close() error
- func (c *PoSV) Config() *params.PoSVConfig
- func (c *PoSV) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...)
- func (c *PoSV) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (c *PoSV) GetEpoch(chain consensus.ChainHeaderReader, checkpoint uint64) (*Epoch, error)
- func (c *PoSV) HookBlockSign(signer common.Address, toSign, current *types.Header) error
- func (c *PoSV) HookGetBlockSigners(chain consensus.ChainHeaderReader, stateBlock *state.StateDB, ...) (map[common.Address]int, error)
- func (c *PoSV) HookGetCandidates(state *state.StateDB) MasterNodes
- func (c *PoSV) HookPenalty(chain consensus.ChainHeaderReader, number uint64) ([]common.Address, error)
- func (c *PoSV) HookRandomizeSigners(statedb *state.StateDB, masternodes []common.Address) ([]common.Address, error)
- func (c *PoSV) HookReward(chain consensus.ChainHeaderReader, stateBlock *state.StateDB, ...) (map[string]interface{}, error)
- func (c *PoSV) HookSetRandomizeOpening(signer common.Address, header *types.Header) error
- func (c *PoSV) HookSetRandomizeSecret(signer common.Address, header *types.Header) error
- func (c *PoSV) LastCheckpoint(currentNumber uint64) uint64
- func (c *PoSV) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *PoSV) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (c *PoSV) SealHash(header *types.Header) common.Hash
- func (c *PoSV) SetAccountManager(acm *accounts.Manager)
- func (c *PoSV) SetChainID(chainID *big.Int)
- func (c *PoSV) SetTxPool(txPool *core.TxPool)
- func (c *PoSV) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (c *PoSV) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *PoSV) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type SignerFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcReward ¶ added in v0.2.6
func CalcReward(cfg *params.PoSVConfig, checkpoint uint64) *big.Int
CalcReward return reward of current epoch
func CliqueRLP ¶
CliqueRLP returns the rlp bytes which needs to be signed for the proof-of-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 query the signer and epoch mechanisms of the proof-of-stake voting scheme.
func (*API) GetEpoch ¶ added in v0.2.0
func (api *API) GetEpoch(number *rpc.BlockNumber) ([]byte, error)
func (*API) GetSigner ¶
GetSigner returns the signer for a specific posv block. Can be called with either a blocknumber, blockhash or an rlp encoded blob. The RLP encoded blob can either be a block or a header.
func (*API) GetSigners ¶
GetSigners retrieves the list of authorized signers at the specified block.
type Epoch ¶ added in v0.2.0
type Epoch struct { Checkpoint uint64 `json:"checkpoint"` M1s MasterNodes `json:"m1s"` // max 99 M2s []common.Address `json:"m2s"` // max 150 Reward *big.Int `json:"reward"` Penalties []common.Address `json:"penalties"` }
func (*Epoch) M1NextTurn ¶ added in v0.2.2
M1NextTurn return the next block should be seal by m1
type Extra ¶ added in v0.2.0
type MasterNode ¶ added in v0.2.0
type MasterNodes ¶ added in v0.2.0
type MasterNodes []MasterNode
func (MasterNodes) Len ¶ added in v0.2.0
func (ms MasterNodes) Len() int
func (MasterNodes) Less ¶ added in v0.2.0
func (ms MasterNodes) Less(i, j int) bool
func (MasterNodes) Swap ¶ added in v0.2.0
func (ms MasterNodes) Swap(i, j int)
type PoSV ¶
type PoSV struct {
// contains filtered or unexported fields
}
PoSV is the proof-of-authority 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-authority consensus engine with the initial signers set to the ones provided by the user.
func (*PoSV) APIs ¶
func (c *PoSV) APIs(chain consensus.ChainHeaderReader) []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.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 % SIGNER_COUNT != SIGNER_INDEX * DIFF_INTURN(1) if BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX
func (*PoSV) Close ¶
Close implements consensus.Engine. It's a noop for posv as there are no background threads.
func (*PoSV) Config ¶ added in v0.2.0
func (c *PoSV) Config() *params.PoSVConfig
func (*PoSV) Finalize ¶
func (c *PoSV) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.
func (*PoSV) FinalizeAndAssemble ¶
func (c *PoSV) 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 (*PoSV) GetEpoch ¶ added in v0.2.0
GetEpoch return the epoch data at checkpoint header,the param checkpoint must be checkpoint number
func (*PoSV) HookBlockSign ¶ added in v0.2.0
func (*PoSV) HookGetBlockSigners ¶ added in v0.2.0
func (*PoSV) HookGetCandidates ¶ added in v0.2.6
func (c *PoSV) HookGetCandidates(state *state.StateDB) MasterNodes
HookGetCandidates Read the candidate list and candidate votes from the contract, sort and return according to the rules; sorting rules: the one with the larger votes is first, and the candidate with the smaller address is the first when the votes are the same
func (*PoSV) HookPenalty ¶ added in v0.2.0
func (*PoSV) HookRandomizeSigners ¶ added in v0.2.2
func (*PoSV) HookReward ¶ added in v0.2.0
func (*PoSV) HookSetRandomizeOpening ¶ added in v0.2.0
func (*PoSV) HookSetRandomizeSecret ¶ added in v0.2.0
func (*PoSV) LastCheckpoint ¶ added in v0.2.6
LastCheckpoint return the epoch checkpoint number
func (*PoSV) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*PoSV) Seal ¶
func (c *PoSV) 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 (*PoSV) SetAccountManager ¶ added in v0.2.6
func (*PoSV) SetChainID ¶ added in v0.2.6
func (*PoSV) VerifyHeader ¶
func (c *PoSV) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*PoSV) VerifyHeaders ¶
func (c *PoSV) 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 (*PoSV) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.