This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(providers): add a subset of admin namespace (#1880)
* tell Geth to expose the admin namespace * wip: add admin namespace support * add networking and peer related structs * add rest of chain config fields * add datadir to geth * fix data dir ref * add dev flag to geth * set dev only if block_time is not set * put mutually exclusive options in an enum * make block_time use the devmode enum * add p2p port to geth * add basic impls for admin endpoints * move from_int_or_hex to ethers-core utils * fix nodeinfo protocol field * the type is better represented by a struct which can have either eth or snap * add chain id and discovery toggle for Geth * remove PeerEvent * should re-add when peer event endpoints are implemented * simplify serde options for admin responses * change signature for peer modification apis * these admin apis accept an enode, which _may_ be an enr, but could also be a legacy enode "v4" url. * add note on where `ChainConfig` fields come from * add note on PeerInfo about the source of fields * add admin namespace support to CHANGELOG * update pr number in changelog * cargo fmt * move chainconfig to genesis in utils * accept genesis file in geth * add genesis writing to geth spawn * finally get geth nodes to connect * import io::Read in provider tests * fix PeerInfo and use enode id for provider test * make clippy happy * improve documentation for genesis module * remove not(wasm) attributes on genesis module * remove debugging printlns * remove io::Read from provider tests * add failing post merge test case * add full mainnet nodeinfo for testing * support deserializing json bignums to U256 * the serde_json arbitrary_precision feature is necessary so the serde_json::Number variant of `IntOrHexOrBigNum` can be converted into a string and fed into U256::from_dec_string * fix from_int_or_hex_opt doc string * remove third variant from IntOrHex * unnecessary since serde_json::Number handles smaller ints as well * add comments for ids * fix enode id type in admin_peers provider test * fix admin typo in Cargo.toml Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> * add method to wait on a gethinstance adding a peer * fix dial loop and wait_to_add_peer doc comments * update geth * the build can be updated by changing the GETH_BUILD env var * wait for geth to exit on drop * remove unnecessary wait * fix mid-handshake PeerInfo deserialization * remove println * make tests less flaky * handle discovery with the rest of the non dev opts * dump geth stderr to debug failing ci test * add method which dumps the unread stderr of the geth instance into a string * remove call_raw debug println * bug is due to authrpc endpoint being in use * use unused port when authrpc port is not specified * remove dump_stderr from GethInstance * did not work properly anyways Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
- Loading branch information
Showing
12 changed files
with
1,126 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::{ | ||
types::{Address, Bytes, H256, U256, U64}, | ||
utils::{from_int_or_hex, from_int_or_hex_opt}, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// This represents the chain configuration, specifying the genesis block, header fields, and hard | ||
/// fork switch blocks. | ||
#[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Genesis { | ||
/// The fork configuration for this network. | ||
pub config: ChainConfig, | ||
|
||
/// The genesis header nonce. | ||
pub nonce: U64, | ||
|
||
/// The genesis header timestamp. | ||
pub timestamp: U64, | ||
|
||
/// The genesis header extra data. | ||
pub extra_data: Bytes, | ||
|
||
/// The genesis header gas limit. | ||
pub gas_limit: U64, | ||
|
||
/// The genesis header difficulty. | ||
#[serde(deserialize_with = "from_int_or_hex")] | ||
pub difficulty: U256, | ||
|
||
/// The genesis header mix hash. | ||
pub mix_hash: H256, | ||
|
||
/// The genesis header coinbase address. | ||
pub coinbase: Address, | ||
|
||
/// The initial state of the genesis block. | ||
pub alloc: HashMap<Address, GenesisAccount>, | ||
} | ||
|
||
/// An account in the state of the genesis block. | ||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct GenesisAccount { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub nonce: Option<u64>, | ||
pub balance: U256, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub code: Option<Bytes>, | ||
#[serde(flatten, skip_serializing_if = "Option::is_none")] | ||
pub storage: Option<HashMap<H256, H256>>, | ||
} | ||
|
||
/// Represents a node's chain configuration. | ||
/// | ||
/// See [geth's `ChainConfig` | ||
/// struct](https://github.com/ethereum/go-ethereum/blob/64dccf7aa411c5c7cd36090c3d9b9892945ae813/params/config.go#L349) | ||
/// for the source of each field. | ||
#[derive(Clone, Debug, Deserialize, Serialize, Default)] | ||
#[serde(default, rename_all = "camelCase")] | ||
pub struct ChainConfig { | ||
/// The network's chain ID. | ||
pub chain_id: u64, | ||
|
||
/// The homestead switch block (None = no fork, 0 = already homestead). | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub homestead_block: Option<u64>, | ||
|
||
/// The DAO fork switch block (None = no fork). | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub dao_fork_block: Option<u64>, | ||
|
||
/// Whether or not the node supports the DAO hard-fork. | ||
pub dao_fork_support: bool, | ||
|
||
/// The EIP-150 hard fork block (None = no fork). | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub eip150_block: Option<u64>, | ||
|
||
/// The EIP-150 hard fork hash. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub eip150_hash: Option<H256>, | ||
|
||
/// The EIP-155 hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub eip155_block: Option<u64>, | ||
|
||
/// The EIP-158 hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub eip158_block: Option<u64>, | ||
|
||
/// The Byzantium hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub byzantium_block: Option<u64>, | ||
|
||
/// The Constantinople hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub constantinople_block: Option<u64>, | ||
|
||
/// The Petersburg hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub petersburg_block: Option<u64>, | ||
|
||
/// The Istanbul hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub istanbul_block: Option<u64>, | ||
|
||
/// The Muir Glacier hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub muir_glacier_block: Option<u64>, | ||
|
||
/// The Berlin hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub berlin_block: Option<u64>, | ||
|
||
/// The London hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub london_block: Option<u64>, | ||
|
||
/// The Arrow Glacier hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub arrow_glacier_block: Option<u64>, | ||
|
||
/// The Gray Glacier hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub gray_glacier_block: Option<u64>, | ||
|
||
/// Virtual fork after the merge to use as a network splitter. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub merge_netsplit_block: Option<u64>, | ||
|
||
/// The Shanghai hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub shanghai_block: Option<u64>, | ||
|
||
/// The Cancun hard fork block. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub cancun_block: Option<u64>, | ||
|
||
/// Total difficulty reached that triggers the merge consensus upgrade. | ||
#[serde(skip_serializing_if = "Option::is_none", deserialize_with = "from_int_or_hex_opt")] | ||
pub terminal_total_difficulty: Option<U256>, | ||
|
||
/// A flag specifying that the network already passed the terminal total difficulty. Its | ||
/// purpose is to disable legacy sync without having seen the TTD locally. | ||
pub terminal_total_difficulty_passed: bool, | ||
|
||
/// Ethash parameters. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub ethash: Option<EthashConfig>, | ||
|
||
/// Clique parameters. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub clique: Option<CliqueConfig>, | ||
} | ||
|
||
/// Empty consensus configuration for proof-of-work networks. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct EthashConfig {} | ||
|
||
/// Consensus configuration for Clique. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct CliqueConfig { | ||
/// Number of seconds between blocks to enforce. | ||
pub period: u64, | ||
|
||
/// Epoch length to reset votes and checkpoints. | ||
pub epoch: u64, | ||
} |
Oops, something went wrong.