Skip to content

[Anvil] Genesis customisation #241

@alindima

Description

@alindima

Some genesis values can be customised directly from the cmdline (--balance, --timestamp, --number). Anvil also supports reading a genesis JSON file (--init). Not everything that can be configured in the genesis is used by anvil. Only these items are (double-check):

  • Genesis block timestamp. Can be queried from within the smart contract with block.timestamp. This ends up in a hostcall going to the Config::Time on pallet revive, which ends up calling into the timestamp pallet. We need to modify the node-side InherentDataProvider to take this genesis timestamp and pass it in.
  • Genesis block number. Let’s leave this for later and see if it’s actually useful. It can be tricky, substrate does not support this by default. Pallets may be making assumptions about the genesis block being 0 so we may break everything.
  • ChainID. A constant part of the pallet-revive Config trait. We can only modify this when building the runtime. Smart contracts can query the value by block.chainid. anvil_setChainId should also be implemented. We need to turn the constant in pallet-revive into a storage item (using frame parameters). We need support from the smart contract team in order to upstream this. Let’s also try to make this configurable at genesis, using GenesisConfig.
  • Coinbase (address of the miner, part of the standard ethereum Block information), can be queried by the smart contract via block.coinbase. Can be modified by rpcs (anvil_setCoinbase, also implement this). This is determined in pallet-revive by the FindAuthor trait impl which by default returns None (translating into a zeroed address). We need to implement FindAuthor properly (needs a runtime modification, to change the FindAuthor implementation and a node-side change for supplying the accountid in the consensus_data_provider inside ManualSealParams).
  • Base_fee_per_gas (not in standard ethereum genesis, it is used in testing). Corresponds to GAS_PRICE constant in pallet-revive. Is returned as part of every block. I don’t think it can be easily overwritten without rebuilding the runtime. It can also be overwritten at runtime (only for the next block) with SetNextBlockBaseFeePerGas. We need a bit more investigation into how gas is used in pallet revive
  • Alloc (accounts): The initial state of accounts in the genesis block. They can also come from the accounts configured in the cmdline (via --accounts, --balance, which can only be basic accounts derived from one mnemonic. The accounts configured in JSON can also be smart contract accounts. Balances we can easily add via GenesisConfig of the balances and revive pallets. They can also configure signers through the privateKey option. Smart contracts cannot currently be registered at genesis in pallet-revive. We could add smart contracts to the genesis config of the pallet (needs upstreaming). We need to also add a CREATE2 deployer contract at genesis (which can be disabled via cmdline). We could get this for free with Add a create2 precompile for deterministic deployments contract-issues#99

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions