From 6cbebb3727423cb5ca4242699184168e1c3f1669 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Wed, 27 Jan 2021 15:41:04 -0800 Subject: [PATCH] move clique constants to dedicated file --- packages/block/src/clique.ts | 11 +++++++++++ packages/block/src/header.ts | 17 ++++++++++------- packages/blockchain/src/clique.ts | 11 ++++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 packages/block/src/clique.ts diff --git a/packages/block/src/clique.ts b/packages/block/src/clique.ts new file mode 100644 index 0000000000..5fda0f0caa --- /dev/null +++ b/packages/block/src/clique.ts @@ -0,0 +1,11 @@ +import { BN } from 'ethereumjs-util' + +// Fixed number of extra-data prefix bytes reserved for signer vanity +export const CLIQUE_EXTRA_VANITY = 32 +// Fixed number of extra-data suffix bytes reserved for signer seal +export const CLIQUE_EXTRA_SEAL = 65 + +// Block difficulty for in-turn signatures +export const CLIQUE_DIFF_INTURN = new BN(2) +// Block difficulty for in-turn signatures +export const CLIQUE_DIFF_NOTURN = new BN(1) diff --git a/packages/block/src/header.ts b/packages/block/src/header.ts index b46659ad07..1e75159775 100644 --- a/packages/block/src/header.ts +++ b/packages/block/src/header.ts @@ -14,15 +14,15 @@ import { bufferToInt, } from 'ethereumjs-util' import { HeaderData, JsonHeader, BlockHeaderBuffer, Blockchain, BlockOptions } from './types' +import { + CLIQUE_EXTRA_VANITY, + CLIQUE_EXTRA_SEAL, + CLIQUE_DIFF_INTURN, + CLIQUE_DIFF_NOTURN, +} from './clique' const DEFAULT_GAS_LIMIT = new BN(Buffer.from('ffffffffffffff', 'hex')) -const CLIQUE_EXTRA_VANITY = 32 -const CLIQUE_EXTRA_SEAL = 65 - -const CLIQUE_DIFF_INTURN = new BN(2) -const CLIQUE_DIFF_NOTURN = new BN(1) - /** * An object that represents the block header. */ @@ -562,7 +562,10 @@ export class BlockHeader { } } - /* Hash for PoA clique blocks is created without the seal */ + /** + * Hash for PoA clique blocks is created without the seal. + * @hidden + */ private cliqueHash() { const raw = this.raw() raw[12] = this.extraData.slice(0, this.extraData.length - CLIQUE_EXTRA_SEAL) diff --git a/packages/blockchain/src/clique.ts b/packages/blockchain/src/clique.ts index c701320e59..93c25d01be 100644 --- a/packages/blockchain/src/clique.ts +++ b/packages/blockchain/src/clique.ts @@ -1,13 +1,18 @@ import { Address, BN } from 'ethereumjs-util' -export type CliqueSignerState = [BN, Address[]] // [blockNumber, signers] +// Clique Signer State: [blockNumber, signers] +export type CliqueSignerState = [BN, Address[]] export type CliqueLatestSignerStates = CliqueSignerState[] -export type CliqueVote = [BN, [Address, Address, Buffer]] // [blockNumber, [signer, beneficiary, cliqueNonce]] +// Clique Vote: [blockNumber, [signer, beneficiary, cliqueNonce]] +export type CliqueVote = [BN, [Address, Address, Buffer]] export type CliqueLatestVotes = CliqueVote[] -export type CliqueBlockSigner = [BN, Address] // [blockNumber, signer] +// Clique Block Signer: [blockNumber, signer] +export type CliqueBlockSigner = [BN, Address] export type CliqueLatestBlockSigners = CliqueBlockSigner[] +// Magic nonce number to vote on adding a new signer export const CLIQUE_NONCE_AUTH = Buffer.from('ffffffffffffffff', 'hex') +// Magic nonce number to vote on removing a signer. export const CLIQUE_NONCE_DROP = Buffer.alloc(8)