-
Notifications
You must be signed in to change notification settings - Fork 765
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@holgerd77 do you have the forkHash references to speed up review? Edit: got most of |
@@ -63,5 +63,7 @@ | |||
"email": "Holger.Drewes@gmail.com" | |||
} | |||
], | |||
"dependencies": {} | |||
"dependencies": { | |||
"crc-32": "^1.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
"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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. double checked against geth implementation.
https://github.com/ethereum/go-ethereum/blob/15540ae9928441a38f8af47d8227347e6bada5ae/core/forkid/forkid_test.go#L92-L104
Rinkeby does not have DAO fork.
"block": 7280000, | ||
"forkHash": "0x668db0af" | ||
}, | ||
{ | ||
"name": "petersburg", | ||
"block": 7280000 | ||
"block": 7280000, | ||
"forkHash": "0x668db0af" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no forkHash
yet. OK
"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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. double checked against geth implementation: https://github.com/ethereum/go-ethereum/blob/15540ae9928441a38f8af47d8227347e6bada5ae/core/forkid/forkid_test.go#L71-L84
@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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yeah, makes sense! 👍
There was a problem hiding this 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.
This PR adds forkhash support to the
Common
library in preparation foreth/64
support for thedevp2p
library as outlined in ethereumjs/ethereumjs-devp2p#55.It does so by adding a new
Common.forkHash()
method which either returns theforkHash
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.