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: add Optimism as separate N-API package #659

Draft
wants to merge 4 commits into
base: feat/multichain
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ gen-execution-api = "run --bin tools -- gen-execution-api"
scenario = "run --release --bin tools -- scenario"
scenario-with-tracing = "run --release --features tracing --bin tools -- scenario"
replay-block = "run --release --bin tools -- replay-block"

# To be able to run unit tests on Linux, support compilation to 'x86_64-unknown-linux-gnu'.
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"]
1 change: 0 additions & 1 deletion .github/workflows/edr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
workflow_dispatch:

env:
RUSTFLAGS: -Dwarnings
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not have any adverse side-effects, as we also manually pass this argument to cargo clippy which should fail if there are any warnings.

For reference:

cargo clippy --workspace --all-targets --all-features -- -D warnings

RUSTDOCFLAGS: -Dwarnings

concurrency:
Expand Down
28 changes: 25 additions & 3 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/edr_napi/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ target-dir = "./target"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]

# To be able to run unit tests on Linux, support compilation to 'x86_64-unknown-linux-gnu'.
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"]
10 changes: 2 additions & 8 deletions crates/edr_napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ version = "0.3.5"
edition = "2021"

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for edr_napi_optimism to use this crate as a dependency


[dependencies]
ansi_term = { version = "0.12.1", default-features = false }
derive-where = { version = "1.2.7", default-features = false }
edr_eth = { path = "../edr_eth" }
edr_evm = { path = "../edr_evm" }
edr_generic = { path = "../edr_generic" }
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 }
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
Expand All @@ -24,7 +22,6 @@ napi-derive = "2.16.0"
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"] }
Expand All @@ -45,11 +42,8 @@ openssl-sys = { version = "0.9.93", features = ["vendored"] }
napi-build = "2.0.1"

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

[profile.release]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo was reporting that this setting was ignored. Only the workspace Cargo.toml's profile are respected.

lto = true
tracing = ["edr_evm/tracing", "edr_napi_core/tracing", "edr_provider/tracing"]

