-
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
VM, Common: Complex Genesis State tests #1757
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
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, looks great already and super clean test setup. 🙂
Description of the next TODO steps also makes sense.
Update: I am actually not sure if this is really needed for this. Just had a look again, the state root is only used for genesis block creation in the Update 2: Uh uh uh. I am just realizing that we really just don't have this functionality or mechanism that the genesis state is initialized in the VM and a tx or so can then be executed with this state context. Ah. Interesting. 🙂 I guess this is something which can be added in a very similar way like the activatePrecompiles option we have in the VM already, so Would value a confirmation from @jochem-brouwer on this, guess he might have some clear opinion on this. I think such an option would generally be handy for various scenarios (e.g. also for our internal testing). |
(but Cesar @cbrzn I guess you can continue with this also without an additional confirmation from Jochem or someone else, would be nice though) |
Update 3 😋: ah, and you can then internally call the |
I'm not entirely sure what the question is here. Common cannot calculate state root. So it should be generated in VM? Isn't this functionality already around by importing the genesis block and then just reading the state root and verifying this is correct? Or is the problem that you only have a genesis state file and no genesis block file (so you cannot read state root?). |
The problem we were having is that, when trying to run a transaction in the VM, we were not being able to somehow inject the What I am currently trying in this PR, more specifically in this file is to create a I have a question tho, which I will dig through it later, but for now, if someone can give me insight would be amazing :-) With this test, I am trying to execute a transaction to a contract previously added in the genesis state... In this contract (in solidity), a variable is defined, which to my understanding, is stored in the first slot of the It is worth mentioning that I am trying to trigger this |
So we add an extra flag to signal the VM that there is a custom genesis state? Why can't we check if the provided common has a custom genesis state and then do this by default? People who would initialize common with a custom state would expect that VM also uses that state, and would take some time to figure out there is a flag. Regarding your other questions: here is the gotcha. You are right that the actual runtime code is returned. Why is this? This is because you have initiated the contract with the What you should do is initiate the contract with code No, you would not, as the contract has all storage slots set to 0 in the genesis. So, (Side note: it might be possible that if you the solidity optimizer it might realize that the value in the slot is impossible to change (it is a constant). In that case, solidity might hardcode the method to return 4. However, I checked, this is not the case, it actually reads from storage). I also checked that your calldata is correct. Let me know if something is unclear or you want some more info 😄 |
Ah, that's an interesting idea, haven't thought about that from that perspective. Some aspects to that:
So I would definitely stick with a flag here. The question is if we might want to activate by default - and rather let people opt out. I would have a tendency to not do so though, I find this a bit risky not really knowing what people do around scenario 2., this comes too close to a breaking change for my taste. |
(lot's of post-submission-edits in the last post, please read "on site" and not via email 😄) |
Otherwise: love this conversation here! 😀 ❤️ |
@jochem-brouwer update: also, some room for a compromise: if you think this would really be highly convenient for users and would therefore push for having this activated, we can also add the flag being deactivated for now and switch over to activate along the breaking releases in (but also just a first thought, not completely sure if we should activate at all) |
03db6f9
to
22efe68
Compare
Thanks for the help @jochem-brouwer now the test is working as expected 😄 This is now ready for review @holgerd77 |
packages/common/src/index.ts
Outdated
* Pattern 2 (with genesis state see {@link GenesisState} for format). Note that in {@link AccountState} there are two | ||
* accepted types. This allows to easily insert accounts in the genesis 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 think instead of this additional note here, you can remove and add some more context below with a Pattern 3 (with complex genesis state, containing contract accounts and storage):
for the next example below
* Pattern 2 (with genesis state see {@link GenesisState} for format). Note that in {@link AccountState} there are two | |
* accepted types. This allows to easily insert accounts in the genesis state | |
* Pattern 2 (with genesis state see {@link GenesisState} for format): |
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.
Just updated it! Please let me know if you have any other feedback and I can implement it - Once everything is cool you can resolve this @ryanio :-D
just a few review/nit comments, but otherwise great PR!! 👏 |
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 second that, this looks really great! 😀
There is an ethereum-tests
folder update which sneaked in here, this needs to be removed. Otherwise I would say this is ready to go! 🎉
| `vm:ops` | Opcode traces | | ||
| `vm:ops:[Lower-case opcode name]` | Traces on a specific opcode | | ||
| Logger | Description | | ||
| --------------------------------- | ------------------------------------------------------------------ | |
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.
Same as the comment above, should I remove these non-related changes?
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 one is kind of annoying, I like the prettier format in the code sections especially, but could do without these table formatting. I wonder if we could turn off markdown table formatting specifically in our prettier root config file.
…state from common, tests on progress
Co-authored-by: Ryan Ghods <ryan@ryanio.com>
e89d16b
to
27f37ba
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.
LGTM, thanks a lot Cesar! 🙂
Changes on this PR:
AccountState
has been created, making it part ofGenesisState
customChain
attribute inCommon
Note that the
GenesisState
was previously being used only as string (not the complex object which is nowAccountState
) - Hence, not introducing breaking changes, since the complex object was not being used at allNow, what I aim to do next, is point 3 from this comment #1708 (comment) and execute
runTx
first with a simple transfer tx and then a contract interaction.If my understanding is correct, I think that I will need to first get the hash and state root through the client process (since in the
Common
package it still does not take into account the genesis state given to calculate these fields) and create a custom test data JSON, this way we instantiate a newCommon
object with this new JSON (+ custom state object) - Then, the execution should work, let's see how it goes :-)