Skip to content

Commit

Permalink
feat: extract wallet api to own service
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Nov 26, 2024
1 parent 552ca9a commit 7b0a5fb
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 115 deletions.
26 changes: 21 additions & 5 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"bin/odyssey/",
"bin/relay/",
"crates/node",
"crates/e2e-tests",
"crates/wallet",
Expand Down Expand Up @@ -148,6 +149,7 @@ alloy-consensus = "0.6.4"
alloy-eips = "0.6.4"
alloy-network = "0.6.4"
alloy-primitives = "0.8.11"
alloy-provider = "0.6.4"
alloy-rpc-types = "0.6.4"
alloy-signer-local = { version = "0.6.4", features = ["mnemonic"] }

Expand All @@ -159,7 +161,6 @@ reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211a
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
Expand All @@ -185,7 +186,6 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aa
"optimism",
] }
reth-revm = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
Expand Down
1 change: 0 additions & 1 deletion bin/odyssey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ alloy-signer-local.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
odyssey-node.workspace = true
odyssey-wallet.workspace = true
odyssey-walltime.workspace = true
eyre.workspace = true
tracing.workspace = true
Expand Down
37 changes: 1 addition & 36 deletions bin/odyssey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
//! - `min-debug-logs`: Disables all logs below `debug` level.
//! - `min-trace-logs`: Disables all logs below `trace` level.
use alloy_network::EthereumWallet;
use alloy_primitives::Address;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
use odyssey_node::{chainspec::OdysseyChainSpecParser, node::OdysseyNode};
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer};
use odyssey_walltime::{OdysseyWallTime, OdysseyWallTimeRpcApiServer};
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth_optimism_cli::Cli;
use reth_optimism_node::{args::RollupArgs, node::OpAddOns};
use reth_provider::{providers::BlockchainProvider2, CanonStateSubscriptions};
use tracing::{info, warn};
use tracing::info;

#[global_allocator]
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();
Expand All @@ -56,36 +51,6 @@ fn main() {
.with_components(OdysseyNode::components(&rollup_args))
.with_add_ons(OpAddOns::new(rollup_args.sequencer_http))
.extend_rpc_modules(move |ctx| {
// register odyssey wallet namespace
if let Ok(sk) = std::env::var("EXP1_SK") {
let signer: PrivateKeySigner =
sk.parse().wrap_err("Invalid EXP0001 secret key.")?;
let wallet = EthereumWallet::from(signer);

let raw_delegations = std::env::var("EXP1_WHITELIST")
.wrap_err("No EXP0001 delegations specified")?;
let valid_delegations: Vec<Address> = raw_delegations
.split(',')
.map(|addr| Address::parse_checksummed(addr, None))
.collect::<Result<_, _>>()
.wrap_err("No valid EXP0001 delegations specified")?;

ctx.modules.merge_configured(
OdysseyWallet::new(
ctx.provider().clone(),
wallet,
ctx.registry.eth_api().clone(),
ctx.config().chain.chain().id(),
valid_delegations,
)
.into_rpc(),
)?;

info!(target: "reth::cli", "EXP0001 wallet configured");
} else {
warn!(target: "reth::cli", "EXP0001 wallet not configured");
}

let walltime = OdysseyWallTime::spawn(ctx.provider().canonical_state_stream());
ctx.modules.merge_configured(walltime.into_rpc())?;
info!(target: "reth::cli", "Walltime configured");
Expand Down
45 changes: 45 additions & 0 deletions bin/relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "odyssey-relay"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true
description = "Odyssey Relay is an EIP-7702 native transaction batcher and sponsor."

[lints]
workspace = true

[dependencies]
alloy-signer-local.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
odyssey-node.workspace = true
odyssey-wallet.workspace = true
odyssey-walltime.workspace = true
eyre.workspace = true
tracing.workspace = true
reth-cli-util.workspace = true
reth-node-builder.workspace = true
reth-optimism-node.workspace = true
reth-optimism-cli.workspace = true
reth-provider.workspace = true
clap = { workspace = true, features = ["derive"] }

[features]
default = ["jemalloc"]

asm-keccak = ["reth-optimism-cli/asm-keccak"]

jemalloc = ["reth-cli-util/jemalloc"]
jemalloc-prof = ["jemalloc", "reth-cli-util/jemalloc-prof"]

min-error-logs = ["tracing/release_max_level_error"]
min-warn-logs = ["tracing/release_max_level_warn"]
min-info-logs = ["tracing/release_max_level_info"]
min-debug-logs = ["tracing/release_max_level_debug"]
min-trace-logs = ["tracing/release_max_level_trace"]

[[bin]]
name = "odyssey"
path = "src/main.rs"
37 changes: 37 additions & 0 deletions bin/relay/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! # Odyssey Relay
//!
//! TBD
use alloy_signer_local::PrivateKeySigner;
use eyre::Context;

fn run() -> eyre::Result<()> {
let signer: PrivateKeySigner = std::env::var("RELAY_SK")
.wrap_err("Environment variable `RELAY_SK` must be set")
.and_then(|sk| sk.parse().wrap_err("Invalid signing key set in `RELAY_SK`"))?;

Ok(())
}

struct Cli {
port: u16,
upstream: Vec<String>, // todo make url
constraints: Constraints,
}

struct Constraints {
max_gas: u64,
}

#[doc(hidden)]
fn main() {
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}

if let Err(err) = run() {
eprint!("Error: {err:?}");
std::process::exit(1);
}
}
6 changes: 1 addition & 5 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
alloy-eips.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-types.workspace = true

reth-storage-api.workspace = true
reth-rpc-eth-api.workspace = true
reth-optimism-rpc.workspace = true

revm-primitives.workspace = true

jsonrpsee = { workspace = true, features = ["server", "macros"] }
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
Expand Down
Loading

0 comments on commit 7b0a5fb

Please sign in to comment.