Documentation ¶
Overview ¶
Package clique implements the proof-of-authority consensus engine.
Index ¶
- Constants
- Variables
- func CliqueRLP(header *types.Header) []byte
- func EncodeBlockNumber(number uint64) []byte
- func LastSnapshotKey() []byte
- func NewCliqueAPI(db kv.RoDB, engine consensus.EngineReader, ...) rpc.API
- func SealHash(header *types.Header) (hash libcommon.Hash)
- func SnapshotFullKey(number uint64, hash libcommon.Hash) []byte
- func SnapshotKey(number uint64) []byte
- type API
- func (api *API) Discard(address libcommon.Address)
- func (api *API) GetSigners(ctx context.Context, number *rpc.BlockNumber) ([]libcommon.Address, error)
- func (api *API) GetSignersAtHash(ctx context.Context, hash libcommon.Hash) ([]libcommon.Address, error)
- func (api *API) GetSnapshot(ctx context.Context, number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(ctx context.Context, hash libcommon.Hash) (*Snapshot, error)
- func (api *API) Proposals() map[libcommon.Address]bool
- func (api *API) Propose(address libcommon.Address, auth bool)
- func (api *API) Status(ctx context.Context) (*status, error)
- type Clique
- func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (c *Clique) Author(header *types.Header) (libcommon.Address, error)
- func (c *Clique) Authorize(signer libcommon.Address, signFn SignerFn)
- func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, _, _ uint64, _ *big.Int, ...) *big.Int
- func (c *Clique) CalculateRewards(config *chain.Config, header *types.Header, uncles []*types.Header, ...) ([]consensus.Reward, error)
- func (c *Clique) Close() error
- func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, ...) (types.Transactions, types.Receipts, types.FlatRequests, error)
- func (c *Clique) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState, ...) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error)
- func (c *Clique) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc
- func (c *Clique) GetTransferFunc() evmtypes.TransferFunc
- func (c *Clique) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header, ...)
- func (c *Clique) IsServiceTransaction(sender libcommon.Address, syscall consensus.SystemCall) bool
- func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header, ...) error
- func (c *Clique) Seal(chain consensus.ChainHeaderReader, blockWithReceipts *types.BlockWithReceipts, ...) error
- func (c *Clique) SealHash(header *types.Header) libcommon.Hash
- func (c *Clique) Snapshot(chain consensus.ChainHeaderReader, number uint64, hash libcommon.Hash, ...) (*Snapshot, error)
- func (c *Clique) Type() chain.ConsensusName
- func (c *Clique) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, _ bool) error
- func (c *Clique) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error
- func (c *Clique) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
- type SignerFn
- type SignersAscending
- type Snapshot
- type Tally
- type VerifyHeaderResponse
- type Vote
Constants ¶
const ( ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity ExtraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal )
const NumberLength = 8
Variables ¶
var ( NonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer DiffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures )
Clique proof-of-authority protocol constants.
var ( errors.New("unauthorized signer") // ErrRecentlySigned is returned if a header is signed by an authorized entity // that already signed a header recently, thus is temporarily not allowed to. ErrRecentlySigned = errors.New("recently signed") )ErrUnauthorizedSigner =
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.
var ErrNotFound = errors.New("not found")
Functions ¶
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.
func EncodeBlockNumber ¶
EncodeBlockNumber encodes a block number as big endian uint64
func NewCliqueAPI ¶
func NewCliqueAPI(db kv.RoDB, engine consensus.EngineReader, blockReader services.FullBlockReader) rpc.API
func SnapshotFullKey ¶
SnapshotFullKey = SnapshotBucket + num (uint64 big endian) + hash
func SnapshotKey ¶
SnapshotKey = SnapshotBucket + num (uint64 big endian)
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 ¶
func (api *API) GetSigners(ctx context.Context, number *rpc.BlockNumber) ([]libcommon.Address, error)
GetSigners retrieves the list of authorized signers at the specified block.
func (*API) GetSignersAtHash ¶
func (api *API) GetSignersAtHash(ctx context.Context, hash libcommon.Hash) ([]libcommon.Address, error)
GetSignersAtHash retrieves the list of authorized signers at the specified 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 { ChainConfig *chain.Config DB kv.RwDB // Database to store and retrieve snapshot checkpoints // The fields below are for testing only FakeDiff bool // Skip difficulty verifications // 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(cfg *chain.Config, snapshotConfig *params.ConsensusSnapshotConfig, cliqueDB kv.RwDB, logger log.Logger) *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.ChainHeaderReader) []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 Ethereum address recovered from the signature in the header's extra-data section. This is thread-safe (only access the header, as well as signatures, which are lru.ARCCache, which is thread-safe)
func (*Clique) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Clique) CalcDifficulty ¶
func (c *Clique) CalcDifficulty(chain consensus.ChainHeaderReader, _, _ uint64, _ *big.Int, parentNumber uint64, parentHash, _ libcommon.Hash, _ uint64) *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 (*Clique) CalculateRewards ¶
func (*Clique) Close ¶
Close implements consensus.Engine. It's a noop for clique as there are no background threads.
func (*Clique) Finalize ¶
func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger, ) (types.Transactions, types.Receipts, types.FlatRequests, error)
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.
func (*Clique) FinalizeAndAssemble ¶
func (c *Clique) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger, ) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error)
FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*Clique) GetPostApplyMessageFunc ¶
func (c *Clique) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc
func (*Clique) GetTransferFunc ¶
func (c *Clique) GetTransferFunc() evmtypes.TransferFunc
func (*Clique) Initialize ¶
func (c *Clique) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header, state *state.IntraBlockState, syscall consensus.SysCallCustom, logger log.Logger, tracer *tracing.Hooks)
func (*Clique) IsServiceTransaction ¶
func (*Clique) Prepare ¶
func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header, state *state.IntraBlockState) 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.ChainHeaderReader, blockWithReceipts *types.BlockWithReceipts, results chan<- *types.BlockWithReceipts, stop <-chan struct{}) error
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Clique) Type ¶
func (c *Clique) Type() chain.ConsensusName
Type returns underlying consensus engine
func (*Clique) VerifyHeader ¶
func (c *Clique) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, _ bool) error
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Clique) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Clique) VerifyUncles ¶
func (c *Clique) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
type SignersAscending ¶
SignersAscending implements the sort interface to allow sorting a list of addresses
func (SignersAscending) Len ¶
func (s SignersAscending) Len() int
func (SignersAscending) Less ¶
func (s SignersAscending) Less(i, j int) bool
func (SignersAscending) Swap ¶
func (s SignersAscending) Swap(i, j int)
type Snapshot ¶
type Snapshot struct { Number uint64 `json:"number"` // Block number where the snapshot was created Hash libcommon.Hash `json:"hash"` // Block hash where the snapshot was created Signers map[libcommon.Address]struct{} `json:"signers"` // Set of authorized signers at this moment Recents map[uint64]libcommon.Address `json:"recents"` // Set of recent signers for spam protections Votes []*Vote `json:"votes"` // List of votes cast in chronological order Tally map[libcommon.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.
func (*Snapshot) GetSigners ¶
signers retrieves the list of authorized signers in ascending order.
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 VerifyHeaderResponse ¶
type VerifyHeaderResponse struct { Results chan error Cancel func() }
type Vote ¶
type Vote struct { Signer libcommon.Address `json:"signer"` // Authorized signer that cast this vote Block uint64 `json:"block"` // Block number the vote was cast in (expire old votes) Address libcommon.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.