Skip to content

Commit

Permalink
move clique constants to dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Jan 28, 2021
1 parent d9e5558 commit 6cbebb3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
11 changes: 11 additions & 0 deletions packages/block/src/clique.ts
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 10 additions & 7 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions packages/blockchain/src/clique.ts
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6cbebb3

Please sign in to comment.