clique

package
v3.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2019 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package clique implements the proof-of-authority consensus engine.

Index

Constants

This section is empty.

Variables

View Source
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")

	// ErrIneligibleSigner is returned if a signer is authorized to sign, but not
	// eligible to sign this block. It has either signed too recently, or the chain
	// has just started and it is not yet its turn.
	ErrIneligibleSigner = errors.New("signer is not eligible to sign this block")
)

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.

View Source
var BlockReward = big.NewInt(7e+18)

Block reward in wei for successfully sealing a block.

Functions

func CalcDifficulty

func CalcDifficulty(lastSigned map[common.Address]uint64, signer common.Address) uint64

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 CliqueRLP added in v3.1.7

func CliqueRLP(header *types.Header) []byte

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.

func ExtraAppendVote

func ExtraAppendVote(extra []byte, candidate common.Address, voter bool) []byte

ExtraAppendVote appends a vote to extra data as 20 bytes of address and a single byte for voter or signer election.

func ExtraCandidate

func ExtraCandidate(extra []byte) common.Address

ExtraCandidate returns the candidate address of the proposal vote, or the zero value if one is not present.

func ExtraEnsureVanity

func ExtraEnsureVanity(extra []byte) []byte

ExtraEnsureVanity returns a slice of length 32, trimming extra or filling with 0s as necessary.

func ExtraHasVote

func ExtraHasVote(extra []byte) bool

ExtraHasVote returns true if extra contains a proposal vote.

func ExtraIsVoterElection

func ExtraIsVoterElection(extra []byte) bool

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

func ExtraVanity(extra []byte) []byte

ExtraVanity returns a slice of the vanity portion of extra (up to 32). It may still contain trailing 0s.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) consensus.Engine

NewFaker returns a new fake consensus.Engine which sleeps for delay during header verification.

func NewFakeFailer

func NewFakeFailer(fail uint64) consensus.Engine

NewFakeFailer returns a new fake consensus.Engine which fails header verification at the given block.

func NewFaker

func NewFaker() consensus.Engine

NewFaker returns a new fake consensus.Engine.

func NewFullFaker

func NewFullFaker() consensus.Engine

NewFullFaker returns a new fake consensus.Engine which skips header verification entirely.

func SealHash added in v3.1.7

func SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

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

func (api *API) Discard(address common.Address)

Discard drops a currently running proposal, stopping the signer from casting further votes (either for or against).

func (*API) GetSigners

func (api *API) GetSigners(ctx context.Context, number *rpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block.

func (*API) GetSignersAtHash

func (api *API) GetSignersAtHash(ctx context.Context, hash common.Hash) ([]common.Address, error)

GetSignersAtHash retrieves the state snapshot at a given block.

func (*API) GetSnapshot

func (api *API) GetSnapshot(ctx context.Context, number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

func (api *API) GetSnapshotAtHash(ctx context.Context, hash common.Hash) (*Snapshot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

func (*API) GetVoters

func (api *API) GetVoters(ctx context.Context, number *rpc.BlockNumber) ([]common.Address, error)

GetVoters retrieves the list of authorized voters at the specified block.

func (*API) Proposals

func (api *API) Proposals() map[common.Address]propose

Proposals returns the current proposals the node tries to uphold and vote on.

func (*API) Propose

func (api *API) Propose(address common.Address, auth bool)

Propose injects a new authorization proposal that the signer will attempt to push through.

func (*API) ProposeVoter

func (api *API) ProposeVoter(address common.Address, auth bool)

Propose injects a new authorization proposal that the signer will attempt to push through.

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

func (c *Clique) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the address recovered from the signature in the header's extra-data section.

func (*Clique) Authorize

func (c *Clique) Authorize(signer common.Address, signFn consensus.SignerFn)

func (*Clique) Finalize

func (c *Clique) Finalize(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(chain consensus.ChainReader, header *types.Header) 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(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, *time.Time, error)

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.

func (*Clique) SealHash

func (c *Clique) SealHash(header *types.Header) common.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*Clique) VerifyHeader

func (c *Clique) VerifyHeader(chain consensus.ChainReader, header *types.Header) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Clique) VerifyHeaders

func (c *Clique) VerifyHeaders(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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL