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 Dec 9, 2024
1 parent e6aac10 commit a35e85d
Show file tree
Hide file tree
Showing 9 changed files with 431 additions and 166 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
merge_group:
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

Expand All @@ -30,29 +30,29 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install Kurtosis
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli
- name: Build Odyssey
run: |
cargo build --profile release --locked --bin odyssey &&
mkdir dist/ &&
cp ./target/release/odyssey dist/odyssey &&
docker buildx build . --load -f .github/assets/Dockerfile -t ghcr.io/ithacaxyz/odyssey:latest
cargo build --profile release --locked --bin odyssey &&
mkdir dist/ &&
cp ./target/release/odyssey dist/odyssey &&
docker buildx build . --load -f .github/assets/Dockerfile -t ghcr.io/ithacaxyz/odyssey:latest
- name: Run enclave
id: kurtosis
run: |
kurtosis engine start
kurtosis run --enclave op-devnet github.com/ethpandaops/optimism-package --args-file ./etc/kurtosis.yaml
ENCLAVE_ID=$(curl http://127.0.0.1:9779/api/enclaves | jq --raw-output 'keys[0]')
SEQUENCER_EL_PORT=$(curl "http://127.0.0.1:9779/api/enclaves/$ENCLAVE_ID/services" | jq '."op-el-1-op-reth-op-node-op-kurtosis".public_ports.rpc.number')
REPLICA_EL_PORT=$(curl "http://127.0.0.1:9779/api/enclaves/$ENCLAVE_ID/services" | jq '."op-el-2-op-reth-op-node-op-kurtosis".public_ports.rpc.number')
echo "SEQUENCER_RPC=http://127.0.0.1:$SEQUENCER_EL_PORT" >> $GITHUB_ENV
echo "REPLICA_RPC=http://127.0.0.1:$REPLICA_EL_PORT" >> $GITHUB_ENV
kurtosis engine start
kurtosis run --enclave op-devnet github.com/ethpandaops/optimism-package --args-file ./etc/kurtosis.yaml
ENCLAVE_ID=$(curl http://127.0.0.1:9779/api/enclaves | jq --raw-output 'keys[0]')
SEQUENCER_EL_PORT=$(curl "http://127.0.0.1:9779/api/enclaves/$ENCLAVE_ID/services" | jq '."op-el-1-op-reth-op-node-op-kurtosis".public_ports.rpc.number')
REPLICA_EL_PORT=$(curl "http://127.0.0.1:9779/api/enclaves/$ENCLAVE_ID/services" | jq '."op-el-2-op-reth-op-node-op-kurtosis".public_ports.rpc.number')
echo "SEQUENCER_RPC=http://127.0.0.1:$SEQUENCER_EL_PORT" >> $GITHUB_ENV
echo "REPLICA_RPC=http://127.0.0.1:$REPLICA_EL_PORT" >> $GITHUB_ENV
- name: Run E2E tests
run: |
cargo nextest run \
--locked \
--workspace \
-E "package(odyssey-e2e-tests)"
cargo nextest run \
--locked \
--workspace \
-E "package(odyssey-e2e-tests)"
25 changes: 23 additions & 2 deletions Cargo.lock

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

32 changes: 22 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[workspace]
members = [
"bin/odyssey/",
"bin/relay/",
"crates/common",
"crates/node",
"crates/e2e-tests",
"crates/wallet",
"crates/walltime",
]
default-members = ["bin/odyssey/"]
default-members = ["bin/odyssey/", "bin/relay/"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -150,22 +151,24 @@ 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-client = { version = "0.6.4", default-features = false }
alloy-rpc-types = "0.6.4"
alloy-rpc-types-eth = "0.6.4"
alloy-signer-local = { version = "0.6.4", features = ["mnemonic"] }
alloy-transport = "0.6.4"
alloy-transport-http = { version = "0.6.4", default-features = false, features = [
"reqwest",
"reqwest-rustls-tls",
] }
reqwest = { version = "0.12.9", default-features = false, features = [
"rustls-tls",
] }

# tokio
tokio = { version = "1.21", default-features = false }

# reth
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-errors = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }

reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9", features = [
"optimism",
] }
Expand Down Expand Up @@ -218,6 +221,15 @@ serde = "1"
serde_json = "1"
thiserror = "1"
futures = "0.3"
url = "2.5"

# misc-testing
rstest = "0.18.2"
reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-errors = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-evm = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "38cf6c9" }
2 changes: 2 additions & 0 deletions bin/odyssey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ workspace = true
alloy-signer-local.workspace = true
alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
odyssey-node.workspace = true
odyssey-wallet.workspace = true
odyssey-walltime.workspace = true
Expand Down
10 changes: 6 additions & 4 deletions bin/odyssey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use odyssey_node::{
node::OdysseyNode,
rpc::{EthApiExt, EthApiOverrideServer},
};
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer};
use odyssey_wallet::{OdysseyWallet, OdysseyWalletApiServer, RethNode};
use odyssey_walltime::{OdysseyWallTime, OdysseyWallTimeRpcApiServer};
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher, NodeComponents};
use reth_optimism_cli::Cli;
Expand Down Expand Up @@ -92,9 +92,11 @@ fn main() {
if let Some(wallet) = wallet {
ctx.modules.merge_configured(
OdysseyWallet::new(
ctx.provider().clone(),
wallet,
ctx.registry.eth_api().clone(),
RethNode::new(
ctx.provider().clone(),
ctx.registry.eth_api().clone(),
wallet,
),
ctx.config().chain.chain().id(),
)
.into_rpc(),
Expand Down
37 changes: 37 additions & 0 deletions bin/relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[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-primitives.workspace = true
alloy-provider.workspace = true
alloy-rpc-client.workspace = true
odyssey-wallet.workspace = true
eyre.workspace = true
jsonrpsee = { workspace = true, features = ["server"] }
tracing.workspace = true
reth-tracing.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
url.workspace = true
tokio = { workspace = true, features = ["rt", "macros"] }

[features]
default = []
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 = "relay"
path = "src/main.rs"
75 changes: 75 additions & 0 deletions bin/relay/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! # Odyssey Relay
//!
//! TBD
use alloy_provider::{network::EthereumWallet, Provider, ProviderBuilder};
use alloy_rpc_client::RpcClient;
use alloy_signer_local::PrivateKeySigner;
use clap::Parser;
use eyre::Context;
use jsonrpsee::server::Server;
use odyssey_wallet::{AlloyNode, OdysseyWallet, OdysseyWalletApiServer};
use reth_tracing::Tracer;
use std::net::{IpAddr, Ipv4Addr};
use tracing::info;
use url::Url;

/// The Odyssey relayer service sponsors transactions for EIP-7702 accounts.
#[derive(Debug, Parser)]
#[command(author, about = "Relay", long_about = None)]
struct Args {
/// The address to serve the RPC on.
#[arg(long = "http.addr", value_name = "ADDR", default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))]
address: IpAddr,
/// The port to serve the RPC on.
#[arg(long = "http.port", value_name = "PORT", default_value_t = 9119)]
port: u16,
/// The RPC endpoint of the chain to send transactions to.
#[arg(long, value_name = "RPC_ENDPOINT")]
upstream: Url,
/// The secret key to sponsor transactions with.
#[arg(long, value_name = "SECRET_KEY", env = "RELAY_SK")]
secret_key: String,
}

/// Run the relayer service.
async fn run(args: Args) -> eyre::Result<()> {
let _guard = reth_tracing::RethTracer::new().init()?;

// construct provider
let signer: PrivateKeySigner = args.secret_key.parse().wrap_err("Invalid signing key")?;
let wallet = EthereumWallet::from(signer);
let rpc_client = RpcClient::new_http(args.upstream).boxed();
let provider =
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_client(rpc_client);

// get chain id
let chain_id = provider.get_chain_id().await?;

// construct rpc module
let rpc = OdysseyWallet::new(AlloyNode::new(provider), chain_id).into_rpc();

// start server
let server = Server::builder().http_only().build((args.address, args.port)).await?;
info!(addr = ?server.local_addr().unwrap(), "Started relay service");

let handle = server.start(rpc);
handle.stopped().await;

Ok(())
}

#[doc(hidden)]
#[tokio::main]
async 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");
}

let args = Args::parse();
if let Err(err) = run(args).await {
eprint!("Error: {err:?}");
std::process::exit(1);
}
}
10 changes: 5 additions & 5 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ 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
alloy-transport.workspace = true

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

revm-primitives.workspace = true
reth-rpc-eth-api.workspace = true
reth-storage-api.workspace = true

jsonrpsee = { workspace = true, features = ["server", "macros"] }
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
eyre.workspace = true
tracing.workspace = true
tokio = { workspace = true, features = ["sync"] }

Expand Down
Loading

0 comments on commit a35e85d

Please sign in to comment.