Documentation ¶
Overview ¶
Package proofofstake implements the proof-of-authority consensus engine.
Index ¶
- Variables
- func ProofOfStakeRLP(header *types.Header) []byte
- func SealHash(header *types.Header) (hash common.Hash)
- type API
- func (api *API) Discard(address common.Address)
- 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)
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) GetValidators() ([]common.Address, error)
- func (api *API) Proposals() map[common.Address]bool
- func (api *API) Propose(address common.Address, auth bool)
- func (api *API) Status() (*status, error)
- type ProofOfStake
- func (c *ProofOfStake) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (c *ProofOfStake) Author(header *types.Header) (common.Address, error)
- func (c *ProofOfStake) Authorize(validator common.Address, signFn SignerFn, signTxFn SignerTxFn)
- func (c *ProofOfStake) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (c *ProofOfStake) Close() error
- func (c *ProofOfStake) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) error
- func (c *ProofOfStake) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (p *ProofOfStake) GetDepositor(validator common.Address, blockHash common.Hash) (common.Address, error)
- func (p *ProofOfStake) GetValidators(number uint64, blockHash common.Hash) ([]common.Address, error)
- func (p *ProofOfStake) GetValidators1(blockHash common.Hash) ([]common.Address, error)
- func (p *ProofOfStake) GetValidatorsAddress1(number uint64, blockHash common.Hash) ([]common.Address, error)
- func (c *ProofOfStake) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *ProofOfStake) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (c *ProofOfStake) SealHash(header *types.Header) common.Hash
- func (c *ProofOfStake) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (c *ProofOfStake) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (c *ProofOfStake) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type SignerFn
- type SignerTxFn
- type Snapshot
- type Tally
- type Vote
Constants ¶
This section is empty.
Variables ¶
var ( FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block ByzantiumBlockReward = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople )
Functions ¶
func ProofOfStakeRLP ¶
ProofOfStakeRLP 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 controlling the signer and voting mechanisms of the proof-of-authority scheme.
func (*API) Discard ¶
Discard drops a currently running proposal, stopping the signer from casting further votes (either for or against).
func (*API) GetSigner ¶
GetSigner returns the signer for a specific proofofstake 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.
func (*API) GetSignersAtHash ¶
GetSignersAtHash retrieves the list of authorized signers at the specified 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.
func (*API) GetValidators ¶
GetValidators retrieves the list of authorized signers at the specified block.
func (*API) Proposals ¶
Proposals returns the current proposals the node tries to uphold and vote on.
type ProofOfStake ¶
type ProofOfStake struct {
// contains filtered or unexported fields
}
ProofOfStake is the proof-of-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.
func New ¶
func New(chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.PublicBlockChainAPI, genesisHash common.Hash) *ProofOfStake
New creates a ProofOfStake proof-of-authority consensus engine with the initial signers set to the ones provided by the user.
func (*ProofOfStake) APIs ¶
func (c *ProofOfStake) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the validator voting.
func (*ProofOfStake) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*ProofOfStake) Authorize ¶
func (c *ProofOfStake) Authorize(validator common.Address, signFn SignerFn, signTxFn SignerTxFn)
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*ProofOfStake) CalcDifficulty ¶
func (c *ProofOfStake) 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 (*ProofOfStake) Close ¶
func (c *ProofOfStake) Close() error
Close implements consensus.Engine. It's a noop for proofofstake as there are no background threads.
func (*ProofOfStake) Finalize ¶
func (c *ProofOfStake) 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 (*ProofOfStake) FinalizeAndAssemble ¶
func (c *ProofOfStake) 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 (*ProofOfStake) GetDepositor ¶
func (*ProofOfStake) GetValidators ¶
func (*ProofOfStake) GetValidators1 ¶
func (*ProofOfStake) GetValidatorsAddress1 ¶
func (*ProofOfStake) Prepare ¶
func (c *ProofOfStake) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*ProofOfStake) Seal ¶
func (c *ProofOfStake) 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 (*ProofOfStake) SealHash ¶
func (c *ProofOfStake) SealHash(header *types.Header) common.Hash
SealHash returns the hash of a block prior to it being sealed.
func (*ProofOfStake) VerifyHeader ¶
func (c *ProofOfStake) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*ProofOfStake) VerifyHeaders ¶
func (c *ProofOfStake) 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 (*ProofOfStake) VerifyUncles ¶
func (c *ProofOfStake) 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.
type SignerTxFn ¶
type SignerTxFn func(accounts.Account, *types.Transaction, *big.Int) (*types.Transaction, error)
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 RecentForkHashes map[uint64]string `json:"recent_fork_hashes"` // Set of recent forkHash Votes []*Vote `json:"votes"` // List of votes cast in chronological order Tally map[common.Address]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.
type Tally ¶
type Tally struct { Authorize bool `json:"authorize"` // Whether the vote is about authorizing or kicking someone Votes int `json:"votes"` // Number of votes until now wanting to pass the proposal }
Tally is a simple vote tally to keep the current score of votes. Votes that go against the proposal aren't counted since it's equivalent to not voting.
type Vote ¶
type Vote struct { Signer common.Address `json:"signer"` // Authorized signer that cast this vote Block uint64 `json:"block"` // Block number the vote was cast in (expire old votes) Address common.Address `json:"address"` // Account being voted on to change its authorization Authorize bool `json:"authorize"` // Whether to authorize or deauthorize the voted account }
Vote represents a single vote that an authorized signer made to modify the list of authorizations.