Skip to content

Commit

Permalink
various rpc param type fixes (#473)
Browse files Browse the repository at this point in the history
* fix eth_feeHistory param type

* fix U64HexOrNumber error

* replace unwraps in sequencer and ethereum-rpc rpc functions
  • Loading branch information
eyusufatik authored May 2, 2024
1 parent 35c2535 commit 99ac329
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
26 changes: 13 additions & 13 deletions crates/ethereum-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use gas_price::gas_oracle::GasPriceOracleConfig;
use jsonrpsee::types::ErrorObjectOwned;
use jsonrpsee::RpcModule;
use reth_primitives::{keccak256, BlockNumberOrTag, B256, U256};
use reth_rpc_types::serde_helpers::U64HexOrNumber;
use reth_rpc_types::trace::geth::{
CallConfig, CallFrame, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerConfig,
GethDebugTracerType, GethDebugTracingOptions, GethTrace, NoopFrame,
Expand Down Expand Up @@ -226,13 +227,12 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
info!("eth module: eth_feeHistory");
let mut params = params.sequence();

let block_count: String = params.next().unwrap();
let newest_block: BlockNumberOrTag = params.next().unwrap();
let block_count: U64HexOrNumber = params.next()?;
let newest_block: BlockNumberOrTag = params.next()?;
let reward_percentiles: Option<Vec<f64>> = params.optional_next()?;

// convert block count to u64 from hex
let block_count = u64::from_str_radix(&block_count[2..], 16)
.map_err(|e| EthApiError::InvalidParams(e.to_string()))?;
let block_count = block_count.to();

let fee_history = {
let mut working_set = WorkingSet::<C>::new(ethereum.storage.clone());
Expand Down Expand Up @@ -490,10 +490,10 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(

let mut params = parmaeters.sequence();

let block_hash: B256 = params.next().unwrap();
let block_hash: B256 = params.next()?;
let evm = Evm::<C>::default();
let mut working_set = WorkingSet::<C>::new(ethereum.storage.clone());
let opts: Option<GethDebugTracingOptions> = params.optional_next().unwrap();
let opts: Option<GethDebugTracingOptions> = params.optional_next()?;

let block_number =
match evm.get_block_number_by_block_hash(block_hash, &mut working_set) {
Expand Down Expand Up @@ -555,8 +555,8 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(

let mut params = parameters.sequence();

let block_number: BlockNumberOrTag = params.next().unwrap();
let opts: Option<GethDebugTracingOptions> = params.optional_next().unwrap();
let block_number: BlockNumberOrTag = params.next()?;
let opts: Option<GethDebugTracingOptions> = params.optional_next()?;

let mut working_set = WorkingSet::<C>::new(ethereum.storage.clone());
let evm = Evm::<C>::default();
Expand Down Expand Up @@ -634,7 +634,7 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
.expect("Block number must be set for tx inside block"),
);

let opts: Option<GethDebugTracingOptions> = params.optional_next().unwrap();
let opts: Option<GethDebugTracingOptions> = params.optional_next()?;

// If opts is None or if opts.tracer is None, then do not check cache or insert cache, just perform the operation
// also since this is not cached we need to stop at somewhere, so we add param stop_at
Expand Down Expand Up @@ -704,8 +704,8 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(

let mut params = parameters.sequence();

let _block_hash: String = params.next().unwrap();
let _uncle_index_position: String = params.next().unwrap();
let _block_hash: String = params.next()?;
let _uncle_index_position: String = params.next()?;

let res = json!(null);

Expand All @@ -719,7 +719,7 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
|parameters, ethereum| async move {
info!("Full Node: eth_sendRawTransaction");
// send this directly to the sequencer
let data: Bytes = parameters.one().unwrap();
let data: Bytes = parameters.one()?;
// sequencer client should send it
let tx_hash = ethereum
.sequencer_client
Expand All @@ -742,7 +742,7 @@ fn register_rpc_methods<C: sov_modules_api::Context, Da: DaService>(
"eth_getTransactionByHash",
|parameters, ethereum| async move {
let mut params = parameters.sequence();
let hash: B256 = params.next().unwrap();
let hash: B256 = params.next()?;
let mempool_only: Result<Option<bool>, ErrorObjectOwned> = params.optional_next();
info!(
"Full Node: eth_getTransactionByHash({}, {:?})",
Expand Down
7 changes: 5 additions & 2 deletions crates/sequencer/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) fn create_rpc_module<C: sov_modules_api::Context>(
})?;
rpc.register_async_method("eth_getTransactionByHash", |parameters, ctx| async move {
let mut params = parameters.sequence();
let hash: B256 = params.next().unwrap();
let hash: B256 = params.next()?;
let mempool_only: Result<Option<bool>, ErrorObjectOwned> = params.optional_next();
info!(
"Sequencer: eth_getTransactionByHash({}, {:?})",
Expand Down Expand Up @@ -100,7 +100,7 @@ pub(crate) fn create_rpc_module<C: sov_modules_api::Context>(
"citrea_sendRawDepositTransaction",
|parameters, ctx| async move {
let mut params = parameters.sequence();
let deposit: Bytes = params.next().unwrap();
let deposit: Bytes = params.next()?;

info!("Sequencer: citrea_sendRawDepositTransaction");

Expand All @@ -125,8 +125,11 @@ pub(crate) fn create_rpc_module<C: sov_modules_api::Context>(
}
Err(e) => {
tracing::error!("Error processing deposit tx: {:?}", e);
return Err(e);
}
}

Ok(())
},
)?;
Ok(rpc)
Expand Down

0 comments on commit 99ac329

Please sign in to comment.