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

block_number genesis parameter removed #225

Open
Pet3ris opened this issue Nov 15, 2021 · 5 comments
Open

block_number genesis parameter removed #225

Pet3ris opened this issue Nov 15, 2021 · 5 comments

Comments

@Pet3ris
Copy link

Pet3ris commented Nov 15, 2021

  • Version: latest
  • Python: 3.9
  • OS: osx

What was wrong?

I noticed that the block_number genesis parameter is removed to make London work (

# "block_number": GENESIS_BLOCK_NUMBER,
). We are relying on it for forking - what would be the new preferred way to override block number in eth-tester?

How can it be fixed?

Uncomment block_number in supported genesis parameters?

@fselmo
Copy link
Contributor

fselmo commented Nov 18, 2021

Hey @Pet3ris. This is due to an upstream set of changes in py-evm for London that made certain values unconfigurable, block_number being one of them. There's no reason we can't make it configurable but I don't see a great work-around that doesn't involve making this change in py-evm. That said, for now, you could get all the default values from the genesis header and unpack them into a dictionary, edit the block_number to your choosing while keeping all the other values the same, and set a new header with the updated parameters as follows:

>>> backend = PyEVMBackend(vm_configuration=(
...    (0, LondonVM),
... ))

>>> default_header_fields = vars(backend.chain.header).items()
>>> custom_header_fields = {}

>>> for key, val in default_header_fields:
...    normalized_key = key[1:]  # removes starting "_" from the property
...    if normalized_key == 'block_number':
...        custom_header_fields['block_number'] = 12345  # set block number here
...    else:
...        custom_header_fields[normalized_key] = val

>>> backend.chain.header = LondonBlockHeader(**custom_header_fields)
>>> backend.chain.header.block_number
12345
>>> tester = EthereumTester(backend=backend)

This is pretty hacky but I'm hoping it will at least get you unstuck for now. I will create an issue in py-evm to allow these values to be configurable and we can un-comment it out here in eth-tester once those changes are in.

Let me know if this workaround helps you get unstuck. Good luck!

@Pet3ris
Copy link
Author

Pet3ris commented Nov 19, 2021

Wow thanks @fselmo - this is super cool, thanks for suggesting the work-around and adding the issue. Will give it a go!

@Pet3ris
Copy link
Author

Pet3ris commented Jan 6, 2022

Alright - I was able to change the block number with this snippet but it looks like it changes the block number of the second block, not the first block.

I'm now getting the error:

Blocks must be numbered consecutively. Block number #12207202 has parent #0

which comes from here:

https://github.com/ethereum/py-evm/blob/cb6f44c3e43f3f56ff4082b10cc63ab90e6acf19/eth/vm/base.py#L608

Is there a way around this other than monkey patching out the parent check?

@fselmo
Copy link
Contributor

fselmo commented Jan 6, 2022

@Pet3ris yeah... none of this is ideal. I can try to check out the py-evm customization issue soon. Hopefully until then you can work around this a bit.

@Pet3ris
Copy link
Author

Pet3ris commented Jan 7, 2022

@fselmo no worries - unfortunate the cascading effects of the block number!

I'll try and think about what would be safe to monkey patch for now.

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

No branches or pull requests

2 participants