-
Notifications
You must be signed in to change notification settings - Fork 6
Create a ChainSpec Wrapper to manage Anvil genesis config #293
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
Conversation
|
EDIT: actually, I don't see it's producing blocks, what I was seeing was probably the anvil config printed as string, not the genesis block storage. So I would say it's not working yet |
After Alex's block production PR, we no longer start producing blocks by default. You either need to configure it via RPC or CLI. A simple way is to use the |
|
I tried customising the genesis block number but without success. When querying the numer from polkadot.js, I get Anyway, setting it in the genesis state is not going to be enough. The block builder uses the block number from the header of the genesis block (not from the runtime state). I think we need to implement another |
|
And for timestamp, we also need to modify the timestamp of the mining engine (similar to what the setTime RPC is doing), so that the next blocks will be based on this timestamp (otherwise they'll just jump right back to the present moment on the next block). CC: @AlexandruCihodaru |
Yeh, looks like block 1 references current time. I don't think we're able to tell what timestamp does block 0 reference, with polkadotjs (no extrinsic shows up in it, like in block 1 case, and the header doesn't seem to show this info either). Would be nice. Not sure how subscan shows it for the production networks. |
I am thinking we should set the genesis block number in the genesis block header too. Not sure though how doable it is. |
| use anvil_polkadot::config::{AnvilNodeConfig, SubstrateNodeConfig}; | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_genesis() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also add a test for configuring via json file, but this can come later, in the next PR if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it in the next PR for genesis accounts
| let latest_block_hash = self.backend.blockchain().info().best_hash; | ||
| Ok(self.chain_id(latest_block_hash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use eth_chain_id()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working right now when we override the chain id in genesis config.
| let Ok(supported_metadata_versions) = | ||
| substrate_service.client.runtime_api().metadata_versions(genesis_hash) | ||
| else { | ||
| return Err(Error::InvalidParams("Unable to fetch metadata versions".to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the subsequent errors feel more like an InternalError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 8915d00
Support genesis configuration customization for
anvil-polkadot.This is implemented through a wrapper struct around
ChainSpec, calledDevelopmentChainSpec, which re-implementsassimilate_storagefor theBuildStoragetrait to override genesis storage for customizable items: chain id, block number, and timestamp.For reference, also see #260 (comment)
Notice that there are still some missing genesis storage items to override: alloc (accounts with code/balances), coinbase (block author), gas settings.