Skip to content
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

Genesis schema #469

Closed
wants to merge 8 commits into from
Closed

Genesis schema #469

wants to merge 8 commits into from

Conversation

ehildenb
Copy link
Contributor

@ehildenb ehildenb commented Jun 1, 2018

Initial attempt at a Genesis test schema. The example from ethereum/EIPs#1085 is at GenesisTests/dummy.json, and is passing the schema at JSONSchema/genesis-schema.json.

@winsvega and @arnetheduck

@pirapira
Copy link
Member

pirapira commented Jun 5, 2018

@ehildenb is this not blocked anymore?

@ehildenb ehildenb changed the title [BLOCKED] Genesis schema Genesis schema Jun 6, 2018
@ehildenb
Copy link
Contributor Author

ehildenb commented Jun 6, 2018

@pirapira I was hoping for some feedback from @winsvega and @arnetheduck on this issue, as they proposed having the schema in the AllCoreDevs meeting. If we want to merge anyway and fix the schema later, that's also fine with me.

@ehildenb
Copy link
Contributor Author

ehildenb commented Jun 6, 2018

@pirapira I need to make a few more changes before this is ready, will let you know when.

"additionalProperties": false,
"properties": {
"author": {
"$ref": "#/definitions/HexData"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

author is a hex address representation it hsouldbe a valid address.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment. Only say happy new year Github. Thanks you very much.

@winsvega
Copy link
Collaborator

winsvega commented Jun 6, 2018

should this script also check the possible range of the field or just the type of the field?
like extradata is a limited field
difficulty field also has limits. and so on.

@ehildenb ehildenb changed the title Genesis schema [BLOCKED] Genesis schema Jun 6, 2018
@ehildenb
Copy link
Contributor Author

ehildenb commented Jun 6, 2018

Blocking this for #472.

@ehildenb
Copy link
Contributor Author

ehildenb commented Jun 6, 2018

@winsvega I've changed the field "author" to be a AddressMaybePrefixOrEmpty, which other addresses seem to be binned as as well.

Also, I've moved the file to JSONSchema/genesis-filler-schema.json, as I assume this is the schema for the Genesis fillers, and not the tests themselves. The dummy sample file I've moved to src/GenesisTestFillers/dummy.json.

I've updated the Makefile to include the genesis test filler validation, and the README also documents this. Still blocked on #472

@ehildenb ehildenb changed the title [BLOCKED] Genesis schema Genesis schema Jun 7, 2018
@ehildenb
Copy link
Contributor Author

ehildenb commented Jun 7, 2018

Unblocking @pirapira and @winsvega.

@arnetheduck
Copy link

Just for the record, I'm not really involved with this issue, other than as a happy consumer (great to see this work!)

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start! A few comments ...

"balance",
"code",
"nonce",
"storage"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I think storage should be required. Actually, I would prefer if all these four are optional, and defaults to 0 (balance, nonce) or empty (code, storage).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can assert anything about the actual value held, just the JSON structure. I could be wrong though, have not read on JSON schemas, just learned by examples.

I'll make these not required.

"byzantiumForkBlock",
"chainID",
"constantinopleForkBlock",
"homesteadForkBlock",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these -- if we make these required, we'll have to update the genesis spec to make future fork blocks also required -- otherwise it'll be inconsistent. So I would instead say that all forkblocks are implicitly maxUint64 unless otherwise specified. Don't know how to express that in json spec though...
A wild idea would be to have a separate section for those: params/forks/xxx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'll make these not required for now...

"constantinopleForkBlock": {
"$ref": "#/definitions/IntegerOrConfusedHex"
},
"homesteadForkBlock": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have the daoForkBlock

"nonce": {
"$ref": "#/definitions/IntegerOrConfusedHex"
},
"timestamp": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to add an optional number or blockNumber to the genesis. Particularly if we want to go with EIP 210, blockhash, it will be good to run tests on high numbered blocks.

@ehildenb
Copy link
Contributor Author

@holiman I've incorporated your suggestions. One thing I wasn't sure about was whether you meant for chainID and miningMethod to also be optional?

Let me know what else should be changed. If you can provide an example of a filled test as well, I can write the schema for that.

@holiman
Copy link
Contributor

holiman commented Jun 13, 2018

One thing I wasn't sure about was whether you meant for chainID and miningMethod to also be optional?

Well, I don't have any clear opinion about those.

@@ -59,6 +59,20 @@
},
"type": "object"
},
"FillerInfo": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a test filler _info or a genesis json _info ?

a filled test _info has more fields that are required.
a filler test _info has only comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should version the fillers? I think it would be a good idea to start doing that (so that we can add a test like "all the fillers have been updated to the newest version").

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean filler format version?
stateTest -> GeneralStateTest

not so many people used fillers. there has been no need to track test filler format as only me and Yoichi used it. ideally yes. test fillers could be versioned and we could have a documentation stating what are the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think for new formats (ie. Genesis) we should try for the "ideal" case. So I think the fillers should be versioned, and the filled should have hashes for the sources.

It will just make it easier to identify which fillers/filled need updated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filled tests already has hash of the filler.
if there is going to be a vesrion of the filler format. that version would be different from genesis format version. I think we need different scheme validators here. if it is possible to split json validation into separate groups that would be great.

}
]
},
"PreStateAccount": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if its a preState account in tests then all fields are required.
if its a prestate account in Genesis then it has different scheme:

    if (_obj.count(c_precompiled))
    {
        // A precompiled contract
        requireJsonFields(_obj, "validateAccountObj",
            {{c_precompiled, {{js::obj_type}, JsonFieldPresence::Required}},
                {c_wei, {{js::str_type}, JsonFieldPresence::Optional}}});    
    }
    else if (_obj.size() == 1)
    {
        // A genesis account with only balance set
        if (_obj.count(c_balance))
            requireJsonFields(_obj, "validateAccountObj",
                {{c_balance, {{js::str_type}, JsonFieldPresence::Required}}});
        else
            requireJsonFields(_obj, "validateAccountObj",
                {{c_wei, {{js::str_type}, JsonFieldPresence::Required}}});
    }

so it could have only balance defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winsvega not sure what you're suggesting here. Currently none of the fields in PreStateAccount are required, are you saying we should require balance?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. thats a good question. I think we should require balance.
account nonce is default. account code empty by default. same with storage.
but if we not declare any fields then what is the meaning of putting account into genesis?

"^.*$": {
"properties": {
"_info": {
"$ref": "#/definitions/FillerInfo"
Copy link
Collaborator

@winsvega winsvega Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a filler info then. its an info section of genesis.json
_ is added because json lib put _ first in a json.
the section could have version field so we have an idea what sheme version we are dealing with

"additionalProperties": false,
"patternProperties": {
"^(0x)?[0-9a-f]*": {
"$ref": "#/definitions/PreStateAccount",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again a genesis pre state account are different from tests pre state accounts.
genesis account could have only one field - balance. or all 4 standart fields. or if we change the format in the future it might change.

"additionalProperties": false,
"properties": {
"author": {
"$ref": "#/definitions/AddressMaybePrefixOrEmpty"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a question.
author field in genesis should not be empty I think.
and we should agree whether we use 0x prefix or not.

@ehildenb
Copy link
Contributor Author

@winsvega I've tried incorporating your comments, but may have messed some things up, so take another look.

I would recommend looking through the changes with git log --patch on this branch, the commits marked sss at the beginning are the ones which address your comments.

I think we should require a version in the FillerInfo section in addition to the comment, so that it's easy to see when we update the format which tests need updated. This will also allow us to slowly migrate the other test-suites to be more standardized.

@winsvega
Copy link
Collaborator

changing the test fillers would require to regenerate all the tests at the current model. as tests has the hash of the test filler. or we could just copy the hash with a tool without generating a tests. but this should be done in a way that we promise that test itself has not been touched. I think filler _info section is another issue.

here I see the mess around json scheme validators. it is easy to mix a validator with some other test field. like _info at genesis and _info at test filler and _info at filled test.

@@ -1,6 +1,7 @@
{
"dummy_test": {
"GenesisFillerTemplate": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenesisExampleTemplate

@@ -33,6 +31,7 @@
"byzantiumForkBlock": "0x00",
"chainID": "0x01",
"constantinopleForkBlock": "0x00",
"daoForkBlock": "0x00",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this fields are not required, what is the default value? thats important cause some client has it set to 0x00 and other to infinity.

also the names of the fields are important issue here. Parity has EIP155.
are devs agreed to use homesteadForkBlock, byzantiumForkBlock, EIP158ForkBlock for the fork names?

@ehildenb
Copy link
Contributor Author

With the version number, it's more about being able to have a script which cycles through the test fillers and makes sure they are all bigger than a certain version number. That way, if we update the format at some point, it's easy to enforce that all the test fillers have been updated (either programmatically or by hand).

Either way, I think we should focus on "best practices" or the "ideal case" with any new test formats, so we don't end up in the same mess again. I can slowly work on making the old test-sets more conformant, so we have less of the stuff like ...OrEmpty in the validators.

@winsvega
Copy link
Collaborator

It is not that we change the test filler format so often...

@ehildenb
Copy link
Contributor Author

It's more about best practices and future proofing than anything. I would like to begin evolving the VMTests format to make them simpler, for example, and it would be easier with versioning in place.

It won't always be us in charge of this repository, eventually someone will have to inherit it, and having versioning in place makes that process easier (as they will inevitably want to change things).

@winsvega
Copy link
Collaborator

VMTests you could take and experement with.

@holiman
Copy link
Contributor

holiman commented Jun 14, 2018

Regarding fork numbers and names. I think we could come to agreement about their names, if it's ByzantiumFork or EIPXXFork etc.
I still think we should have a separate section forks which contains hardfork numbers. Everything in that section should default to infinity unless specified otherwise (which is outside of the scope for the specification to dictate). That would make it more future-proof, imo, since other config params can be required, whereas more forks can be added later without having to rewrite old tests which lack later forks.

@ehildenb
Copy link
Contributor Author

@winsvega I have removed "version" from being required (which I still think is a mistake).

@holiman I think I have implemented the change you are indicating with the hardfork numbers. The last commit (marked sss) makes the change to the file src/GenesisTestsFiller/template.json so that it passes the validator.

Anything else that should be changed? Can someone supply me with an example Filled GenesisTest so I can write the schema for that?

@ehildenb
Copy link
Contributor Author

I've also pushed a new commit (latest one marked sss) which "tightens" the allowed things to show up in each field. Basically, anywhere possible I put HexData instead of IntegerOrConfusedHex.

That way the clients can have more limited code for reading in the test-sets instead of having to have lots of branches for the potential different ways that keys/values can be passed in.

@winsvega
Copy link
Collaborator

winsvega commented Jun 14, 2018

version field being required in genesis schema is ok
version field being required in test fillers is not ready yet. it will make all PRs to this repo red.
lets first make all tests with version field then add this rule.

@ehildenb
Copy link
Contributor Author

I have added some initial genesis test templates at ./GenesisTests supplied by @folsen, as well as an initial genesis test validator at ./JSONSchema/genesis-schema.json. The last commit demonstrates how to enable said validator in the Makefile test-runner.

Someone should look over and let me know what needs to change, I'll adopt the templates in there to conform to the schema/update the schema a bit more this week.

@winsvega
Copy link
Collaborator

travis check fails.
what about fork block names?

@winsvega
Copy link
Collaborator

winsvega commented Jul 19, 2018

https://github.com/ehildenb/ethereum-tests/blob/4e24d411d67cde54bd1343501b6468a3d4f1489e/GenesisTests/basic_genesis_tests.json
I would like to create this tests with retesteth.
if any client dev is to implement genesis standart they could run
./retesteth -t compatibility/genesis (example)
so if they have test_setChainParams method the tool would try to send different genesis config requests to the client and see if it manage to parse it in response from the client via RPC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expire soon outdated PR/Issue needs to be resolve or closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants