-
Notifications
You must be signed in to change notification settings - Fork 783
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
common: Refactor and update common.getHardforkByBlockNumber to address post merge hfs #2313
Conversation
Codecov Report
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
bdff698
to
f14520b
Compare
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.
Will do more review later but here are some initial questions/feedback.
packages/common/src/common.ts
Outdated
|
||
// hf qualifies else we would have broken out of the loop till now | ||
if (hardfork?.ttd !== undefined && hardfork?.ttd !== null) { | ||
passedMergeHF = hardfork! |
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.
Why do we need this in addition to preMergeHf
? I think I must not be tracking all of the logic yet because there can be only one hardfork with TTD set. So, if we have that, can't we just use that hardfork (set above as preMergeHf
). Also, it seems really odd to call the merge hardfork preMergeHf
. The "pre-merge hardfork" is London so maybe we can find a better way to name this?
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.
yes, thats what preMergeHf
should represent, its london
, and passedMergedHF
is assigned merge
hardfork if its passed, i guess i can change it to boolean and store the merge hardfork as mergeHF
as this later needs to be accessed.
st.equal(c.getHardforkByBlockNumber(0), Hardfork.London, msg) | ||
//using Hardfork.London even though Merge is expected after terminal block 1450408 | ||
st.equal(c.getHardforkByBlockNumber(1450409), Hardfork.London, msg) | ||
st.equal(c.getHardforkByBlockNumber(1450409, BigInt('17000000000000000')), Hardfork.Merge, msg) |
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.
I think this result is counterintuitive. The function is called getHardforkByBlockNumber
and yet when we set TTD and a block number prior to the actual merge block, it's telling me the hardfork is the Merge hardfork. If we're checking the hardfork and specifying a block number prior to the actual block where the merge happens, we shouldn't report a hardfork that is happening later. I know there's screwiness around Merge and MergeForkTransitionId but this doesn't make a ton of sense to me.
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.
I still think this result is counterintuitive. If you provide a block number and the merge hasn't happened yet, regardless of what you pass in for TD, this method should return the previous hardfork. Block number should trump hardfork in terms of which fork is returned.
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.
merge HAS happened if we provide td > ttd (L73), and hasn't happened if we don't provide td L72
TBH: I have no idea what we are actually solving here.
This seems like the correct behavior to me. When a TTD is given the TTD takes precedence (and therefore returns the Merge HF with the TTD set, otherwise respectively in the only-block-number case the mergeForkIdTransition HF is returned. What is the problematic behavior respectively what case can not be modelled with the current method behavior? thinking |
It ( The current change is to get the correct |
Yes, you should only call the You should just be able to call with TTD on all code parts where you want the Merge HF and otherwise do without. |
in post merge world, how would one know if the current hardfork is a post merge scheduled hardfork? I was under the impression that is interface (with Else I can write a wrapper in the client to combine me the functionality of the hardforkByNumber as well as td |
OR you mean to say, we selectively call with/without |
If we pass with TTD only, it just becomes a boolean of To my way of thinking, if a user wants to know if a given block is passed the merge hardfork using this method, we should require them to pass both block number and ttd, run through the list of hardforks and find the one that we're on by block number, then check ttd only if the hf by blocknumber says we're on london. If we find a later hardfork with a block number (e.g. in some future world where Shanghai has passed already), then we shouldn't need to look at ttd at all. Does that logic make sense at all? |
Could we replace the whole thing with something like this? // Filter out hardforks with no block number and no ttd (i.e. unapplied hardforks)
const hfs = common
.hardforks()
.filter((hf) => hf.block !== null || (hf.ttd !== null && hf.ttd !== undefined))
// The index of the hardfork in the hf array that matches our hardfork based on block number
const hfIndex = hfs.findIndex((entry) => entry.block !== null && entry.block > blockNumber) - 1
if (hfs[hfIndex].block === null) {
// We're on the merge hardfork. Let's check the TTD
if (BigInt(hfs[hfIndex].ttd!) > td) {
// Merge ttd greater than current td so we're on hardfork before merge
hf = hfs[hfIndex - 1]
} else {
// Merge ttd equal or less than current td so we're on merge hardfork
hf = hfs[hfIndex]
}
}
return hf This assumes that the hardfork array is in sequentially ascending order (as today) and that hardforks with a |
st.equal(c.getHardforkByBlockNumber(0), Hardfork.London, msg) | ||
//using Hardfork.London even though Merge is expected after terminal block 1450408 | ||
st.equal(c.getHardforkByBlockNumber(1450409), Hardfork.London, msg) | ||
st.equal(c.getHardforkByBlockNumber(1450409, BigInt('17000000000000000')), Hardfork.Merge, msg) |
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.
I still think this result is counterintuitive. If you provide a block number and the merge hasn't happened yet, regardless of what you pass in for TD, this method should return the previous hardfork. Block number should trump hardfork in terms of which fork is returned.
const prevMergeBlockVal = mergeHf.block | ||
mergeHf.block = null | ||
|
||
// should get Hardfork.London even though happened with 1450408 as terminal as config doesn't have that info |
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.
@acolytec3 see if these comments help making sense of the situation
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.
as terminal as config doesn't have that info
-- I don't think this is true any more. You updated the sepolia config to have a block number for the merge.
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.
yes but for this test case i made block null, see L209, i have made this test to be independent of what we specify config in json
Co-authored-by: acolytec3 <[email protected]>
Co-authored-by: acolytec3 <[email protected]>
Co-authored-by: acolytec3 <[email protected]>
Co-authored-by: acolytec3 <[email protected]>
db7d9ef
to
d07f8b3
Compare
|
||
try { | ||
c.getHardforkByBlockNumber(0) | ||
t.fail('should have thrown since no hardfork should quality') |
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.
t.fail('should have thrown since no hardfork should quality') | |
t.fail('should have thrown since no hardfork should qualify') |
packages/common/src/common.ts
Outdated
// all hardforks apply, set hfIndex to the last one as thats the candidate | ||
hfIndex = hfs.length - 1 | ||
} else if (hfIndex === 0) { | ||
// Cant move back, ideally we should throw?? |
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.
Let's remove this comment
packages/common/src/common.ts
Outdated
hfIndex = hfs.length - 1 | ||
} else if (hfIndex === 0) { | ||
// Cant move back, ideally we should throw?? | ||
throw Error('No hardfork qualitifies') |
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.
throw Error('No hardfork qualitifies') | |
throw Error('Must have at least one hardfork at block 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.
LGTM!
…s post merge hfs (#2313) * common: Refactor and update the hardfork cal to address post merge hfs * make strick check optional for post merge hardforks * add tests for post merge hardforks using sepolia * simplify getHardforkByBlockNumber * remove duplicate hf * clarify comment * add post merge hf * further simplify the fn and add test to enhance coverage * update comments * remove hash to add it as a separate pr to not pollute this one * fix typo Co-authored-by: acolytec3 <[email protected]> * comment improvement * undo mainnet json changes * simplify dup ttd check * fix spec * fix typo Co-authored-by: acolytec3 <[email protected]> * fix typo Co-authored-by: acolytec3 <[email protected]> * improve clarity * simpilfy futher based on acolytec3s logic * fix some more validations * remove extra if * improve wording Co-authored-by: acolytec3 <[email protected]> * move spec, add test for merge hf with block num * relocate test * relocate test * lint * add merge block numbers * add merge forkhash * handle no hardfork found case * Fix nits Co-authored-by: acolytec3 <[email protected]>
Ok, cool, thanks for finalizing! |
The sepolia network even post this
was only giving
merge
hardfork oncommon.getHardforkByBlockNumber(1735371,"17000000000000000")
and would give
mergeForkIdTransition
oncommon.getHardforkByBlockNumber(1735371)
This PR refactors the
getHardforkByBlockNumber
as the case handling was not clear and upfrontTODO: