From 52ba987a930bdb421e63ecb3a5341b7f3bc270a9 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:15:02 +0100 Subject: [PATCH] Remove methods --- crates/ethereum-rpc/src/ethereum.rs | 6 --- crates/ethereum-rpc/src/lib.rs | 44 ++++++++----------- .../sov-modules-api/src/utils.rs | 8 ---- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/crates/ethereum-rpc/src/ethereum.rs b/crates/ethereum-rpc/src/ethereum.rs index 4e37ade26..207df4a9a 100644 --- a/crates/ethereum-rpc/src/ethereum.rs +++ b/crates/ethereum-rpc/src/ethereum.rs @@ -42,8 +42,6 @@ pub struct Ethereum { pub(crate) web3_client_version: String, pub(crate) trace_cache: Mutex, ByLength>>, pub(crate) subscription_manager: Option, - pub(crate) is_sequencer: bool, - pub(crate) enable_subscription: bool, } impl Ethereum { @@ -57,8 +55,6 @@ impl Ethereum { ledger_db: LedgerDB, sequencer_client: Option, soft_confirmation_rx: Option>, - is_sequencer: bool, - enable_subscription: bool, ) -> Self { let evm = Evm::::default(); let gas_price_oracle = @@ -86,8 +82,6 @@ impl Ethereum { web3_client_version: current_version, trace_cache, subscription_manager, - is_sequencer, - enable_subscription, } } diff --git a/crates/ethereum-rpc/src/lib.rs b/crates/ethereum-rpc/src/lib.rs index fb4647272..0de9555ec 100644 --- a/crates/ethereum-rpc/src/lib.rs +++ b/crates/ethereum-rpc/src/lib.rs @@ -28,7 +28,7 @@ use serde_json::{json, Value}; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::da::BlockHeaderTrait; -use sov_modules_api::utils::{jsonrpsee_error_not_found, to_jsonrpsee_error_object}; +use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_modules_api::WorkingSet; use sov_rollup_interface::services::da::DaService; use tokio::join; @@ -650,10 +650,6 @@ where } async fn eth_send_raw_transaction(&self, data: Bytes) -> RpcResult { - if self.ethereum.is_sequencer { - return Err(jsonrpsee_error_not_found()); - } - let tx_hash = SequencerRpcClient::eth_send_raw_transaction( self.ethereum.sequencer_client.as_ref().unwrap(), data, @@ -674,10 +670,6 @@ where hash: B256, mempool_only: Option, ) -> RpcResult>> { - if self.ethereum.is_sequencer { - return Err(jsonrpsee_error_not_found()); - } - match mempool_only { Some(true) => { match SequencerRpcClient::eth_get_transaction_by_hash( @@ -721,10 +713,6 @@ where } async fn citrea_sync_status(&self) -> RpcResult { - if self.ethereum.is_sequencer { - return Err(jsonrpsee_error_not_found()); - } - let (sequencer_response, da_response) = join!( self.ethereum .sequencer_client @@ -792,11 +780,6 @@ where end_block: BlockNumberOrTag, opts: Option, ) -> SubscriptionResult { - if !self.ethereum.enable_subscription { - pending.reject(jsonrpsee_error_not_found()).await; - return Ok(()); - } - if &topic == "traceChain" { handle_debug_trace_chain(start_block, end_block, opts, pending, self.ethereum.clone()) .await; @@ -814,11 +797,6 @@ where topic: String, filter: Option, ) -> SubscriptionResult { - if !self.ethereum.enable_subscription { - pending.reject(jsonrpsee_error_not_found()).await; - return Ok(()); - } - match topic.as_str() { "newHeads" => { let subscription = pending.accept().await?; @@ -888,9 +866,23 @@ where ledger_db, sequencer_client_url.map(|url| HttpClientBuilder::default().build(url).unwrap()), soft_confirmation_rx, - is_sequencer, - enable_subscriptions, )); let server = EthereumRpcServerImpl::new(ethereum); - EthereumRpcServer::into_rpc(server) + + let mut module = EthereumRpcServer::into_rpc(server); + + if is_sequencer { + module.remove_method("eth_sendRawTransaction"); + module.remove_method("eth_getTransactionByHash"); + module.remove_method("citrea_syncStatus"); + } + + if !enable_subscriptions { + module.remove_method("eth_subscribe"); + module.remove_method("eth_unsubscribe"); + module.remove_method("debug_subscribe"); + module.remove_method("debug_unsubscribe"); + } + + module } diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/utils.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/utils.rs index 8ba3876a5..ef54e3fbc 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/utils.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/utils.rs @@ -14,11 +14,3 @@ pub fn to_jsonrpsee_error_object(message: &str, err: impl ToString) -> ErrorObje Some(err.to_string()), ) } - -pub fn jsonrpsee_error_not_found() -> ErrorObjectOwned { - ErrorObjectOwned::owned( - jsonrpsee::types::error::METHOD_NOT_FOUND_CODE, - jsonrpsee::types::error::METHOD_NOT_FOUND_MSG, - None::, - ) -}