-
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 Geth Config #1708
Comments
Related: #1696 |
I will expand this issue a bit with adding "Support Geth Config (in Common)" to the title. This is very related since in the Client we already support this functionality along the Geth genesis.json import/parse logic and it would be good to not double the code base here but optimally unify in Common. Furthermore it would generally be good if Common would be able to itself read in Geth config files since this would expand on the use cases, e.g. to have this kind of configuration files as a basis for VM runs. I can vaguely remember that this was in discussion already when we were implementing, and then we had some blockers with prevented this from being implementable in an easy way. Also a vague remembrance: I think it had something to do that - atm we have the Not sure, can't recall the whole chain of complexity here any more, maybe @acolytec3 Andrew can shine some light here since I think he did the implementation on this and stumbled upon these kind of things. |
I'd have to do some exploratory coding but it should be feasible to compute the stateroot and hash if not provided in a genesis file. That's what we do in the client to parse the geth genesis file. The stateroot is calculated here. As I recall, the issue with putting this in common was the concern over adding the |
Ah yes, thanks, remember a bit more clearly. I guess we need to have a closer look where Can't say for sure, but I vaguely remember that this was a bit tricky (stateRoot being used in a below-VM/StateManager based library or something like that). |
Update: ah, I guess strictly speaking this is somewhat of a design flaw - I would call this an "implicit circular dependency" - since we are expecting here (in the Block library) some state context (the calculated state root) while - theoretically - this doesn't belong to Block (block should not need to have some notion of state) - and rather to the Blockchain library. Some meta note: I often thought already that we likely have several of these very, very subtle design (structural) flaws in our libraries which then makes it harder to realize on something else. So in this case the hard (but maybe also the correct) way would be: remove/replace/refactor this option. This state root dependency just shouldn't be there at that place. |
But all this might not be practical. So one way to circumvent this would be to always require the triple of
As an input if someone wants to run Common with a custom genesis file in Geth format. Then we leave it to the user to provide this. (I guess we already were at this place if I recall correctly. 😋) Along we could provide a short library-independent script (or two) for creating the hash and stateRoot if necessary (or - maybe also a way: add some dedicated helper function on this in a fitting upstream library (Blockchain? Client? VM? No idea atm.). Still seems like a feasible way to go to me. |
I dug back through the old issues/PRs around this because I thought I had written just such a script at one point but couldn't come up with anything. I can't find the conversation either but my recollection is that at least when I was approaching it, having an independent script always required installing the trie library to come up with the stateRoot. For someone wanting to run a custom chain, that doesn't seem problematic, right? |
Ok, I had a closer look here and discovered that we already have this extended genesis format accepting So I guess on a first round we should forget about the Geth config support and limit on the following tasks:
This work should be done towards |
After digging through this for a while and reading your discussions in different issues/threads, I have come to some conclusions:
I think that this can be achieved by doing the following:
type GenesisState = {
[address: string] = {
code: string;
balance: string;
storage: Record<string, string>
}
}
Note: Sorry if something does not make sense, this is based on my current understanding of things :-) |
Hi @cbrzn, great, thanks for this write-up, yes, I think you are describing the situation pretty acurately. 😄 Yes, adding the My idea for this round (this should be work towards gethGenesis: {
genesisJSON: file,
stateRoot: string,
hash: string
} and point people who want to use this to the client and describe in Thing is: this geth-genesis-file-to-common is really rather just a nice-to-have feature right now and I wouldn't want to overblow this task and make it a 2-week-long thing. The more important thing is this first "add support for genesis to add code/storage/nonces to genesis accounts" part of this issue (so this would be to add the tests I described in the comment from above). You are very much invited to improve the typing on these things, it just should remain - in the scope of this task - backwards-compatible. |
Now that we have the complex genesis state - I think the next steps to tackle support geth config can be something like:
This game plan is based on the previous PR mentioned but only focuses to support geth file config in common. This will allow us to set the |
That sounds all good, thanks for the write-up! 😄
Just a small nit: this can (should, I guess) just be part of the normal INFO log output (something like "Geth config file loaded chain=... id=... stateRoot =... hash=...) (just a very quick write-up with the broader notion: output some useful information here 🙂) rather than use |
Update: there has been a substantial rework of the genesis-related functionality - also in Common - taken place in #1916 for This is rather a mid-term task though for after the breaking releases are done. |
This has been addressed in #2300, will close. |
Some chains, like MATIC/Polygon, initialize certain contracts on the Genesis block. This is not supported currently in Common, we can only add (?) balance to accounts. To import these chains, genesis should support setting code/storage/nonces of accounts as well.
The text was updated successfully, but these errors were encountered: