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

refactor(rpc): add rpc crate #375

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
75 changes: 52 additions & 23 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/builder",
"crates/pool",
"crates/provider",
"crates/rpc",
"crates/sim",
"crates/task",
"crates/types",
Expand Down
1 change: 1 addition & 0 deletions bin/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Rundler tools

[dependencies]
rundler-rundler = { path = "../../crates/rundler" }
rundler-rpc = { path = "../../crates/rpc" }

anyhow = "1.0.70"
clap = { version = "4.2.4", features = ["derive", "env"] }
Expand Down
3 changes: 2 additions & 1 deletion bin/tools/src/bin/get_example_ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dotenv::dotenv;
use rundler_rundler::{common::dev::DevClients, rpc::RpcUserOperation};
use rundler_rpc::RpcUserOperation;
use rundler_rundler::common::dev::DevClients;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions bin/tools/src/bin/send_ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dotenv::dotenv;
use rundler_rundler::common::{dev::DevClients, eth};
use rundler_rundler::common::{dev, dev::DevClients};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand All @@ -17,7 +17,7 @@ async fn main() -> anyhow::Result<()> {
println!("Sending op {i}");
let op = clients.new_wallet_op(wallet.nonce(), 0.into()).await?;
let call = entry_point.handle_ops(vec![op], bundler_client.address());
eth::await_mined_tx(call.send(), "send user operation").await?;
dev::await_mined_tx(call.send(), "send user operation").await?;
}

Ok(())
Expand Down
31 changes: 31 additions & 0 deletions crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "rundler-rpc"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
rundler-builder = { path = "../builder" }
rundler-pool = { path = "../pool" }
rundler-provider = { path = "../provider" }
rundler-sim = { path = "../sim" }
rundler-task = { path = "../task" }
rundler-types = { path = "../types" }
rundler-utils = { path = "../utils" }

anyhow.workspace = true
async-trait.workspace = true
ethers.workspace = true
jsonrpsee = { version = "0.20.0", features = ["client", "macros", "server"] }
metrics.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-util.workspace = true
tonic.workspace = true
tower.workspace = true
tracing.workspace = true
serde.workspace = true
strum.workspace = true
url.workspace = true
19 changes: 15 additions & 4 deletions crates/rundler/src/rpc/debug.rs → crates/rpc/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
use async_trait::async_trait;
use ethers::types::{Address, H256};
use jsonrpsee::{core::RpcResult, proc_macros::rpc, types::error::INTERNAL_ERROR_CODE};
use rundler_builder::{BuilderServer, BundlingMode};
use rundler_pool::PoolServer;
use tonic::async_trait;

use super::{rpc_err, RpcReputation, RpcUserOperation};
use crate::{
error::rpc_err,
types::{RpcReputation, RpcUserOperation},
};

/// Debug API
#[rpc(client, server, namespace = "debug")]
pub trait DebugApi {
/// Clears the state of the pool.
#[method(name = "bundler_clearState")]
async fn bundler_clear_state(&self) -> RpcResult<String>;

/// Dumps the mempool.
#[method(name = "bundler_dumpMempool")]
async fn bundler_dump_mempool(&self, entry_point: Address) -> RpcResult<Vec<RpcUserOperation>>;

/// Triggers the builder to send a bundle now
///
/// Note that the bundling mode must be set to `Manual` else this will fail.
#[method(name = "bundler_sendBundleNow")]
async fn bundler_send_bundle_now(&self) -> RpcResult<H256>;

/// Sets the bundling mode.
#[method(name = "bundler_setBundlingMode")]
async fn bundler_set_bundling_mode(&self, mode: BundlingMode) -> RpcResult<String>;

/// Sets the reputations of entities on the given entry point.
#[method(name = "bundler_setReputation")]
async fn bundler_set_reputation(
&self,
reputations: Vec<RpcReputation>,
entry_point: Address,
) -> RpcResult<String>;

/// Dumps the reputations of entities from the given entry point.
#[method(name = "bundler_dumpReputation")]
async fn bundler_dump_reputation(&self, entry_point: Address) -> RpcResult<Vec<RpcReputation>>;
}

pub struct DebugApi<P, B> {
pub(crate) struct DebugApi<P, B> {
pool: P,
builder: B,
}

impl<P, B> DebugApi<P, B> {
pub fn new(pool: P, builder: B) -> Self {
pub(crate) fn new(pool: P, builder: B) -> Self {
Self { pool, builder }
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/rpc/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use jsonrpsee::types::{ErrorObject, ErrorObjectOwned};
use serde::Serialize;

pub(crate) fn rpc_err(code: i32, msg: impl Into<String>) -> ErrorObjectOwned {
create_rpc_err(code, msg, None::<()>)
}

pub(crate) fn rpc_err_with_data<S: Serialize>(
code: i32,
msg: impl Into<String>,
data: S,
) -> ErrorObjectOwned {
create_rpc_err(code, msg, Some(data))
}

fn create_rpc_err<S: Serialize>(
code: i32,
msg: impl Into<String>,
data: Option<S>,
) -> ErrorObjectOwned {
ErrorObject::owned(code, msg.into(), data)
}
Loading
Loading