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

feat(providers): add a subset of admin namespace #1880

Merged
merged 54 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0c0a99c
tell Geth to expose the admin namespace
Rjected Nov 6, 2022
a350324
wip: add admin namespace support
Rjected Nov 17, 2022
0fce96c
add rest of chain config fields
Rjected Nov 21, 2022
4adffd4
add datadir to geth
Rjected Nov 21, 2022
0562f0b
fix data dir ref
Rjected Nov 22, 2022
26c0d66
add dev flag to geth
Rjected Nov 22, 2022
2bedcd2
set dev only if block_time is not set
Rjected Nov 22, 2022
6a237b3
put mutually exclusive options in an enum
Rjected Nov 22, 2022
d6b9687
make block_time use the devmode enum
Rjected Nov 22, 2022
fce6c40
add p2p port to geth
Rjected Nov 22, 2022
52a7a35
add basic impls for admin endpoints
Rjected Nov 22, 2022
e28d1a1
move from_int_or_hex to ethers-core utils
Rjected Nov 22, 2022
4cfaffb
fix nodeinfo protocol field
Rjected Nov 22, 2022
1033b13
add chain id and discovery toggle for Geth
Rjected Nov 22, 2022
5e3eb65
remove PeerEvent
Rjected Nov 22, 2022
2bb8b32
simplify serde options for admin responses
Rjected Nov 22, 2022
3dcacb4
change signature for peer modification apis
Rjected Nov 22, 2022
280a3d3
add note on where `ChainConfig` fields come from
Rjected Nov 22, 2022
0c1cf6d
add note on PeerInfo about the source of fields
Rjected Nov 22, 2022
23fa941
add admin namespace support to CHANGELOG
Rjected Nov 22, 2022
09c4509
update pr number in changelog
Rjected Nov 22, 2022
f9a324a
cargo fmt
Rjected Nov 22, 2022
285f037
move chainconfig to genesis in utils
Rjected Nov 22, 2022
20446a3
accept genesis file in geth
Rjected Nov 22, 2022
0052e72
add genesis writing to geth spawn
Rjected Nov 22, 2022
343fd89
finally get geth nodes to connect
Rjected Nov 23, 2022
02db1b1
import io::Read in provider tests
Rjected Nov 23, 2022
6f5b06f
fix PeerInfo and use enode id for provider test
Rjected Nov 26, 2022
037fbcf
make clippy happy
Rjected Nov 26, 2022
567cf38
improve documentation for genesis module
Rjected Nov 26, 2022
6183c87
remove not(wasm) attributes on genesis module
Rjected Nov 26, 2022
d27d0bc
remove debugging printlns
Rjected Nov 26, 2022
a345fa3
remove io::Read from provider tests
Rjected Nov 26, 2022
2c3375d
add failing post merge test case
Rjected Nov 26, 2022
7efbd36
add full mainnet nodeinfo for testing
Rjected Nov 26, 2022
51b4638
support deserializing json bignums to U256
Rjected Nov 26, 2022
302cb9c
fix from_int_or_hex_opt doc string
Rjected Nov 26, 2022
54ad70c
remove third variant from IntOrHex
Rjected Nov 26, 2022
ae22226
add comments for ids
Rjected Nov 26, 2022
cce36a6
fix enode id type in admin_peers provider test
Rjected Nov 26, 2022
20557f0
fix admin typo in Cargo.toml
Rjected Nov 28, 2022
7697f69
add method to wait on a gethinstance adding a peer
Rjected Nov 28, 2022
e92dbf6
fix dial loop and wait_to_add_peer doc comments
Rjected Nov 28, 2022
50ccfce
update geth
Rjected Nov 28, 2022
af47a31
wait for geth to exit on drop
Rjected Nov 28, 2022
f6188d3
remove unnecessary wait
Rjected Nov 28, 2022
548b360
fix mid-handshake PeerInfo deserialization
Rjected Nov 29, 2022
dbb53a9
remove println
Rjected Nov 29, 2022
96c897c
make tests less flaky
Rjected Nov 29, 2022
7c445e3
handle discovery with the rest of the non dev opts
Rjected Nov 29, 2022
a66548d
dump geth stderr to debug failing ci test
Rjected Nov 29, 2022
b71c71c
remove call_raw debug println
Rjected Nov 29, 2022
9d7e23e
use unused port when authrpc port is not specified
Rjected Nov 29, 2022
8ca864c
remove dump_stderr from GethInstance
Rjected Nov 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
ETHERSCAN_API_KEY_ETHEREUM: I5BXNZYP5GEDWFINGVEZKYIVU2695NPQZB
ETHERSCAN_API_KEY_CELO: B13XSMUT6Q3Q4WZ5DNQR8RXDBA2KNTMT4M
GOERLI_PRIVATE_KEY: "fa4a1a79e869a96fcb42727f75e3232d6865a82ea675bb95de967a7fe6a773b2"
GETH_BUILD: 1.10.26-e5eb32ac

jobs:
tests:
Expand All @@ -36,9 +37,9 @@ jobs:
- name: Install geth
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
Expand Down Expand Up @@ -79,9 +80,9 @@ jobs:
- name: Install geth
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
Expand Down Expand Up @@ -201,9 +202,9 @@ jobs:
- name: Install geth (for state overrides example)
run: |
mkdir -p "$HOME/bin"
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz
tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz
mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth
wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_BUILD.tar.gz
tar -xvf geth-linux-amd64-$GETH_BUILD.tar.gz
mv geth-linux-amd64-$GETH_BUILD/geth $HOME/bin/geth
chmod u+x "$HOME/bin/geth"
export PATH=$HOME/bin:$PATH
geth version
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@

### Unreleased

- Add a subset of the `admin` namespace
[1880](https://github.com/gakonst/ethers-rs/pull/1880)
- Return String for net version
[1376](https://github.com/gakonst/ethers-rs/pull/1376)
- Stream of paginated logs that load logs in small pages
Expand Down
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ethers-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tiny-keccak = { version = "2.0.2", default-features = false }
# misc
chrono = { version = "0.4", default-features = false }
serde = { version = "1.0.124", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.64", default-features = false }
serde_json = { version = "1.0.64", default-features = false, features = ["arbitrary_precision"] }
thiserror = { version = "1.0", default-features = false }
bytes = { version = "1.3.0", features = ["serde"] }
hex = { version = "0.4.3", default-features = false, features = ["std"] }
Expand Down
22 changes: 2 additions & 20 deletions ethers-core/src/types/fee.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::str::FromStr;

use crate::types::U256;
use serde::{de::Deserializer, Deserialize, Serialize};
use crate::{types::U256, utils::from_int_or_hex};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
Expand All @@ -19,19 +17,3 @@ pub struct FeeHistory {
#[serde(default)]
pub reward: Vec<Vec<U256>>,
}

fn from_int_or_hex<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum IntOrHex {
Int(u64),
Hex(String),
}
match IntOrHex::deserialize(deserializer)? {
IntOrHex::Int(n) => Ok(U256::from(n)),
IntOrHex::Hex(s) => U256::from_str(s.as_str()).map_err(serde::de::Error::custom),
}
}
170 changes: 170 additions & 0 deletions ethers-core/src/utils/genesis.rs
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,
}
Loading