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

Goerli support and genesis changes #593

Closed
wants to merge 4 commits into from

Conversation

petertdavies
Copy link
Collaborator

This PR adds support for Goerli. I have made two structural changes to achieve this:

  • Hardfork blocks are read from dictionaries in src/ethereum/hardfork.py.
  • Genesis is now not part of Frontier, it's in src/ethereum/genesis.py. The genesis hardfork is configurable so that Sepolia genesis (which has a baseFeePerGas) can be handled cleanly.

We should consider whether we should get rid of MAINNET_FORK_BLOCK variables, but I have not done this.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

src/ethereum/genesis.py Outdated Show resolved Hide resolved
Comment on lines +123 to +129
The `nonce` field is `0x42` referencing Douglas Adams' "HitchHiker's Guide
to the Galaxy".

The `extra_data` field contains the hash of block `1028201` on
the pre-launch Olympus testnet. The creation of block `1028201` on Olympus
marked the "starting gun" for Ethereum block creation. Including its hash
in the genesis block ensured a fair launch of the Ethereum mining process.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these values come from the genesis parameter, I'm not sure these paragraphs make sense for all inputs (ex. goerli.json looks like it has a nonce of zero.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@petertdavies where'd we land on this?

Comment on lines +133 to +135
On testnets the genesis configuration usually allocates 1 wei to addresses
`0x00` to `0xFF` to avoid edgecases around precompiles being created or
cleared (by EIP 161).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how I feel about this. It's certainly a useful and interesting tidbit, but it isn't relevant for mainnet, and isn't a strict requirement for testnets. Feel free to ignore this comment!

src/ethereum/hardforks.py Outdated Show resolved Hide resolved

Returns
-------
20_byte_stream : `bytes`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
20_byte_stream : `bytes`
20_byte_stream : `Bytes20`

src/ethereum/hardforks.py Show resolved Hide resolved
This module contains code and configuration information enabling the
specification to be used with Ethereum testnets.

This module does not form part of the Ethereum specification.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this make sense as a separate module, like src/ethereum_testnets/... or is that not possible?

Comment on lines +2 to +3
Clique
^^^^^^
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be nice to expand the heading a bit for people not familiar with clique?

Suggested change
Clique
^^^^^^
Clique Consensus
^^^^^^^^^^^^^^^^

Comment on lines +98 to +120
pay_rewards_backup = hardfork.module("spec").pay_rewards
hardfork.module("spec").pay_rewards = dont_pay_rewards

(
gas_used,
transactions_root,
receipt_root,
block_logs_bloom,
state,
) = hardfork.module("spec").apply_body(
chain.state,
hardfork.module("spec").get_last_256_block_hashes(chain),
signer_address,
block.header.number,
block.header.gas_limit,
block.header.timestamp,
block.header.difficulty,
block.transactions,
block.ommers,
chain.chain_id,
)

hardfork.module("spec").pay_rewards = pay_rewards_backup
Copy link
Collaborator

Choose a reason for hiding this comment

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

This answer has an interesting way to import a module under a different handle, such that items from one handle are separate from items from the other:

import sys
import importlib.util

SPEC_OS = importlib.util.find_spec('os')
os1 = importlib.util.module_from_spec(SPEC_OS)
SPEC_OS.loader.exec_module(os1)
sys.modules['os1'] = os1

os2 = importlib.util.module_from_spec(SPEC_OS)
SPEC_OS.loader.exec_module(os2)
sys.modules['os2'] = os2
del SPEC_OS

assert os1 is not os2, \
    "Module `os` instancing failed"

I tried it out, and it seems to work for monkey patching (so we could create entirely separate modules clique_frontier, clique_homestead, and so on.)

Thoughts?

@petertdavies
Copy link
Collaborator Author

Closing. This will be superseded by several upcoming PRs.

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

Successfully merging this pull request may close these issues.

None yet

3 participants