[lints]
workspace = true
16 changes: 8 additions & 8 deletions crates/edr_napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ export class EdrContext {
registerProviderFactory(chainType: string, factory: ProviderFactory): Promise<void>
}
export class ProviderFactory { }
export class Response {
/**Returns the response data as a JSON string or a JSON object. */
get data(): string | any
/**Returns the Solidity trace of the transaction that failed to execute, if any. */
get solidityTrace(): RawTrace | null
/**Returns the raw traces of executed contracts. This maybe contain zero or more traces. */
get traces(): Array<RawTrace>
}
/** A JSON-RPC provider for Ethereum. */
export class Provider {
/**Handles a JSON-RPC request and returns a JSON-RPC response. */
Expand All @@ -450,14 +458,6 @@ export class Provider {
*/
setVerboseTracing(verboseTracing: boolean): Promise<void>
}
export class Response {
/**Returns the response data as a JSON string or a JSON object. */
get data(): string | any
/**Returns the Solidity trace of the transaction that failed to execute, if any. */
get solidityTrace(): RawTrace | null
/**Returns the raw traces of executed contracts. This maybe contain zero or more traces. */
get traces(): Array<RawTrace>
}
export class RawTrace {
trace(): Array<TracingMessage | TracingStep | TracingMessageResult>
}
4 changes: 2 additions & 2 deletions crates/edr_napi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { MineOrdering, EdrContext, GENERIC_CHAIN_TYPE, genericChainProviderFactory, L1_CHAIN_TYPE, l1ProviderFactory, SpecId, FRONTIER, FRONTIER_THAWING, HOMESTEAD, DAO_FORK, TANGERINE, SPURIOUS_DRAGON, BYZANTIUM, CONSTANTINOPLE, PETERSBURG, ISTANBUL, MUIR_GLACIER, BERLIN, LONDON, ARROW_GLACIER, GRAY_GLACIER, MERGE, SHANGHAI, CANCUN, PRAGUE, PRAGUE_EOF, LATEST, ProviderFactory, Provider, SuccessReason, ExceptionalHalt, Response, RawTrace } = nativeBinding
const { MineOrdering, EdrContext, GENERIC_CHAIN_TYPE, genericChainProviderFactory, L1_CHAIN_TYPE, l1ProviderFactory, SpecId, FRONTIER, FRONTIER_THAWING, HOMESTEAD, DAO_FORK, TANGERINE, SPURIOUS_DRAGON, BYZANTIUM, CONSTANTINOPLE, PETERSBURG, ISTANBUL, MUIR_GLACIER, BERLIN, LONDON, ARROW_GLACIER, GRAY_GLACIER, MERGE, SHANGHAI, CANCUN, PRAGUE, PRAGUE_EOF, LATEST, ProviderFactory, Response, Provider, SuccessReason, ExceptionalHalt, RawTrace } = nativeBinding

module.exports.MineOrdering = MineOrdering
module.exports.EdrContext = EdrContext
Expand Down Expand Up @@ -341,8 +341,8 @@ module.exports.PRAGUE = PRAGUE
module.exports.PRAGUE_EOF = PRAGUE_EOF
module.exports.LATEST = LATEST
module.exports.ProviderFactory = ProviderFactory
module.exports.Response = Response
module.exports.Provider = Provider
module.exports.SuccessReason = SuccessReason
module.exports.ExceptionalHalt = ExceptionalHalt
module.exports.Response = Response
module.exports.RawTrace = RawTrace
2 changes: 1 addition & 1 deletion crates/edr_napi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"build:debug": "napi build --platform",
"build:tracing": "napi build --platform --release --features tracing",
"build:scenarios": "napi build --platform --release --features scenarios",
"prepublishOnly": "bash scripts/prepublish.sh",
"prepublishOnly": "bash ../../scripts/prepublish.sh",
"universal": "napi universal",
"version": "napi version",
"pretest": "pnpm build",
Expand Down
19 changes: 7 additions & 12 deletions crates/edr_napi/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{io, sync::Arc};

use edr_eth::HashMap;
use edr_napi_core::provider::{self, SyncProviderFactory};
use napi::{
tokio::{runtime, sync::Mutex as AsyncMutex},
Env, JsObject, Status,
Expand All @@ -11,7 +12,7 @@ use tracing_subscriber::{prelude::*, EnvFilter, Registry};
use crate::{
config::ProviderConfig,
logger::LoggerConfig,
provider::{factory::SyncProviderFactory, Provider, ProviderFactory},
provider::{Provider, ProviderFactory},
subscription::SubscriptionConfig,
};

Expand Down Expand Up @@ -44,6 +45,7 @@ impl EdrContext {
subscription_config: SubscriptionConfig,
) -> napi::Result<JsObject> {
let provider_config = edr_napi_core::provider::Config::try_from(provider_config)?;
let logger_config = logger_config.resolve(&env)?;

#[cfg(feature = "scenarios")]
let scenario_file =
Expand All @@ -61,7 +63,7 @@ impl EdrContext {
&chain_type,
provider_config,
logger_config,
subscription_config,
subscription_config.into(),
)?
};

Expand Down Expand Up @@ -153,17 +155,10 @@ impl Context {
env: &napi::Env,
chain_type: &str,
provider_config: edr_napi_core::provider::Config,
logger_config: LoggerConfig,
subscription_config: SubscriptionConfig,
) -> napi::Result<Box<dyn crate::provider::Builder>> {
logger_config: edr_napi_core::logger::Config,
subscription_config: edr_napi_core::subscription::Config,
) -> napi::Result<Box<dyn provider::Builder>> {
if let Some(factory) = self.provider_factories.get(chain_type) {
// #[cfg(feature = "scenarios")]
// let scenario_file = crate::scenarios::scenario_file(
// &config,
// edr_provider::Logger::is_enabled(&*logger),
// )
// .await?;

factory.create_provider_builder(
env,
provider_config,
Expand Down
23 changes: 12 additions & 11 deletions crates/edr_napi/src/generic_chain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::sync::Arc;

use edr_generic::GenericChainSpec;
use edr_napi_core::{
logger::{self, Logger},
provider::{self, ProviderBuilder, SyncProviderFactory},
spec::SyncNapiSpec as _,
subscription,
};
use napi_derive::napi;

use crate::{
logger::{Logger, LoggerConfig},
provider::{self, factory::SyncProviderFactory, ProviderBuilder, ProviderFactory},
spec::SyncNapiSpec,
subscription::{SubscriptionCallback, SubscriptionConfig},
};
use crate::provider::ProviderFactory;

pub struct GenericChainProviderFactory;

Expand All @@ -17,19 +18,19 @@ impl SyncProviderFactory for GenericChainProviderFactory {
&self,
env: &napi::Env,
provider_config: edr_napi_core::provider::Config,
logger_config: LoggerConfig,
subscription_config: SubscriptionConfig,
logger_config: logger::Config,
subscription_config: subscription::Config,
) -> napi::Result<Box<dyn provider::Builder>> {
let logger = Logger::<GenericChainSpec>::new(env, logger_config)?;
let logger = Logger::<GenericChainSpec>::new(logger_config)?;

let provider_config =
edr_provider::ProviderConfig::<GenericChainSpec>::from(provider_config);

let subscription_callback =
SubscriptionCallback::new(env, subscription_config.subscription_callback)?;
subscription::Callback::new(env, subscription_config.subscription_callback)?;

Ok(Box::new(ProviderBuilder::new(
logger,
Box::new(logger),
provider_config,
subscription_callback,
)))
Expand Down
23 changes: 12 additions & 11 deletions crates/edr_napi/src/l1.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::sync::Arc;

use edr_eth::{chain_spec::L1ChainSpec, specification};
use edr_napi_core::{
logger::Logger,
provider::{self, ProviderBuilder, SyncProviderFactory},
spec::SyncNapiSpec as _,
subscription,
};
use napi_derive::napi;

use crate::{
logger::{Logger, LoggerConfig},
provider::{self, factory::SyncProviderFactory, ProviderBuilder, ProviderFactory},
spec::SyncNapiSpec,
subscription::{SubscriptionCallback, SubscriptionConfig},
};
use crate::provider::ProviderFactory;

pub struct L1ProviderFactory;

Expand All @@ -17,18 +18,18 @@ impl SyncProviderFactory for L1ProviderFactory {
&self,
env: &napi::Env,
provider_config: edr_napi_core::provider::Config,
logger_config: LoggerConfig,
subscription_config: SubscriptionConfig,
logger_config: edr_napi_core::logger::Config,
subscription_config: edr_napi_core::subscription::Config,
) -> napi::Result<Box<dyn provider::Builder>> {
let logger = Logger::<L1ChainSpec>::new(env, logger_config)?;
let logger = Logger::<L1ChainSpec>::new(logger_config)?;

let provider_config = edr_provider::ProviderConfig::<L1ChainSpec>::from(provider_config);

let subscription_callback =
SubscriptionCallback::new(env, subscription_config.subscription_callback)?;
subscription::Callback::new(env, subscription_config.subscription_callback)?;

Ok(Box::new(ProviderBuilder::new(
logger,
Box::new(logger),
provider_config,
subscription_callback,
)))
Expand Down
2 changes: 0 additions & 2 deletions crates/edr_napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub mod result;
/// Types relating to benchmark scenarios.
#[cfg(feature = "scenarios")]
pub mod scenarios;
/// Types for N-API-related chain specification.
pub mod spec;
/// Types for subscribing to events.
pub mod subscription;
/// Types for EVM traces.
Expand Down
Loading
Loading