Skip to content

Commit

Permalink
address another case for merge just post genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Nov 22, 2022
1 parent 94b8c9d commit 5ae2e16
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { intToHex, isHexPrefixed, stripHexPrefix } from '@ethereumjs/util'

import { Hardfork } from './enums'

type ConfigHardfork = { name: string; block: number }
/**
* Transforms Geth formatted nonce (i.e. hex string) to 8 byte 0x-prefixed string used internally
* @param nonce string parsed from the Geth genesis file
Expand Down Expand Up @@ -116,6 +117,10 @@ function parseGethParams(json: any, mergeForkIdPostMerge: boolean = true) {
}))
.filter((fork) => fork.block !== null && fork.block !== undefined)

// sort with block
params.hardforks.sort(function (a: ConfigHardfork, b: ConfigHardfork) {
return a.block - b.block
})
params.hardforks.unshift({ name: Hardfork.Chainstart, block: 0 })

if (config.terminalTotalDifficulty !== undefined) {
Expand All @@ -125,10 +130,18 @@ function parseGethParams(json: any, mergeForkIdPostMerge: boolean = true) {
block: null,
}

// Merge hardfork has to be placed before first non-zero blockhard fork that is dependent
// on merge, as genesis block can never be a PoS block
// If any of the genesis block require merge, then we need merge just right after genesis
const isMergeJustPostGenesis: boolean = params.hardforks
.filter((hf: ConfigHardfork) => hf.block === 0)
.reduce(
(acc: boolean, hf: ConfigHardfork) => acc || forkMap[hf.name]?.postMerge === true,
false
)

// Merge hardfork has to be placed before first non-zero block hardfork that is dependent
// on merge or first non zero block hardfork if any of genesis hardforks require merge
const postMergeIndex = params.hardforks.findIndex(
(hf: any) => forkMap[hf.name]?.postMerge === true && hf.block > 0
(hf: any) => (isMergeJustPostGenesis || forkMap[hf.name]?.postMerge === true) && hf.block > 0
)
if (postMergeIndex !== -1) {
params.hardforks.splice(postMergeIndex, 0, mergeConfig)
Expand Down

1 comment on commit 5ae2e16

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 5ae2e16 Previous: 161a402 Ratio
Block 9422908 9330 ops/sec (±7.90%) 18760 ops/sec (±1.48%) 2.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.