@ethereumjs/blockchain / CliqueConsensus
This class encapsulates Clique-related consensus functionality when used with the Blockchain class. Note: reorgs which happen between epoch transitions, which change the internal voting state over the reorg will result in failure and is currently not supported. The hotfix for this could be: re-load the latest epoch block (this has the clique state in the extraData of the header) Now replay all blocks on top of it. This should validate the chain up to the new/reorged tip which previously threw.
• new CliqueConsensus()
• _cliqueLatestBlockSigners: CliqueLatestBlockSigners
= []
List of signers for the last consecutive Blockchain.cliqueSignerLimit blocks. Kept as a snapshot for quickly checking for “recently signed” error. Format: [ [BLOCK_NUMBER, SIGNER_ADDRESS], …]
On reorgs elements from the array are removed until BLOCK_NUMBER > REORG_BLOCK.
• _cliqueLatestSignerStates: CliqueLatestSignerStates
= []
List with the latest signer states checkpointed on blocks where a change (added new or removed a signer) occurred.
Format: [ [BLOCK_NUMBER_1, [SIGNER1, SIGNER 2,]], [BLOCK_NUMBER2, [SIGNER1, SIGNER3]], …]
The top element from the array represents the list of current signers. On reorgs elements from the array are removed until BLOCK_NUMBER > REORG_BLOCK.
Always keep at least one item on the stack.
• _cliqueLatestVotes: CliqueLatestVotes
= []
List with the latest signer votes.
Format: [ [BLOCK_NUMBER_1, [SIGNER, BENEFICIARY, AUTH]], [BLOCK_NUMBER_1, [SIGNER, BENEFICIARY, AUTH]] ] where AUTH = CLIQUE_NONCE_AUTH | CLIQUE_NONCE_DROP
For votes all elements here must be taken into account with a block number >= LAST_EPOCH_BLOCK (nevertheless keep entries with blocks before EPOCH_BLOCK in case a reorg happens during an epoch change)
On reorgs elements from the array are removed until BLOCK_NUMBER > REORG_BLOCK.
• algorithm: ConsensusAlgorithm
• blockchain: undefined
| Blockchain
▸ cliqueActiveSigners(blockNum
): Address
[]
Returns a list with the current block signers
Name | Type |
---|---|
blockNum |
bigint |
Address
[]
▸ cliqueSignerInTurn(signer
, blockNum
): Promise
<boolean
>
Helper to determine if a signer is in or out of turn for the next block.
Name | Type | Description |
---|---|---|
signer |
Address |
The signer address |
blockNum |
bigint |
- |
Promise
<boolean
>
▸ genesisInit(genesisBlock
): Promise
<void
>
Initialize genesis for consensus mechanism
Name | Type | Description |
---|---|---|
genesisBlock |
Block |
genesis block |
Promise
<void
>
▸ newBlock(block
, commonAncestor
): Promise
<void
>
Update consensus on new block
Name | Type | Description |
---|---|---|
block |
Block |
new block |
commonAncestor |
undefined | BlockHeader |
common ancestor block header (optional) |
Promise
<void
>
▸ setup(param
): Promise
<void
>
Name | Type | Description |
---|---|---|
param |
ConsensusOptions |
dictionary containin a Blockchain object Note: this method must be called before consensus checks are used or type errors will occur |
Promise
<void
>
▸ validateConsensus(block
): Promise
<void
>
Validate block consensus parameters
Name | Type | Description |
---|---|---|
block |
Block |
block to be validated |
Promise
<void
>
▸ validateDifficulty(header
): Promise
<void
>
Name | Type |
---|---|
header |
BlockHeader |
Promise
<void
>