Skip to content

Commit

Permalink
Remove methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Dec 19, 2024
1 parent 21fc3af commit 52ba987
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
6 changes: 0 additions & 6 deletions crates/ethereum-rpc/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pub struct Ethereum<C: sov_modules_api::Context, Da: DaService> {
pub(crate) web3_client_version: String,
pub(crate) trace_cache: Mutex<LruMap<u64, Vec<GethTrace>, ByLength>>,
pub(crate) subscription_manager: Option<SubscriptionManager>,
pub(crate) is_sequencer: bool,
pub(crate) enable_subscription: bool,
}

impl<C: sov_modules_api::Context, Da: DaService> Ethereum<C, Da> {
Expand All @@ -57,8 +55,6 @@ impl<C: sov_modules_api::Context, Da: DaService> Ethereum<C, Da> {
ledger_db: LedgerDB,
sequencer_client: Option<HttpClient>,
soft_confirmation_rx: Option<broadcast::Receiver<u64>>,
is_sequencer: bool,
enable_subscription: bool,
) -> Self {
let evm = Evm::<C>::default();
let gas_price_oracle =
Expand Down Expand Up @@ -86,8 +82,6 @@ impl<C: sov_modules_api::Context, Da: DaService> Ethereum<C, Da> {
web3_client_version: current_version,
trace_cache,
subscription_manager,
is_sequencer,
enable_subscription,
}
}

Expand Down
44 changes: 18 additions & 26 deletions crates/ethereum-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -650,10 +650,6 @@ where
}

async fn eth_send_raw_transaction(&self, data: Bytes) -> RpcResult<B256> {
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,
Expand All @@ -674,10 +670,6 @@ where
hash: B256,
mempool_only: Option<bool>,
) -> RpcResult<Option<RpcTransaction<AnyNetwork>>> {
if self.ethereum.is_sequencer {
return Err(jsonrpsee_error_not_found());
}

match mempool_only {
Some(true) => {
match SequencerRpcClient::eth_get_transaction_by_hash(
Expand Down Expand Up @@ -721,10 +713,6 @@ where
}

async fn citrea_sync_status(&self) -> RpcResult<SyncStatus> {
if self.ethereum.is_sequencer {
return Err(jsonrpsee_error_not_found());
}

let (sequencer_response, da_response) = join!(
self.ethereum
.sequencer_client
Expand Down Expand Up @@ -792,11 +780,6 @@ where
end_block: BlockNumberOrTag,
opts: Option<GethDebugTracingOptions>,
) -> 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;
Expand All @@ -814,11 +797,6 @@ where
topic: String,
filter: Option<Filter>,
) -> 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?;
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>,
)
}

0 comments on commit 52ba987

Please sign in to comment.