Skip to content

Commit

Permalink
explicitly check for blockchain.cliqueActiveSigners() in `BlockHead…
Browse files Browse the repository at this point in the history
…er.validateCliqueDifficulty()`
  • Loading branch information
ryanio committed Jan 29, 2021
1 parent 47b36cc commit d58a901
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,20 @@ export class BlockHeader {

/**
* For poa, validates `difficulty` is correctly identified as INTURN or NOTURN.
* Returns false if invalid.
*/
validateCliqueDifficulty(blockchain: Blockchain): boolean {
if (!this.difficulty.eq(CLIQUE_DIFF_INTURN) && !this.difficulty.eq(CLIQUE_DIFF_NOTURN)) {
throw new Error(
`difficulty for clique block must be INTURN (2) or NOTURN (1), received: ${this.difficulty.toString()}`
)
}
const signers = blockchain.cliqueActiveSigners()
if ('cliqueActiveSigners' in blockchain === false) {
throw new Error(
'PoA blockchain requires method blockchain.cliqueActiveSigners() to validate clique difficulty'
)
}
const signers = (blockchain as any).cliqueActiveSigners()
if (signers.length === 0) {
// abort if signers are unavailable
return true
Expand Down
3 changes: 1 addition & 2 deletions packages/block/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, AddressLike, BNLike, BufferLike } from 'ethereumjs-util'
import { AddressLike, BNLike, BufferLike } from 'ethereumjs-util'
import Common from '@ethereumjs/common'
import { TxData, JsonTx } from '@ethereumjs/tx'
import { Block } from './block'
Expand Down Expand Up @@ -135,5 +135,4 @@ export interface JsonHeader {

export interface Blockchain {
getBlock(hash: Buffer): Promise<Block>
cliqueActiveSigners(): Address[]
}

0 comments on commit d58a901

Please sign in to comment.