-
Notifications
You must be signed in to change notification settings - Fork 773
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: Support custom hash & state root on genesis #1833
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
if (this._customChains?.length && Array.isArray(this._customChains[0])) { | ||
plainCustomChains = (this._customChains as [IChain, GenesisState | GethGenesisState][]).map( | ||
([chain, state]) => { | ||
if ('hash' && 'stateRoot' in state) { |
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 believe this needs to be
if ('hash' && 'stateRoot' in state) { | |
if ('hash' in state && 'stateRoot' in state) { |
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.
a trick i use when the list starts getting long (from parse.ts):
if (['config', 'difficulty', 'gasLimit', 'alloc'].some((field) => !(field in json))) {
throw new Error('Invalid format, expected geth genesis fields missing')
}
stateRoot: 'cool-state-root', | ||
hash: 'cool-hash', |
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.
can you use valid values? maybe we should strictly validate them
wouldn't it be safer to derive the block hash and state root ourselves to ensure they equal the submitted params, rather than using them as an "override"? that would ensure everything in our stack is working to derive them correctly it doesn't make sense to me that common should have any "geth" logic, rather i like that the client (or somewhere, could be a common util) sets everything up for a proper common instance. the geth config file should just be formatted and parsed to be used in the rest of our stack, not as a custom option. think if we tried to also support a nethermind config, we wouldn't want to add custom logic and storage for parsing of the nethermind config, we just want a resulting common that matches the config exactly. |
I agree with you, but the problem is that, if we want to generate these hashes we would need the
That's a super important point and thanks for bringing that up I think is aligned with my thought, which is making the edit: also, if you feel this should not be done just let me know - I am trying to approach a way to make L2 support easier, but probably I am missing things for my lack of knowledge |
sounds good, thanks for explaining. i guess we can use this as a "trusted source" then. it might be a good idea to check in the client that these hash and stateRoot match on bootup and error and abort if not, i imagine it would help to know in advance rather than getting different values in different places.
|
@cbrzn thanks for a start on this, great! 🙂 @ryanio the main use case for this is that people can easily (easier) use a Geth config file within our lower level libraries (so everything below the client, e.g. - guess main use case - use this for running a tx in the VM or generally creating a tx - if one only has a Geth config file at hand). The other alternative would be to remove - along the breaking work - So So a chain of refactoring would look roughly as follows:
Have no 100% proof that this would be it, but I am thinking about this topic for several weeks now and have followed this whole interdependency chain a couple of times and I think this would roughly be it which might lead us to generally leave some non-logical twists behind, also regarding e.g. some overload/misplacement on StateManager and inconsistent library placements/dependencies regarding the Client/Blockchain/VM correlation. This is pretty heavy stuff though. 😬 😋 We could tackle nevertheless. The solution here would be the - very - local one just extending a bit (but not too dramatically) on our own sub-optimalities. I have no totally strong bias in the one or the other direction. We should just know what we are doing. 🙂 |
thanks for the in-depth walk through, super interesting! and a great time to consider some broader changes while working on develop. i will let this sink in before i give an opinion on a route, but i do like your bullet points, they seem like improvements in the right direction to me. |
As a second thing, this kind of deeper-reaching refactoring would also allow to solve on #1673 - so the heavy bundle sizes due to the bundling of the genesis state within Common - by moving genesis states to At the same time (if I am not mistaken) genesis state could still be provided on an API level for us internally on all places where it is necessary. Common would then solely take genesis in as a constructor option. |
Very good points @holgerd77!
Right, so we move |
That would at least be a possibility, we can explore this further. Note that there is no imminent need though to do anything in this direction at all. So if we do not want to overload on this we can also simply skip this point for now. |
Still have my sights on this, will try to pick up and continue this week. I'll open a new PR targeting develop with the changes outlined in #1833 (comment) |
Oh, interesting (and great), totally forgot about this TBH. |
@ryanio you can also consider #1833 (comment) (another comment, even if linked with the same text) along if you want. |
Also have added an additional "In Discussion/TODO" note on the v6 Release Notes so that we do not forget about this task. |
I've gotten started on this but have run into a few things so far:
|
@ryanio great that you had a first look! 🙂 All of these are first-shots, so we might want to deepen discussion on the call or something:
We could make the
Yeah, maybe we wait on this for the VM/EVM refactor? I guess the
If the genesis functionality is now in |
Have continued in #1916 so I will close here |
This PR aims to support custom hash and state root in
Common
initialization. Currently, we are updating thegenesis
object with the desired hash and state root, but the state given (which is thejson
attribute) is not being used at all, the reason for this is that the geth state parser is inClient
and not inCommon
package.I think that we should be able to support also the genesis state object (Since we are passing a state root hash, we need a state that can represent that hash - If I understand this correctly). After thinking a bit though this, I think that the easiest way to achieve this is to just make this
json
param to beGenesisState
typeI am seeing this from the point of view of initiating for example the polygon chain, we can set the state with proper hashes, being able to fully execute a block
edit: I marked this as draft because it's not ready yet but would be awesome to get a review just to make sure I am going in the correct path