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

make a difficulty blockchain tests separated and genesis block > 0 #318

Closed
winsvega opened this issue Sep 12, 2017 · 17 comments
Closed

make a difficulty blockchain tests separated and genesis block > 0 #318

winsvega opened this issue Sep 12, 2017 · 17 comments

Comments

@winsvega
Copy link
Collaborator

winsvega commented Sep 12, 2017

Currently all blockchain tests are using mining to calculate the correct difficulty for the block.
however we only need a set of tests for the difficulty rules and other tests could just skip mining and difficulty check. switch to noProof rules.

this should increase the speed of blockchain tests generation by x100 times.

to test the difficulty we will be using new set of tests in blockchain tests format
which will have genesis block != 0 so that we could test difficulty formula on any block number on any fork network rules.

The idea

  • disable difficulty check on blockchain tests (swith to noProof)
  • enable difficulty check only if it is signaled by a special option in .json blockchain file
  • make genesis to have number > 0 so we could test the difficulty starting with higher blocks

*an uncle from <= genesis block number - 1 is not allowed.
*any opcode calls to genesis block number -1 are not allowed

or you could suggest the other format to enable / disable difficulty check on blockchain tests

@winsvega
Copy link
Collaborator Author

@pirapira @holiman @fjl

@cdetrio
Copy link
Member

cdetrio commented Sep 13, 2017

Supporting a "genesis" state with block number > 0 is easiest for clients that already support a "snapshot import" (where the snapshot is a json list of accounts ethereum/EIPs#227), which I think is only pyethereum.

It would be best if clients added support for importing a state snapshot as a way to sync to the mainnet (i.e. a user exposed feature). Then the new test format is the same as the json state snapshot format, and could be used with Hive clients as a black-box test runner (rather than clients adding custom unit-testing hooks).

@holiman
Copy link
Contributor

holiman commented Sep 13, 2017

In a whitebox/custom test setting, it would be pretty simple, I should think. Don't think we could do it through hive, though

@gumb0
Copy link
Member

gumb0 commented Sep 13, 2017

Having non-zero genesis to signal special sealing mode looks like a hack, why couldn't we just have a special setting in tests to enable/disable mining?

@winsvega
Copy link
Collaborator Author

winsvega commented Sep 13, 2017

right we could have a special setting in a config json file to signal that mining difficulty should be checked.
but we still need a support for genesis != 0

no need to change smth on hive. this should be done on clients when starting node.
so hive might just change the configuration a bit.

@pirapira
Copy link
Member

@winsvega can we separate genesis != 0 and NoProof in two different issues?

@winsvega
Copy link
Collaborator Author

yes. so lets say if blockchaintest.json has "sealEngine" : "NoProof" then difficulty should not be calculated.
if .json has "sealEngine" : "Ethash" then it works as usual.
if .json has no "sealEngine" field then it should fail as the test is outdated

@pirapira
Copy link
Member

pirapira commented Sep 18, 2017

@winsvega I created #325 for blockchain tests without mining. This issue is now about enabling genesis block with non-zero block numbers.

@winsvega
Copy link
Collaborator Author

winsvega commented Sep 26, 2017

Curren approach is to dave difficulty formula tests
like here difficulty*.json
https://github.com/ethereum/tests/tree/develop/BasicTests

  • because we don't have much time to implement difficulty tests in a blockchain test form.
  • and because this way we could cover much more test cases then with difficulty based on blockchain tests.
  • and I guess difficulty formula wont test the exact situation on a mainnet even if we start block 3M with difficulty 0x020000 in a blockchain test

@cdetrio @holiman @pirapira

@winsvega
Copy link
Collaborator Author

another issue with disabling mining on blockchain tests. as @holiman said such tests would not then be blind and we can't port them to Hive.

I guess this issue could be closed and resolved with

  1. use custom difficulty .json tests in the test repository (done)
  2. generating blockchain tests on threads (done)
  3. optimize mining in cpp

@holgerd77
Copy link
Contributor

holgerd77 commented Sep 29, 2018

What is the state of difficulty tests for Constantinople? Is it worth wait for that and will there be an additional basicTests/difficultyConstantinople.json test cases file in the basicTests directory? Or is there any way to test this?

If this is too much workload, maybe someone else can help out here?

@winsvega
Copy link
Collaborator Author

Yes.additional basic tests will be.
But genesis > 0 is unlikely

@winsvega
Copy link
Collaborator Author

At the moment regenerating blockchain tests for Constantinople

@holgerd77
Copy link
Contributor

@winsvega Cool, thanks for the update!

@winsvega
Copy link
Collaborator Author

@holiman at this point we have difficulty checked even with NoProof rules in a blockchain tests.
only genesis number > 0 is not implemented. do we really ned genesis to be > 0 ?
or could we stick to formula tests for that purpose? (https://github.com/ethereum/tests/blob/develop/BasicTests/difficultyConstantinople.json)

I think we dont really have to support genesis > 0 if we just check the difficulty.
if genesis could be > 0 for testing purposes it require changes on all the clients running hive again to support such config.

@holiman
Copy link
Contributor

holiman commented Nov 15, 2018

I actually happened to look into that a while back, because I wanted to be able to run evm programs with BLOCKNUMBER correctly reproducing an on-chain event.
Turns out it was pretty difficult to implement. Cheating the genesis is easy, but then there are various internal invariants, that there is an unbroken chain of blocks all the way back to 0, which makes the whole thing pretty unstable and ... weird...

@winsvega
Copy link
Collaborator Author

difficulty hash field checks are disabled. the difficulty formula is still verified but with no proof.
genesis > 0 is not implemented.
instead have separate test files for difficulty formula in difficulty tests folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants