Skip to content

Commit

Permalink
Client fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Jul 16, 2024
1 parent 9052933 commit e5c0c0c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
4 changes: 1 addition & 3 deletions packages/blockchain/examples/clique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
9 changes: 6 additions & 3 deletions packages/client/src/blockchain/chain.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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'

Expand Down Expand Up @@ -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
}

Expand All @@ -170,6 +172,7 @@ export class Chain {
hardforkByHeadBlockNumber: true,
validateBlocks: true,
validateConsensus,
consensusDict,
genesisState: options.genesisState,
genesisStateRoot: options.genesisStateRoot,
}))
Expand Down Expand Up @@ -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(), {
Expand Down
8 changes: 6 additions & 2 deletions packages/client/test/integration/merge.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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({
Expand Down
7 changes: 5 additions & 2 deletions packages/client/test/integration/miner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockchain } from '@ethereumjs/blockchain'
import { CliqueConsensus, createBlockchain } from '@ethereumjs/blockchain'
import {
Chain as ChainCommon,
Common,
Expand All @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down
8 changes: 6 additions & 2 deletions packages/client/test/integration/util.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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,
})

Expand Down

0 comments on commit e5c0c0c

Please sign in to comment.