diff --git a/packages/blockchain/examples/clique.ts b/packages/blockchain/examples/clique.ts index d2a158247e..92a822a03f 100644 --- a/packages/blockchain/examples/clique.ts +++ b/packages/blockchain/examples/clique.ts @@ -6,9 +6,7 @@ const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.London }) const consensusDict: ConsensusDict = {} consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() const blockchain = await createBlockchain({ - consensusDict: { - clique: new CliqueConsensus(), - }, + consensusDict, common, }) console.log(`Created blockchain with ${blockchain.consensus.algorithm} consensus algorithm`) diff --git a/packages/client/src/blockchain/chain.ts b/packages/client/src/blockchain/chain.ts index a2a8dbe50a..b2adafd7b7 100644 --- a/packages/client/src/blockchain/chain.ts +++ b/packages/client/src/blockchain/chain.ts @@ -1,5 +1,5 @@ import { BlockHeader, createBlockFromValuesArray } from '@ethereumjs/block' -import { createBlockchain } from '@ethereumjs/blockchain' +import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain' import { ConsensusAlgorithm, Hardfork } from '@ethereumjs/common' import { BIGINT_0, BIGINT_1, equalsBytes } from '@ethereumjs/util' @@ -8,7 +8,7 @@ import { Event } from '../types.js' import type { Config } from '../config.js' import type { Block } from '@ethereumjs/block' -import type { Blockchain } from '@ethereumjs/blockchain' +import type { Blockchain, ConsensusDict } from '@ethereumjs/blockchain' import type { DB, DBObject, GenesisState } from '@ethereumjs/util' import type { AbstractLevel } from 'abstract-level' @@ -158,7 +158,9 @@ export class Chain { */ public static async create(options: ChainOptions) { let validateConsensus = false + const consensusDict: ConsensusDict = {} if (options.config.chainCommon.consensusAlgorithm() === ConsensusAlgorithm.Clique) { + consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() validateConsensus = true } @@ -170,6 +172,7 @@ export class Chain { hardforkByHeadBlockNumber: true, validateBlocks: true, validateConsensus, + consensusDict, genesisState: options.genesisState, genesisStateRoot: options.genesisStateRoot, })) @@ -448,7 +451,7 @@ export class Chain { td, b.header.timestamp ) - await this.blockchain.consensus.setup({ blockchain: this.blockchain }) + await this.blockchain.consensus?.setup({ blockchain: this.blockchain }) } const block = createBlockFromValuesArray(b.raw(), { diff --git a/packages/client/test/integration/merge.spec.ts b/packages/client/test/integration/merge.spec.ts index 5e07abd0f0..bf0b6734f8 100644 --- a/packages/client/test/integration/merge.spec.ts +++ b/packages/client/test/integration/merge.spec.ts @@ -1,5 +1,5 @@ import { BlockHeader } from '@ethereumjs/block' -import { createBlockchain } from '@ethereumjs/blockchain' +import { CliqueConsensus, EthashConsensus, createBlockchain } from '@ethereumjs/blockchain' import { Chain as ChainCommon, ConsensusAlgorithm, @@ -18,7 +18,7 @@ import { Event } from '../../src/types.js' import { MockServer } from './mocks/mockserver.js' import { destroy, setup } from './util.js' -import type { CliqueConsensus } from '@ethereumjs/blockchain' +import type { ConsensusDict } from '@ethereumjs/blockchain' import type { Common } from '@ethereumjs/common' const commonPoA = createCustomCommon( @@ -74,10 +74,14 @@ const accounts: [Address, Uint8Array][] = [ async function minerSetup(common: Common): Promise<[MockServer, FullEthereumService]> { const config = new Config({ common, accountCache: 10000, storageCache: 1000 }) const server = new MockServer({ config }) as any + const consensusDict: ConsensusDict = {} + consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() + consensusDict[ConsensusAlgorithm.Ethash] = new EthashConsensus() const blockchain = await createBlockchain({ common, validateBlocks: false, validateConsensus: false, + consensusDict, }) ;(blockchain.consensus as CliqueConsensus).cliqueActiveSigners = () => [accounts[0][0]] // stub const serviceConfig = new Config({ diff --git a/packages/client/test/integration/miner.spec.ts b/packages/client/test/integration/miner.spec.ts index 64d7dd98d7..a92685eedf 100644 --- a/packages/client/test/integration/miner.spec.ts +++ b/packages/client/test/integration/miner.spec.ts @@ -1,4 +1,4 @@ -import { createBlockchain } from '@ethereumjs/blockchain' +import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain' import { Chain as ChainCommon, Common, @@ -18,7 +18,7 @@ import { Event } from '../../src/types.js' import { MockServer } from './mocks/mockserver.js' import { destroy, setup } from './util.js' -import type { CliqueConsensus } from '@ethereumjs/blockchain' +import type { ConsensusDict } from '@ethereumjs/blockchain' // Schedule london at 0 and also unset any past scheduled timestamp hardforks that might collide with test const hardforks = new Common({ chain: ChainCommon.Goerli }) @@ -52,10 +52,13 @@ async function minerSetup(): Promise<[MockServer, FullEthereumService]> { const config = new Config({ common, accountCache: 10000, storageCache: 1000 }) const server = new MockServer({ config }) as any + const consensusDict: ConsensusDict = {} + consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() const blockchain = await createBlockchain({ common, validateBlocks: false, validateConsensus: false, + consensusDict, }) ;(blockchain.consensus as CliqueConsensus).cliqueActiveSigners = () => [accounts[0][0]] // stub const chain = await Chain.create({ config, blockchain }) diff --git a/packages/client/test/integration/util.ts b/packages/client/test/integration/util.ts index 16e9cf0e78..7d467505b4 100644 --- a/packages/client/test/integration/util.ts +++ b/packages/client/test/integration/util.ts @@ -1,4 +1,5 @@ -import { createBlockchain } from '@ethereumjs/blockchain' +import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain' +import { type Common, ConsensusAlgorithm } from '@ethereumjs/common' import { MemoryLevel } from 'memory-level' import { Config } from '../../src/config.js' @@ -9,7 +10,7 @@ import { MockChain } from './mocks/mockchain.js' import { MockServer } from './mocks/mockserver.js' import type { SyncMode } from '../../src/config.js' -import type { Common } from '@ethereumjs/common' +import type { ConsensusDict } from '@ethereumjs/blockchain' interface SetupOptions { location?: string @@ -39,9 +40,12 @@ export async function setup( }) const server = new MockServer({ config, location }) as any + const consensusDict: ConsensusDict = {} + consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() const blockchain = await createBlockchain({ validateBlocks: false, validateConsensus: false, + consensusDict, common, })