Skip to content

Commit

Permalink
refactor: chain-specific N-API (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann authored Aug 29, 2024
1 parent 226295c commit 2a19726
Show file tree
Hide file tree
Showing 69 changed files with 4,751 additions and 5,589 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-wasps-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": minor
---

Replaces the Provider constructor with an API for registering and creating chain-specific providers in the EdrContext
51 changes: 25 additions & 26 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions book/src/04_multichain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Multi-chain

EDR supports multiple Ethereum chains. This chapter explores how to add your own chain to EDR & Hardhat.
35 changes: 35 additions & 0 deletions book/src/04_multichain/01_chain_spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Chain Specification

EDR uses a concept called _chain specification_ to define all necessary types and functionality to support an Ethereum chain at compile-time.

This is achieved through the usage of multiple traits, some of which are supertraits of each other, providing increasing scope of functionality in the EDR ecosystem:

- Revm primitives: `revm_primitives::EvmWiring`
- Implements the main trait for implementing associated chain-specific primitive types.
- Revm: `revm::EvmWiring`
- Adds an additional function to `revm_primitives::EvmWiring` that depends on the `Evm`.
- Header builder: `edr_eth::EthHeaderConstants`
- RPC client: `edr_rpc_eth::RpcSpec`
- EVM runtime: `edr_evm::ChainSpec`
- EVM provider: `edr_provider::ProviderSpec`
- EDR N-API bindings: `edr_napi::SyncNapiSpec`

Most of these traits have a `Sync*` equivalent (e.g. `SyncChainSpec`) which is automatically implemented for types that are `Send` and `Sync`.

## Supported Chain Types

Currently, EDR supports the following chain types out-of-the-box.

- L1 Ethereum
- Optimism

## Adding your own Chain Type

To add a new chain type, add a new unit struct. E.g.

```rs
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, RlpEncodable)]
pub struct GenericChainSpec;
```

Depending on which functionality you want to support for your chain type, you can implement some or all of the traits outlined [above](#chain-specification).
4 changes: 4 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@

- [Release](./03_release.md)

- [Multi-chain](./04_multichain.md)

- [Chain Specification](04_multichain/01_chain_spec.md)

- [Contributing](./99_contributing.md)
8 changes: 4 additions & 4 deletions crates/edr_eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ itertools = { version = "0.10.5", default-features = false, features = ["use_all
k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", ] }
log = { version = "0.4.17", default-features = false }
once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] }
revm = { git = "https://github.com/Wodann/revm", rev = "6d479da", version = "12.1", default-features = false, features = ["c-kzg", "dev", "serde"] }
revm-primitives = { git = "https://github.com/Wodann/revm", rev = "6d479da", version = "7.1", default-features = false, features = ["c-kzg", "hashbrown"] }
serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true }
revm = { git = "https://github.com/Wodann/revm", rev = "a500675", version = "12.1", default-features = false, features = ["c-kzg", "dev", "serde"] }
revm-primitives = { git = "https://github.com/Wodann/revm", rev = "a500675", version = "7.1", default-features = false, features = ["c-kzg", "hashbrown"] }
serde = { version = "1.0.209", default-features = false, features = ["derive"], optional = true }
sha2 = { version = "0.10.8", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
thiserror = { version = "1.0.37", default-features = false }
Expand All @@ -34,7 +34,7 @@ edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
edr_test_utils = { version = "0.3.5", path = "../edr_test_utils" }
lazy_static = "1.4.0"
paste = { version = "1.0.14", default-features = false }
serde_json = { version = "1.0.89" }
serde_json = { version = "1.0.127" }
serial_test = "2.0.0"
tempfile = { version = "3.7.1", default-features = false }
tokio = { version = "1.23.0", features = ["macros"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/edr_eth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ pub use c_kzg::{Blob, Bytes48, BYTES_PER_BLOB, BYTES_PER_COMMITMENT, BYTES_PER_P
pub use revm_primitives::{
address,
alloy_primitives::{Bloom, BloomInput, ChainId, B512, B64, U128, U160, U64, U8},
bytes, db, env, hex, hex_literal, result, AccessList, AccessListItem, AccountInfo, Address,
Bytecode, Bytes, HashMap, HashSet, Precompile, SpecId, B256, KECCAK_EMPTY, MAX_INITCODE_SIZE,
U256,
bytes, db, env, hex, hex_literal, result, specification, AccessList, AccessListItem,
AccountInfo, Address, Bytecode, Bytes, HashMap, HashSet, Precompile, SpecId, B256,
KECCAK_EMPTY, MAX_INITCODE_SIZE, U256,
};

pub use self::block_spec::{BlockSpec, BlockTag, Eip1898BlockSpec, PreEip1898BlockSpec};
Expand Down
6 changes: 3 additions & 3 deletions crates/edr_evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ parking_lot = { version = "0.12.1", default-features = false }
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["rand", "serde"] }
edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
revm = { git = "https://github.com/Wodann/revm", rev = "6d479da", version = "12.1", default-features = false, features = ["c-kzg", "dev", "serde", "std"] }
revm = { git = "https://github.com/Wodann/revm", rev = "a500675", version = "12.1", default-features = false, features = ["c-kzg", "dev", "serde", "std"] }
rpds = { version = "1.1.0", default-features = false, features = ["std"] }
serde = { version = "1.0.158", default-features = false, features = ["std"] }
serde_json = { version = "1.0.94", default-features = false, features = ["std"] }
serde = { version = "1.0.209", default-features = false, features = ["std"] }
serde_json = { version = "1.0.127", default-features = false, features = ["std"] }
thiserror = { version = "1.0.38", default-features = false }
tokio = { version = "1.21.2", default-features = false, features = ["macros", "rt-multi-thread", "sync"] }
tracing = { version = "0.1.37", features = ["attributes", "std"], optional = true }
Expand Down
26 changes: 11 additions & 15 deletions crates/edr_napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@ crate-type = ["cdylib"]

[dependencies]
ansi_term = { version = "0.12.1", default-features = false }
crossbeam-channel = { version = "0.5.6", default-features = false }
derive-where = { version = "1.2.7", default-features = false }
edr_eth = { path = "../edr_eth" }
edr_evm = { path = "../edr_evm" }
edr_napi_core = { path = "../edr_napi_core" }
edr_provider = { path = "../edr_provider" }
edr_rpc_client = { path = "../edr_rpc_client" }
itertools = { version = "0.12.0", default-features = false }
k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", "precomputed-tables", "std"] }
log = { version = "0.4.20", default-features = false }
mimalloc = { version = "0.1.39", default-features = false, features = ["local_dynamic_tls"] }
# when napi is pinned, be sure to pin napi-derive to the same version
# The `async` feature ensures that a tokio runtime is available
napi = { version = "2.16.0", default-features = false, features = ["async", "error_anyhow", "napi8", "serde-json"] }
napi-derive = "2.16.0"
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_evm = { version = "0.3.5", path = "../edr_evm", features = ["tracing"]}
edr_eth = { version = "0.3.5", path = "../edr_eth" }
edr_provider = { version = "0.3.5", path = "../edr_provider" }
edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] }
rand = { version = "0.8.4", optional = true }
serde = { version = "1.0.209", features = ["derive"] }
serde_json = { version = "1.0.127" }
thiserror = { version = "1.0.37", default-features = false }
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
tracing-flame = { version = "0.2.0", default-features = false, features = ["smallvec"] }
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["ansi", "env-filter", "fmt", "parking_lot", "smallvec", "std"] }
parking_lot = { version = "0.12.1", default-features = false }
lazy_static = { version = "1.4.0", features = [] }
rand = { version = "0.8.4", optional = true }
serde = { version = "1.0.189", features = ["derive"] }
mimalloc = { version = "0.1.39", default-features = false, features = ["local_dynamic_tls"] }

[target.x86_64-unknown-linux-gnu.dependencies]
openssl-sys = { version = "0.9.93", features = ["vendored"] }
Expand All @@ -48,7 +44,7 @@ openssl-sys = { version = "0.9.93", features = ["vendored"] }
napi-build = "2.0.1"

[features]
tracing = ["edr_evm/tracing", "edr_provider/tracing"]
tracing = ["edr_evm/tracing", "edr_napi_core/tracing", "edr_provider/tracing"]
scenarios = ["rand"]

[profile.release]
Expand Down
Loading

0 comments on commit 2a19726

Please sign in to comment.