Skip to content

Commit 2a85fa7

Browse files
committed
common -> custom chains: moved default hardfork to be a parameter in the chain json files (all set to istanbul for backwards compatibility)
1 parent 0614e2e commit 2a85fa7

File tree

10 files changed

+15
-5
lines changed

10 files changed

+15
-5
lines changed

packages/common/src/chains/goerli.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "goerli",
33
"chainId": 5,
44
"networkId": 5,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "poa",
78
"algorithm": "clique"

packages/common/src/chains/kovan.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "kovan",
33
"chainId": 42,
44
"networkId": 42,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "poa",
78
"algorithm": "aura"

packages/common/src/chains/mainnet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "mainnet",
33
"chainId": 1,
44
"networkId": 1,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "pow",
78
"algorithm": "ethash"

packages/common/src/chains/rinkeby.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "rinkeby",
33
"chainId": 4,
44
"networkId": 4,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "poa",
78
"algorithm": "clique"

packages/common/src/chains/ropsten.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "ropsten",
33
"chainId": 3,
44
"networkId": 3,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "pow",
78
"algorithm": "ethash"

packages/common/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { buf as crc32Buffer } from 'crc-32'
22
import { _getInitializedChains } from './chains'
33
import { hardforks as HARDFORK_CHANGES } from './hardforks'
44
import { EIPs } from './eips'
5-
import { BootstrapNode, Chain, GenesisBlock, Hardfork } from './types'
5+
import { Chain } from './types'
66

77
/**
88
* Options for instantiating a [[Common]] instance.
@@ -57,7 +57,7 @@ interface hardforkOptions {
5757
* Common class to access chain and hardfork parameters
5858
*/
5959
export default class Common {
60-
readonly DEFAULT_HARDFORK: string = 'istanbul'
60+
readonly DEFAULT_HARDFORK: string
6161

6262
private _chainParams: Chain
6363
private _hardfork: string
@@ -117,6 +117,7 @@ export default class Common {
117117
constructor(opts: CommonOpts) {
118118
this._customChains = opts.customChains ?? []
119119
this._chainParams = this.setChain(opts.chain)
120+
this.DEFAULT_HARDFORK = this._chainParams.defaultHardfork
120121
this._hardfork = this.DEFAULT_HARDFORK
121122
if (opts.supportedHardforks) {
122123
this._supportedHardforks = opts.supportedHardforks
@@ -513,7 +514,7 @@ export default class Common {
513514
// Logic: if accumulator is still null and on the first occurence of
514515
// a block greater than the current hfBlock set the accumulator,
515516
// pass on the accumulator as the final result from this time on
516-
const nextHfBlock = (this.hardforks() as any).reduce((acc: number, hf: any) => {
517+
const nextHfBlock = this.hardforks().reduce((acc: number, hf: any) => {
517518
return hf.block > hfBlock && acc === null ? hf.block : acc
518519
}, null)
519520
return nextHfBlock
@@ -539,7 +540,7 @@ export default class Common {
539540
const genesis = Buffer.from(this.genesis().hash.substr(2), 'hex')
540541

541542
let hfBuffer = Buffer.alloc(0)
542-
let prevBlock: number | null = 0
543+
let prevBlock = 0
543544
for (const hf of this.hardforks()) {
544545
const block = hf.block
545546

@@ -565,7 +566,7 @@ export default class Common {
565566
* Returns an eth/64 compliant fork hash (EIP-2124)
566567
* @param hardfork Hardfork name, optional if HF set
567568
*/
568-
forkHash(hardfork?: string): string | null {
569+
forkHash(hardfork?: string) {
569570
hardfork = this._chooseHardfork(hardfork, false)
570571
const data = this._getHardfork(hardfork)
571572
if (data['block'] === null) {

packages/common/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Chain {
1616
name: string
1717
chainId: number
1818
networkId: number
19+
defaultHardfork: string
1920
comment: string
2021
url: string
2122
genesis: GenesisBlock

packages/common/tests/data/energyWebChain.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "energyWebChain",
33
"chainId": 246,
44
"networkId": 246,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "pow",
78
"algorithm": "ethash"

packages/common/tests/data/testnet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "testnet",
33
"chainId": 12345,
44
"networkId": 12345,
5+
"defaultHardfork": "byzantium",
56
"consensus": {
67
"type": "pow",
78
"algorithm": "ethash"

packages/common/tests/data/volta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "volta",
33
"chainId": 73799,
44
"networkId": 73799,
5+
"defaultHardfork": "istanbul",
56
"consensus": {
67
"type": "pow",
78
"algorithm": "ethash"

0 commit comments

Comments
 (0)