@@ -9,7 +9,7 @@ import * as ropsten from './chains/ropsten.json'
99import * as sepolia from './chains/sepolia.json'
1010import { EIPs } from './eips'
1111import { Chain , CustomChain , Hardfork } from './enums'
12- import { hardforks as HARDFORK_CHANGES } from './hardforks'
12+ import { hardforks as HARDFORK_SPECS } from './hardforks'
1313import { parseGethGenesis } from './utils'
1414
1515import type { ConsensusAlgorithm , ConsensusType } from './enums'
@@ -29,6 +29,8 @@ import type {
2929} from './types'
3030import type { BigIntLike } from '@ethereumjs/util'
3131
32+ type HardforkSpecKeys = keyof typeof HARDFORK_SPECS
33+ type HardforkSpecValues = typeof HARDFORK_SPECS [ HardforkSpecKeys ]
3234/**
3335 * Common class to access chain and hardfork parameters and to provide
3436 * a unified and shared view on the network and hardfork state.
@@ -45,6 +47,8 @@ export class Common extends EventEmitter {
4547 private _eips : number [ ] = [ ]
4648 private _customChains : ChainConfig [ ]
4749
50+ private HARDFORK_CHANGES : [ HardforkSpecKeys , HardforkSpecValues ] [ ]
51+
4852 /**
4953 * Creates a {@link Common} object for a custom chain, based on a standard one.
5054 *
@@ -214,6 +218,11 @@ export class Common extends EventEmitter {
214218 this . _customChains = opts . customChains ?? [ ]
215219 this . _chainParams = this . setChain ( opts . chain )
216220 this . DEFAULT_HARDFORK = this . _chainParams . defaultHardfork ?? Hardfork . Merge
221+ // Assign hardfork changes in the sequence of the applied hardforks
222+ this . HARDFORK_CHANGES = this . hardforks ( ) . map ( ( hf ) => [
223+ hf . name as HardforkSpecKeys ,
224+ HARDFORK_SPECS [ hf . name as HardforkSpecKeys ] ,
225+ ] )
217226 this . _hardfork = this . DEFAULT_HARDFORK
218227 if ( opts . hardfork !== undefined ) {
219228 this . setHardfork ( opts . hardfork )
@@ -262,7 +271,7 @@ export class Common extends EventEmitter {
262271 */
263272 setHardfork ( hardfork : string | Hardfork ) : void {
264273 let existing = false
265- for ( const hfChanges of HARDFORK_CHANGES ) {
274+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
266275 if ( hfChanges [ 0 ] === hardfork ) {
267276 if ( this . _hardfork !== hardfork ) {
268277 this . _hardfork = hardfork
@@ -432,7 +441,7 @@ export class Common extends EventEmitter {
432441 */
433442 paramByHardfork ( topic : string , name : string , hardfork : string | Hardfork ) : bigint {
434443 let value = null
435- for ( const hfChanges of HARDFORK_CHANGES ) {
444+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
436445 // EIP-referencing HF file (e.g. berlin.json)
437446 if ( 'eips' in hfChanges [ 1 ] ) {
438447 const hfEIPs = hfChanges [ 1 ] [ 'eips' ]
@@ -504,7 +513,7 @@ export class Common extends EventEmitter {
504513 if ( this . eips ( ) . includes ( eip ) ) {
505514 return true
506515 }
507- for ( const hfChanges of HARDFORK_CHANGES ) {
516+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
508517 const hf = hfChanges [ 1 ]
509518 if ( this . gteHardfork ( hf [ 'name' ] ) && 'eips' in hf ) {
510519 if ( ( hf [ 'eips' ] as number [ ] ) . includes ( eip ) ) {
@@ -591,7 +600,7 @@ export class Common extends EventEmitter {
591600 * @returns Block number or null if unscheduled
592601 */
593602 eipBlock ( eip : number ) : bigint | null {
594- for ( const hfChanges of HARDFORK_CHANGES ) {
603+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
595604 const hf = hfChanges [ 1 ]
596605 if ( 'eips' in hf ) {
597606 // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
@@ -834,7 +843,7 @@ export class Common extends EventEmitter {
834843 const hardfork = this . hardfork ( )
835844
836845 let value
837- for ( const hfChanges of HARDFORK_CHANGES ) {
846+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
838847 if ( 'consensus' in hfChanges [ 1 ] ) {
839848 value = hfChanges [ 1 ] [ 'consensus' ] [ 'type' ]
840849 }
@@ -856,7 +865,7 @@ export class Common extends EventEmitter {
856865 const hardfork = this . hardfork ( )
857866
858867 let value
859- for ( const hfChanges of HARDFORK_CHANGES ) {
868+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
860869 if ( 'consensus' in hfChanges [ 1 ] ) {
861870 value = hfChanges [ 1 ] [ 'consensus' ] [ 'algorithm' ]
862871 }
@@ -883,7 +892,7 @@ export class Common extends EventEmitter {
883892 const hardfork = this . hardfork ( )
884893
885894 let value
886- for ( const hfChanges of HARDFORK_CHANGES ) {
895+ for ( const hfChanges of this . HARDFORK_CHANGES ) {
887896 if ( 'consensus' in hfChanges [ 1 ] ) {
888897 // The config parameter is named after the respective consensus algorithm
889898 value = hfChanges [ 1 ] [ 'consensus' ] [ hfChanges [ 1 ] [ 'consensus' ] [ 'algorithm' ] ]
0 commit comments