Documentation ¶
Overview ¶
Package clique implements the proof-of-authority consensus engine.
Index ¶
- Variables
- func CalcDifficulty(lastSigned map[common.Address]uint64, signer common.Address) uint64
- func ExtraAppendVote(extra []byte, candidate common.Address, voter bool) []byte
- func ExtraCandidate(extra []byte) common.Address
- func ExtraEnsureVanity(extra []byte) []byte
- func ExtraHasVote(extra []byte) bool
- func ExtraIsVoterElection(extra []byte) bool
- func ExtraVanity(extra []byte) []byte
- func NewFakeDelayer(delay time.Duration) consensus.Engine
- func NewFakeFailer(fail uint64) consensus.Engine
- func NewFaker() consensus.Engine
- func NewFullFaker() consensus.Engine
- type API
- func (api *API) Discard(address common.Address)
- func (api *API) GetSigners(ctx context.Context, number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetSignersAtHash(ctx context.Context, hash common.Hash) ([]common.Address, error)
- func (api *API) GetSnapshot(ctx context.Context, number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(ctx context.Context, hash common.Hash) (*Snapshot, error)
- func (api *API) GetVoters(ctx context.Context, number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) Proposals() map[common.Address]propose
- func (api *API) Propose(address common.Address, auth bool)
- func (api *API) ProposeVoter(address common.Address, auth bool)
- type Clique
- func (c *Clique) APIs(chain consensus.ChainReader) []rpc.API
- func (c *Clique) Author(ctx context.Context, header *types.Header) (common.Address, error)
- func (c *Clique) Authorize(signer common.Address, signFn consensus.SignerFn)
- func (c *Clique) Finalize(ctx context.Context, chain consensus.ChainReader, header *types.Header, ...) *types.Block
- func (c *Clique) Prepare(ctx context.Context, chain consensus.ChainReader, header *types.Header) (*time.Time, error)
- func (c *Clique) Seal(ctx context.Context, chain consensus.ChainReader, block *types.Block, ...) (*types.Block, error)
- func (c *Clique) VerifyHeader(ctx context.Context, chain consensus.ChainReader, header *types.Header) error
- func (c *Clique) VerifyHeaders(ctx context.Context, chain consensus.ChainReader, headers []*types.Header) (chan<- struct{}, <-chan error)
- type Snapshot
- type Tally
- type Vote
Constants ¶
This section is empty.
Variables ¶
var BlockReward = big.NewInt(7e+18)
Block reward in wei for successfully sealing a block.
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 returns the difficulty for signer, given all signers and their most recently signed block numbers, with 0 meaning 'has not signed'. With n signers, it will always return values from n/2+1 to n, inclusive, or 0.
Difficulty for ineligible signers (too recent) is always 0. For eligible signers, difficulty is defined as 1 plus the number of lower priority signers, with more recent signers have lower priority. If multiple signers have not yet signed (0), then addresses which lexicographically sort later have lower priority.
func ExtraAppendVote ¶
ExtraAppendVote appends a vote to extra data as 20 bytes of address and a single byte for voter or signer election.
func ExtraCandidate ¶
ExtraCandidate returns the candidate address of the proposal vote, or the zero value if one is not present.
func ExtraEnsureVanity ¶
ExtraEnsureVanity returns a slice of length 32, trimming extra or filling with 0s as necessary.
func ExtraHasVote ¶
ExtraHasVote returns true if extra contains a proposal vote.
func ExtraIsVoterElection ¶
IsVoterElection returns true if extra votes on a voter election, or false if it votes on a signer election or does not contain a vote.
func ExtraVanity ¶
ExtraVanity returns a slice of the vanity portion of extra (up to 32). It may still contain trailing 0s.
func NewFakeDelayer ¶
NewFaker returns a new fake consensus.Engine which sleeps for delay during header verification.
func NewFakeFailer ¶
NewFakeFailer returns a new fake consensus.Engine which fails header verification at the given block.
func NewFullFaker ¶
NewFullFaker returns a new fake consensus.Engine which skips header verification entirely.
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) 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 ¶
GetSnapshot retrieves the state snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
func (*API) Proposals ¶
Proposals returns the current proposals the node tries to uphold and vote on.
type Clique ¶
type Clique struct {
// contains filtered or unexported fields
}
Clique is the proof-of-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.
func New ¶
func New(config *params.CliqueConfig, db common.Database) *Clique
New creates a Clique proof-of-authority consensus engine with the initial signers set to the ones provided by the user.
func (*Clique) APIs ¶
func (c *Clique) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.
func (*Clique) Author ¶
Author implements consensus.Engine, returning the address recovered from the signature in the header's extra-data section.
func (*Clique) Finalize ¶
func (c *Clique) Finalize(ctx context.Context, chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt, block bool) *types.Block
Finalize implements consensus.Engine, ensuring no uncles are set, but this does give rewards.
func (*Clique) Prepare ¶
func (c *Clique) Prepare(ctx context.Context, chain consensus.ChainReader, header *types.Header) (*time.Time, error)
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Clique) Seal ¶
func (c *Clique) Seal(ctx context.Context, 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 (*Clique) VerifyHeader ¶
func (c *Clique) VerifyHeader(ctx context.Context, chain consensus.ChainReader, header *types.Header) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Clique) VerifyHeaders ¶
func (c *Clique) VerifyHeaders(ctx context.Context, chain consensus.ChainReader, headers []*types.Header) (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).
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]uint64 `json:"signers"` // Each authorized signer at this moment and their most recently signed block Voters map[common.Address]struct{} `json:"voters"` // Set of authorized voters at this moment 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.