Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 4b68562

Browse files
Rjectedgakonst
andauthored
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 <[email protected]> * 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 <[email protected]>
1 parent 2d793ed commit 4b68562

File tree

12 files changed

+1126
-44
lines changed

12 files changed

+1126
-44
lines changed

.github/workflows/ci.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
ETHERSCAN_API_KEY_ETHEREUM: I5BXNZYP5GEDWFINGVEZKYIVU2695NPQZB
1414
ETHERSCAN_API_KEY_CELO: B13XSMUT6Q3Q4WZ5DNQR8RXDBA2KNTMT4M
1515
GOERLI_PRIVATE_KEY: "fa4a1a79e869a96fcb42727f75e3232d6865a82ea675bb95de967a7fe6a773b2"
16+
GETH_BUILD: 1.10.26-e5eb32ac
1617

1718
jobs:
1819
tests:
@@ -36,9 +37,9 @@ jobs:
3637
- name: Install geth
3738
run: |
3839
mkdir -p "$HOME/bin"
39-
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
40-
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
41-
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
40+
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
41+
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
42+
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
4243
chmod u+x "$HOME/bin/geth"
4344
export PATH=$HOME/bin:$PATH
4445
geth version
@@ -79,9 +80,9 @@ jobs:
7980
- name: Install geth
8081
run: |
8182
mkdir -p "$HOME/bin"
82-
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
83-
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
84-
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
83+
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
84+
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
85+
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
8586
chmod u+x "$HOME/bin/geth"
8687
export PATH=$HOME/bin:$PATH
8788
geth version
@@ -201,9 +202,9 @@ jobs:
201202
- name: Install geth (for state overrides example)
202203
run: |
203204
mkdir -p "$HOME/bin"
204-
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
205-
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
206-
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
205+
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
206+
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
207+
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
207208
chmod u+x "$HOME/bin/geth"
208209
export PATH=$HOME/bin:$PATH
209210
geth version

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@
221221

222222
### Unreleased
223223

224+
- Add a subset of the `admin` namespace
225+
[1880](https://github.com/gakonst/ethers-rs/pull/1880)
224226
- Return String for net version
225227
[1376](https://github.com/gakonst/ethers-rs/pull/1376)
226228
- Stream of paginated logs that load logs in small pages

Cargo.lock

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethers-core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tiny-keccak = { version = "2.0.2", default-features = false }
2727
# misc
2828
chrono = { version = "0.4", default-features = false }
2929
serde = { version = "1.0.124", default-features = false, features = ["derive"] }
30-
serde_json = { version = "1.0.64", default-features = false }
30+
serde_json = { version = "1.0.64", default-features = false, features = ["arbitrary_precision"] }
3131
thiserror = { version = "1.0", default-features = false }
3232
bytes = { version = "1.3.0", features = ["serde"] }
3333
hex = { version = "0.4.3", default-features = false, features = ["std"] }

ethers-core/src/types/fee.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::str::FromStr;
2-
3-
use crate::types::U256;
4-
use serde::{de::Deserializer, Deserialize, Serialize};
1+
use crate::{types::U256, utils::from_int_or_hex};
2+
use serde::{Deserialize, Serialize};
53

64
#[derive(Deserialize, Serialize, Debug, Clone)]
75
#[serde(rename_all = "camelCase")]
@@ -19,19 +17,3 @@ pub struct FeeHistory {
1917
#[serde(default)]
2018
pub reward: Vec<Vec<U256>>,
2119
}
22-
23-
fn from_int_or_hex<'de, D>(deserializer: D) -> Result<U256, D::Error>
24-
where
25-
D: Deserializer<'de>,
26-
{
27-
#[derive(Deserialize)]
28-
#[serde(untagged)]
29-
enum IntOrHex {
30-
Int(u64),
31-
Hex(String),
32-
}
33-
match IntOrHex::deserialize(deserializer)? {
34-
IntOrHex::Int(n) => Ok(U256::from(n)),
35-
IntOrHex::Hex(s) => U256::from_str(s.as_str()).map_err(serde::de::Error::custom),
36-
}
37-
}

ethers-core/src/utils/genesis.rs

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
use std::collections::HashMap;
2+
3+
use crate::{
4+
types::{Address, Bytes, H256, U256, U64},
5+
utils::{from_int_or_hex, from_int_or_hex_opt},
6+
};
7+
use serde::{Deserialize, Serialize};
8+
9+
/// This represents the chain configuration, specifying the genesis block, header fields, and hard
10+
/// fork switch blocks.
11+
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
12+
#[serde(rename_all = "camelCase")]
13+
pub struct Genesis {
14+
/// The fork configuration for this network.
15+
pub config: ChainConfig,
16+
17+
/// The genesis header nonce.
18+
pub nonce: U64,
19+
20+
/// The genesis header timestamp.
21+
pub timestamp: U64,
22+
23+
/// The genesis header extra data.
24+
pub extra_data: Bytes,
25+
26+
/// The genesis header gas limit.
27+
pub gas_limit: U64,
28+
29+
/// The genesis header difficulty.
30+
#[serde(deserialize_with = "from_int_or_hex")]
31+
pub difficulty: U256,
32+
33+
/// The genesis header mix hash.
34+
pub mix_hash: H256,
35+
36+
/// The genesis header coinbase address.
37+
pub coinbase: Address,
38+
39+
/// The initial state of the genesis block.
40+
pub alloc: HashMap<Address, GenesisAccount>,
41+
}
42+
43+
/// An account in the state of the genesis block.
44+
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
45+
pub struct GenesisAccount {
46+
#[serde(skip_serializing_if = "Option::is_none")]
47+
pub nonce: Option<u64>,
48+
pub balance: U256,
49+
#[serde(skip_serializing_if = "Option::is_none")]
50+
pub code: Option<Bytes>,
51+
#[serde(flatten, skip_serializing_if = "Option::is_none")]
52+
pub storage: Option<HashMap<H256, H256>>,
53+
}
54+
55+
/// Represents a node's chain configuration.
56+
///
57+
/// See [geth's `ChainConfig`
58+
/// struct](https://github.com/ethereum/go-ethereum/blob/64dccf7aa411c5c7cd36090c3d9b9892945ae813/params/config.go#L349)
59+
/// for the source of each field.
60+
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
61+
#[serde(default, rename_all = "camelCase")]
62+
pub struct ChainConfig {
63+
/// The network's chain ID.
64+
pub chain_id: u64,
65+
66+
/// The homestead switch block (None = no fork, 0 = already homestead).
67+
#[serde(skip_serializing_if = "Option::is_none")]
68+
pub homestead_block: Option<u64>,
69+
70+
/// The DAO fork switch block (None = no fork).
71+
#[serde(skip_serializing_if = "Option::is_none")]
72+
pub dao_fork_block: Option<u64>,
73+
74+
/// Whether or not the node supports the DAO hard-fork.
75+
pub dao_fork_support: bool,
76+
77+
/// The EIP-150 hard fork block (None = no fork).
78+
#[serde(skip_serializing_if = "Option::is_none")]
79+
pub eip150_block: Option<u64>,
80+
81+
/// The EIP-150 hard fork hash.
82+
#[serde(skip_serializing_if = "Option::is_none")]
83+
pub eip150_hash: Option<H256>,
84+
85+
/// The EIP-155 hard fork block.
86+
#[serde(skip_serializing_if = "Option::is_none")]
87+
pub eip155_block: Option<u64>,
88+
89+
/// The EIP-158 hard fork block.
90+
#[serde(skip_serializing_if = "Option::is_none")]
91+
pub eip158_block: Option<u64>,
92+
93+
/// The Byzantium hard fork block.
94+
#[serde(skip_serializing_if = "Option::is_none")]
95+
pub byzantium_block: Option<u64>,
96+
97+
/// The Constantinople hard fork block.
98+
#[serde(skip_serializing_if = "Option::is_none")]
99+
pub constantinople_block: Option<u64>,
100+
101+
/// The Petersburg hard fork block.
102+
#[serde(skip_serializing_if = "Option::is_none")]
103+
pub petersburg_block: Option<u64>,
104+
105+
/// The Istanbul hard fork block.
106+
#[serde(skip_serializing_if = "Option::is_none")]
107+
pub istanbul_block: Option<u64>,
108+
109+
/// The Muir Glacier hard fork block.
110+
#[serde(skip_serializing_if = "Option::is_none")]
111+
pub muir_glacier_block: Option<u64>,
112+
113+
/// The Berlin hard fork block.
114+
#[serde(skip_serializing_if = "Option::is_none")]
115+
pub berlin_block: Option<u64>,
116+
117+
/// The London hard fork block.
118+
#[serde(skip_serializing_if = "Option::is_none")]
119+
pub london_block: Option<u64>,
120+
121+
/// The Arrow Glacier hard fork block.
122+
#[serde(skip_serializing_if = "Option::is_none")]
123+
pub arrow_glacier_block: Option<u64>,
124+
125+
/// The Gray Glacier hard fork block.
126+
#[serde(skip_serializing_if = "Option::is_none")]
127+
pub gray_glacier_block: Option<u64>,
128+
129+
/// Virtual fork after the merge to use as a network splitter.
130+
#[serde(skip_serializing_if = "Option::is_none")]
131+
pub merge_netsplit_block: Option<u64>,
132+
133+
/// The Shanghai hard fork block.
134+
#[serde(skip_serializing_if = "Option::is_none")]
135+
pub shanghai_block: Option<u64>,
136+
137+
/// The Cancun hard fork block.
138+
#[serde(skip_serializing_if = "Option::is_none")]
139+
pub cancun_block: Option<u64>,
140+
141+
/// Total difficulty reached that triggers the merge consensus upgrade.
142+
#[serde(skip_serializing_if = "Option::is_none", deserialize_with = "from_int_or_hex_opt")]
143+
pub terminal_total_difficulty: Option<U256>,
144+
145+
/// A flag specifying that the network already passed the terminal total difficulty. Its
146+
/// purpose is to disable legacy sync without having seen the TTD locally.
147+
pub terminal_total_difficulty_passed: bool,
148+
149+
/// Ethash parameters.
150+
#[serde(skip_serializing_if = "Option::is_none")]
151+
pub ethash: Option<EthashConfig>,
152+
153+
/// Clique parameters.
154+
#[serde(skip_serializing_if = "Option::is_none")]
155+
pub clique: Option<CliqueConfig>,
156+
}
157+
158+
/// Empty consensus configuration for proof-of-work networks.
159+
#[derive(Clone, Debug, Deserialize, Serialize)]
160+
pub struct EthashConfig {}
161+
162+
/// Consensus configuration for Clique.
163+
#[derive(Clone, Debug, Deserialize, Serialize)]
164+
pub struct CliqueConfig {
165+
/// Number of seconds between blocks to enforce.
166+
pub period: u64,
167+
168+
/// Epoch length to reset votes and checkpoints.
169+
pub epoch: u64,
170+
}

0 commit comments

Comments
 (0)