Skip to content

Commit

Permalink
feat(rpc): modify rpc to use alloy types
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Sep 30, 2024
1 parent 38c7337 commit e1670fe
Show file tree
Hide file tree
Showing 22 changed files with 462 additions and 399 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

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

32 changes: 32 additions & 0 deletions crates/provider/src/alloy/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file is part of Rundler.
//
// Rundler is free software: you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later version.
//
// Rundler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use alloy_json_rpc::RequestPacket;
/// Method extractor
use rundler_types::task::traits::RequestExtractor;

/// Method extractor for Alloy providers
#[derive(Clone, Copy)]
pub struct AlloyMethodExtractor;

impl RequestExtractor<RequestPacket> for AlloyMethodExtractor {
fn get_method_name(req: &RequestPacket) -> String {
match req {
RequestPacket::Single(request) => request.method().to_string(),
_ => {
// can't extract method name for batch.
"batch".to_string()
}
}
}
}
1 change: 1 addition & 0 deletions crates/provider/src/alloy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

pub(crate) mod entry_point;
pub(crate) mod evm;
pub(crate) mod metrics;
1 change: 1 addition & 0 deletions crates/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub use alloy::{
},
},
evm::AlloyEvmProvider,
metrics::AlloyMethodExtractor,
};

mod traits;
Expand Down
6 changes: 5 additions & 1 deletion crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ repository.workspace = true
publish = false

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

alloy-primitives.workspace = true
alloy-sol-types.workspace = true

anyhow.workspace = true
async-trait.workspace = true
ethers.workspace = true
jsonrpsee = { workspace = true , features = ["client", "macros", "server"] }
metrics.workspace = true
thiserror.workspace = true
Expand All @@ -32,6 +35,7 @@ futures-util.workspace = true

[dev-dependencies]
mockall.workspace = true
alloy-consensus.workspace = true
rundler-provider = { path = "../provider", features = ["test-utils"]}
rundler-sim = { path = "../sim", features = ["test-utils"] }
rundler-types= { path = "../types", features = ["test-utils"]}
4 changes: 2 additions & 2 deletions crates/rpc/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use alloy_primitives::Address;
use anyhow::Context;
use async_trait::async_trait;
use ethers::types::Address;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use rundler_types::pool::Pool;

Expand Down Expand Up @@ -51,7 +51,7 @@ impl<P> AdminApi<P> {
#[async_trait]
impl<P> AdminApiServer for AdminApi<P>
where
P: Pool,
P: Pool + 'static,
{
async fn clear_state(&self, clear_params: RpcAdminClearState) -> RpcResult<String> {
utils::safe_call_rpc_handler(
Expand Down
24 changes: 14 additions & 10 deletions crates/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use alloy_primitives::{Address, B256, U64};
use anyhow::Context;
use async_trait::async_trait;
use ethers::types::{Address, H256};
use futures_util::StreamExt;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use rundler_types::{
Expand Down Expand Up @@ -48,7 +48,7 @@ pub trait DebugApi {
///
/// 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>;
async fn bundler_send_bundle_now(&self) -> RpcResult<B256>;

/// Sets the bundling mode.
#[method(name = "bundler_setBundlingMode")]
Expand Down Expand Up @@ -103,8 +103,8 @@ impl<P, B> DebugApi<P, B> {
#[async_trait]
impl<P, B> DebugApiServer for DebugApi<P, B>
where
P: Pool,
B: Builder,
P: Pool + 'static,
B: Builder + 'static,
{
async fn bundler_clear_state(&self) -> RpcResult<String> {
utils::safe_call_rpc_handler("bundler_clearState", DebugApi::bundler_clear_state(self))
Expand All @@ -127,7 +127,7 @@ where
.await
}

async fn bundler_send_bundle_now(&self) -> RpcResult<H256> {
async fn bundler_send_bundle_now(&self) -> RpcResult<B256> {
utils::safe_call_rpc_handler(
"bundler_sendBundleNow",
DebugApi::bundler_send_bundle_now(self),
Expand Down Expand Up @@ -235,7 +235,7 @@ where
.collect::<Vec<RpcUserOperation>>())
}

async fn bundler_send_bundle_now(&self) -> InternalRpcResult<H256> {
async fn bundler_send_bundle_now(&self) -> InternalRpcResult<B256> {
tracing::debug!("Sending bundle");

let mut new_heads = self
Expand Down Expand Up @@ -318,8 +318,8 @@ where

let reputation = RpcReputationOutput {
address: r.address,
ops_seen: r.ops_seen.into(),
ops_included: r.ops_included.into(),
ops_seen: U64::from(r.ops_seen),
ops_included: U64::from(r.ops_included),
status,
};

Expand All @@ -344,8 +344,12 @@ where
is_staked: result.is_staked,
stake_info: RpcStakeInfo {
addr: address,
stake: result.stake_info.stake.as_u128(),
unstake_delay_sec: result.stake_info.unstake_delay_sec.as_u32(),
stake: result
.stake_info
.stake
.try_into()
.context("stake should fit in u128")?,
unstake_delay_sec: result.stake_info.unstake_delay_sec,
},
})
}
Expand Down
Loading

0 comments on commit e1670fe

Please sign in to comment.