Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forkhash support to Common library #765

Merged
merged 6 commits into from
Jun 5, 2020
Merged

Conversation

holgerd77
Copy link
Member

This PR adds forkhash support to the Common library in preparation for eth/64 support for the devp2p library as outlined in ethereumjs/ethereumjs-devp2p#55.

It does so by adding a new Common.forkHash() method which either returns the forkHash for a HF from a chain file or calculates via the newly added internal _calcForkHash() function.

I didn't add a Common.forkHashes() method yet as proposed here. I am not completely sure about the output format.

Such a method can be added later if needed along the integration work on the devp2p library.

Fork hashes hardcoded in the chain files are validated with the _calcForkHash() function in the tests.

@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #765 into master will decrease coverage by 0.02%.
The diff coverage is 92.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #765      +/-   ##
==========================================
- Coverage   92.02%   91.99%   -0.03%     
==========================================
  Files          47       44       -3     
  Lines        2995     3011      +16     
  Branches      469      472       +3     
==========================================
+ Hits         2756     2770      +14     
- Misses        144      145       +1     
- Partials       95       96       +1     
Flag Coverage Δ
#account 94.11% <ø> (ø)
#block 88.09% <ø> (ø)
#blockchain 88.74% <ø> (ø)
#common 93.52% <92.00%> (-0.63%) ⬇️
#tx 94.16% <ø> (ø)
#vm 93.09% <ø> (ø)
Impacted Files Coverage Δ
packages/common/src/index.ts 93.52% <92.00%> (-0.35%) ⬇️
packages/common/src/hardforks/index.ts
packages/common/src/chains/index.ts
packages/common/src/genesisStates/index.ts

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ac21f6...b08d076. Read the comment docs.

@evertonfraga
Copy link
Contributor

evertonfraga commented Jun 5, 2020

@holgerd77 do you have the forkHash references to speed up review?

Edit: got most of forkIds from geth implementaion: https://github.com/ethereum/go-ethereum/blob/15540ae9928441a38f8af47d8227347e6bada5ae/core/forkid/forkid_test.go#L41-L116

@@ -63,5 +63,7 @@
"email": "Holger.Drewes@gmail.com"
}
],
"dependencies": {}
"dependencies": {
"crc-32": "^1.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines +39 to +65
"block": 0,
"forkHash": "0xa3f5ab08"
},
{
"name": "byzantium",
"block": 0
"block": 0,
"forkHash": "0xa3f5ab08"
},
{
"name": "constantinople",
"block": 0
"block": 0,
"forkHash": "0xa3f5ab08"
},
{
"name": "petersburg",
"block": 0
"block": 0,
"forkHash": "0xa3f5ab08"
},
{
"name": "istanbul",
"block": 1561651
"block": 1561651,
"forkHash": "0xc25efa5c"
},
{
"name": "berlin",
"block": null
"block": null,
"forkHash": null
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +19 to +65
"block": 0,
"forkHash": "0x3b8e0691"
},
{
"name": "homestead",
"block": 1
"block": 1,
"forkHash": "0x60949295"
},
{
"name": "dao",
"block": null
"block": null,
"forkHash": null
},
{
"name": "tangerineWhistle",
"block": 2
"block": 2,
"forkHash": "0x8bde40dd"
},
{
"name": "spuriousDragon",
"block": 3
"block": 3,
"forkHash": "0xcb3a64bb"
},
{
"name": "byzantium",
"block": 1035301
"block": 1035301,
"forkHash": "0x8d748b57"
},
{
"name": "constantinople",
"block": 3660663
"block": 3660663,
"forkHash": "0xe49cab14"
},
{
"name": "petersburg",
"block": 4321234
"block": 4321234,
"forkHash": "0xafec6b27"
},
{
"name": "istanbul",
"block": 5435345
"block": 5435345,
"forkHash": "0xcbdb8838"
},
{
"name": "berlin",
"block": null
"block": null,
"forkHash": null
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +49 to +55
"block": 7280000,
"forkHash": "0x668db0af"
},
{
"name": "petersburg",
"block": 7280000
"block": 7280000,
"forkHash": "0x668db0af"
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, they share the same forkHash.

},
{
"name": "berlin",
"block": null
"block": null,
"forkHash": null
Copy link
Contributor

Choose a reason for hiding this comment

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

no forkHash yet. OK

Comment on lines +19 to +70
"block": 0,
"forkHash": "0x30c7ddbc"
},
{
"name": "homestead",
"block": 0
"block": 0,
"forkHash": "0x30c7ddbc"
},
{
"name": "dao",
"block": null
"block": null,
"forkHash": null
},
{
"name": "tangerineWhistle",
"block": 0
"block": 0,
"forkHash": "0x30c7ddbc"
},
{
"name": "spuriousDragon",
"block": 10
"block": 10,
"forkHash": "0x63760190"
},
{
"name": "byzantium",
"block": 1700000
"block": 1700000,
"forkHash": "0x3ea159c7"
},
{
"name": "constantinople",
"block": 4230000
"block": 4230000,
"forkHash": "0x97b544f3"
},
{
"name": "petersburg",
"block": 4939394
"block": 4939394,
"forkHash": "0xd6e2149b"
},
{
"name": "istanbul",
"block": 6485846
"block": 6485846,
"forkHash": "0x4bc66396"
},
{
"name": "muirGlacier",
"block": 7117117
"block": 7117117,
"forkHash": "0x6727ef90"
},
{
"name": "berlin",
"block": null
"block": null,
"forkHash": null
Copy link
Contributor

Choose a reason for hiding this comment

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

packages/common/src/index.ts Outdated Show resolved Hide resolved
packages/common/src/index.ts Outdated Show resolved Hide resolved
packages/common/src/index.ts Outdated Show resolved Hide resolved
packages/common/src/index.ts Show resolved Hide resolved
@holgerd77
Copy link
Member Author

@evertonfraga ok, hopefully have addressed everything 😄 , ready for re-review.

@@ -129,8 +129,7 @@ export default class Common {
* @param hardfork Hardfork given to function as a parameter
* @returns Hardfork chosen to be used
*/
_chooseHardfork(hardfork?: string | null, onlySupported?: boolean): string {
onlySupported = onlySupported === undefined ? true : onlySupported
_chooseHardfork(hardfork?: string | null, onlySupported: boolean = true): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change does not alter the final signature. The compiler implies that setting a default value means that the parameter is optional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, yeah, makes sense! 👍

@evertonfraga evertonfraga self-requested a review June 5, 2020 16:47
Copy link
Contributor

@evertonfraga evertonfraga left a comment

Choose a reason for hiding this comment

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

@holgerd77 this is good to go! I liked how you did the calc function, so it can be used as a future-proof mechanism while also fulfill custom chain requirements.

I don't know how expensive CRC32 execution is, but down the road, if it's expressive enough, memoizing forkHash() would save resources for cases other than those represented in this repo.

@holgerd77 holgerd77 merged commit 28b8fa4 into master Jun 5, 2020
@holgerd77 holgerd77 deleted the add-forkhash-support branch June 5, 2020 17:57
@evertonfraga evertonfraga added this to the VM v5 milestone Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants