Skip to content

Commit

Permalink
handle clique consensus validation at correct point
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Aug 13, 2024
1 parent fe00092 commit 07342f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions packages/block/src/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ export function createSealedCliqueBlock(
cliqueSigner: Uint8Array,
opts: BlockOptions = {},
): Block {
const sealedCliqueBlock = createBlock(blockData, { ...opts, ...{ freeze: false } })
const sealedCliqueBlock = createBlock(blockData, {
...opts,
...{ freeze: false, skipConsensusFormatValidation: true },
})
;(sealedCliqueBlock.header.extraData as any) = retrieveCliqueBlockExtraData(
sealedCliqueBlock.header,
cliqueSigner,
Expand All @@ -531,6 +534,10 @@ export function createSealedCliqueBlock(
// We have to freeze here since we can't freeze the block when constructing it since we are overwriting `extraData`
Object.freeze(sealedCliqueBlock)
}
if (opts?.skipConsensusFormatValidation === false) {
// We need to validate the consensus format here since we skipped it when constructing the block
sealedCliqueBlock.header['_consensusFormatValidation']()
}
return sealedCliqueBlock
}

Expand All @@ -539,11 +546,16 @@ export function createSealedCliqueBlockHeader(
cliqueSigner: Uint8Array,
opts: BlockOptions = {},
): BlockHeader {
const sealedCliqueBlockHeader = new BlockHeader(headerData, opts)
const sealedCliqueBlockHeader = new BlockHeader(headerData, {
...opts,
...{ skipConsensusFormatValidation: true },
})
;(sealedCliqueBlockHeader.extraData as any) = retrieveCliqueBlockExtraData(
sealedCliqueBlockHeader,
cliqueSigner,
)

if (opts.skipConsensusFormatValidation === false)
// We need to validate the consensus format here since we skipped it when constructing the block header
sealedCliqueBlockHeader['_consensusFormatValidation']()
return sealedCliqueBlockHeader
}
6 changes: 4 additions & 2 deletions packages/vm/src/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
genTransactionsTrieRoot,
genWithdrawalsTrieRoot,
} from '@ethereumjs/block'
import { ConsensusType, Hardfork } from '@ethereumjs/common'
import { ConsensusAlgorithm, ConsensusType, Hardfork } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { Trie } from '@ethereumjs/trie'
import { BlobEIP4844Transaction, createMinimal4844TxFromNetworkWrapper } from '@ethereumjs/tx'
Expand Down Expand Up @@ -366,7 +366,9 @@ export class BlockBuilder {

let block
const cs = this.blockOpts.cliqueSigner
if (cs !== undefined) {
if (this.blockOpts.common?.consensusAlgorithm() === ConsensusAlgorithm.Clique) {
if (cs === undefined)
throw new Error('cliqueSigner required for building blocks under PoA consensus')
block = createSealedCliqueBlock(blockData, cs, this.blockOpts)
} else {
block = createBlock(blockData, blockOpts)
Expand Down

0 comments on commit 07342f8

Please sign in to comment.