diff --git a/Cargo.lock b/Cargo.lock index 53a10112f..40d358ed5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1673,6 +1673,7 @@ dependencies = [ "reth-interfaces", "reth-primitives", "reth-provider", + "reth-rpc", "reth-rpc-types", "reth-rpc-types-compat", "reth-tasks", @@ -8153,6 +8154,7 @@ name = "sequencer-client" version = "0.3.0" dependencies = [ "anyhow", + "citrea-evm", "ethers", "hex", "jsonrpsee", diff --git a/bin/citrea/tests/mempool/mod.rs b/bin/citrea/tests/mempool/mod.rs index d6945ddbb..4b9cee4d9 100644 --- a/bin/citrea/tests/mempool/mod.rs +++ b/bin/citrea/tests/mempool/mod.rs @@ -61,7 +61,7 @@ async fn test_same_nonce_tx_should_panic() { // send tx with nonce 1 again and expect it to be rejected let res = test_client.send_eth(addr, None, None, Some(1), 0u128).await; - assert!(res.unwrap_err().to_string().contains("already imported")); + assert!(res.unwrap_err().to_string().contains("already known")); seq_task.abort(); } @@ -87,8 +87,7 @@ async fn test_nonce_too_low() { .unwrap(); let res = test_client.send_eth(addr, None, None, Some(0), 0u128).await; - - assert!(res.unwrap_err().to_string().contains("already imported")); + assert!(res.unwrap_err().to_string().contains("already known")); seq_task.abort(); } @@ -292,7 +291,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); // Replacement error with equal fee let err = test_client @@ -300,7 +299,7 @@ async fn test_same_nonce_tx_replacement() { .await .unwrap_err(); - assert!(err.to_string().contains("already imported")); + assert!(err.to_string().contains("already known")); // Replacement error with enough base fee but low priority fee let err = test_client @@ -316,7 +315,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); // Replacement error with enough base fee but low priority fee let err = test_client @@ -332,7 +331,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); // Replacement error with not enough fee increase (like 5% or sth.) let err = test_client @@ -348,7 +347,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); // Replacement success with 10% fee bump - does not work let err = test_client @@ -364,7 +363,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); let err = test_client .send_eth( @@ -379,7 +378,7 @@ async fn test_same_nonce_tx_replacement() { assert!(err .to_string() - .contains("insufficient gas price to replace existing transaction")); + .contains("replacement transaction underpriced")); // Replacement success with more than 10% bump let tx_hash_11_bump = test_client diff --git a/crates/ethereum-rpc/src/lib.rs b/crates/ethereum-rpc/src/lib.rs index 52780fc3c..50109f20e 100644 --- a/crates/ethereum-rpc/src/lib.rs +++ b/crates/ethereum-rpc/src/lib.rs @@ -7,7 +7,7 @@ use std::sync::Mutex; #[cfg(feature = "local")] pub use citrea_evm::DevSigner; use citrea_evm::{EthApiError, Evm}; -use ethers::types::Bytes; +use ethers::types::{Bytes, H256}; pub use gas_price::fee_history::FeeHistoryCacheConfig; use gas_price::gas_oracle::GasPriceOracle; pub use gas_price::gas_oracle::GasPriceOracleConfig; @@ -30,8 +30,6 @@ use tracing::info; use crate::gas_price::gas_oracle::convert_u256_to_u64; -const ETH_RPC_ERROR: &str = "ETH_RPC_ERROR"; - const MAX_TRACE_BLOCK: u32 = 1000; #[derive(Clone)] @@ -234,7 +232,7 @@ fn register_rpc_methods( // convert block count to u64 from hex let block_count = u64::from_str_radix(&block_count[2..], 16) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; + .map_err(|e| EthApiError::InvalidParams(e.to_string()))?; let fee_history = { let mut working_set = WorkingSet::::new(ethereum.storage.clone()); @@ -485,7 +483,7 @@ fn register_rpc_methods( // Ok::<_, ErrorObjectOwned>(tx_hash) // })?; - rpc.register_async_method( + rpc.register_async_method::, ErrorObjectOwned>, _, _>( "debug_traceBlockByHash", |parmaeters, ethereum| async move { info!("eth module: debug_traceBlockByHash"); @@ -501,23 +499,18 @@ fn register_rpc_methods( match evm.get_block_number_by_block_hash(block_hash, &mut working_set) { Some(block_number) => block_number, None => { - return Err(to_jsonrpsee_error_object( - EthApiError::UnknownBlockNumber, - ETH_RPC_ERROR, - )); + return Err(EthApiError::UnknownBlockNumber.into()); } }; // If opts is None or if opts.tracer is None, then do not check cache or insert cache, just perform the operation if opts.as_ref().map_or(true, |o| o.tracer.is_none()) { - return evm - .trace_block_transactions_by_number( - block_number, - opts.clone(), - None, - &mut working_set, - ) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR)); + return evm.trace_block_transactions_by_number( + block_number, + opts.clone(), + None, + &mut working_set, + ); } if let Some(traces) = ethereum.trace_cache.lock().unwrap().get(&block_number) { @@ -528,17 +521,15 @@ fn register_rpc_methods( requested_opts.tracer.unwrap(), requested_opts.tracer_config, )?; - return Ok::, ErrorObjectOwned>(traces); + return Ok(traces); } let cache_options = create_trace_cache_opts(); - let traces = evm - .trace_block_transactions_by_number( - block_number, - Some(cache_options), - None, - &mut working_set, - ) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; + let traces = evm.trace_block_transactions_by_number( + block_number, + Some(cache_options), + None, + &mut working_set, + )?; ethereum .trace_cache .lock() @@ -553,11 +544,11 @@ fn register_rpc_methods( tracer_config, )?; - Ok::, ErrorObjectOwned>(traces) + Ok(traces) }, )?; - rpc.register_async_method( + rpc.register_async_method::, ErrorObjectOwned>, _, _>( "debug_traceBlockByNumber", |parameters, ethereum| async move { info!("eth module: debug_traceBlockByNumber"); @@ -572,18 +563,12 @@ fn register_rpc_methods( let block_number = match block_number { BlockNumberOrTag::Number(block_number) => block_number, BlockNumberOrTag::Latest => convert_u256_to_u64(evm.block_number(&mut working_set)?), - _ => { - return Err(to_jsonrpsee_error_object( - EthApiError::Unsupported("Earliest, pending, safe and finalized are not supported for debug_traceBlockByNumber"), - ETH_RPC_ERROR, - )); - } + _ => return Err(EthApiError::Unsupported("Earliest, pending, safe and finalized are not supported for debug_traceBlockByNumber").into()), }; // If opts is None or if opts.tracer is None, then do not check cache or insert cache, just perform the operation if opts.as_ref().map_or(true, |o| o.tracer.is_none()) { - return evm.trace_block_transactions_by_number(block_number, opts.clone(), None, &mut working_set) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR)); + return evm.trace_block_transactions_by_number(block_number, opts.clone(), None, &mut working_set); } if let Some(traces) = ethereum.trace_cache.lock().unwrap().get(&block_number) { @@ -601,8 +586,7 @@ fn register_rpc_methods( Some(cache_options), None, &mut working_set, - ) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; + )?; ethereum .trace_cache .lock() @@ -614,11 +598,11 @@ fn register_rpc_methods( let tracer_config = requested_opts.tracer_config; let traces = get_traces_with_reuqested_tracer_and_config(traces.clone(), requested_opts.tracer.unwrap(), tracer_config)?; - Ok::, ErrorObjectOwned>(traces) + Ok(traces) }, )?; - rpc.register_async_method( + rpc.register_async_method::, _, _>( "debug_traceTransaction", |parameters, ethereum| async move { // the main rpc handler for debug_traceTransaction @@ -655,17 +639,13 @@ fn register_rpc_methods( // 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 if opts.as_ref().map_or(true, |o| o.tracer.is_none()) { - return Ok::( - evm.trace_block_transactions_by_number( - block_number, - opts.clone(), - Some(trace_index as usize), - &mut working_set, - ) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))? - [trace_index as usize] - .clone(), - ); + let traces = evm.trace_block_transactions_by_number( + block_number, + opts.clone(), + Some(trace_index as usize), + &mut working_set, + )?; + return Ok(traces[trace_index as usize].clone()); } // check cache if found convert to requested tracer and config and return @@ -677,18 +657,16 @@ fn register_rpc_methods( requested_opts.tracer.unwrap(), tracer_config, )?; - return Ok::(traces.into_iter().next().unwrap()); + return Ok(traces.into_iter().next().unwrap()); } let cache_options = create_trace_cache_opts(); - let traces = evm - .trace_block_transactions_by_number( - block_number, - Some(cache_options), - None, - &mut working_set, - ) - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; + let traces = evm.trace_block_transactions_by_number( + block_number, + Some(cache_options), + None, + &mut working_set, + )?; ethereum .trace_cache .lock() @@ -703,7 +681,7 @@ fn register_rpc_methods( tracer_config, )?; - Ok::(traces.into_iter().next().unwrap()) + Ok(traces.into_iter().next().unwrap()) }, )?; @@ -736,7 +714,7 @@ fn register_rpc_methods( )?; if !is_sequencer { - rpc.register_async_method( + rpc.register_async_method::, _, _>( "eth_sendRawTransaction", |parameters, ethereum| async move { info!("Full Node: eth_sendRawTransaction"); @@ -750,11 +728,17 @@ fn register_rpc_methods( .send_raw_tx(data) .await; - tx_hash.map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR)) + match tx_hash { + Ok(tx_hash) => Ok(tx_hash), + Err(e) => match e { + jsonrpsee::core::Error::Call(e_owned) => Err(e_owned), + _ => Err(to_jsonrpsee_error_object("SEQUENCER_CLIENT_ERROR", e)), + }, + } }, )?; - rpc.register_async_method( + rpc.register_async_method::, ErrorObjectOwned>, _, _>( "eth_getTransactionByHash", |parameters, ethereum| async move { let mut params = parameters.sequence(); @@ -769,40 +753,48 @@ fn register_rpc_methods( match mempool_only { // only ask sequencer Ok(Some(true)) => { - let tx = ethereum + match ethereum .sequencer_client .as_ref() .unwrap() .get_tx_by_hash(hash, Some(true)) .await - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; - - Ok::, ErrorObjectOwned>(tx) + { + Ok(tx) => Ok(tx), + Err(e) => match e { + jsonrpsee::core::Error::Call(e_owned) => Err(e_owned), + _ => Err(to_jsonrpsee_error_object("SEQUENCER_CLIENT_ERROR", e)), + }, + } } _ => { // if mempool_only is not true ask evm first then sequencer let evm = Evm::::default(); let mut working_set = WorkingSet::::new(ethereum.storage.clone()); match evm.get_transaction_by_hash(hash, &mut working_set) { - Ok(Some(tx)) => Ok::< - Option, - ErrorObjectOwned, - >(Some(tx)), + Ok(Some(tx)) => Ok(Some(tx)), Ok(None) => { // if not found in evm then ask to sequencer mempool - let tx = ethereum + match ethereum .sequencer_client .as_ref() .unwrap() .get_tx_by_hash(hash, Some(true)) .await - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; - - Ok::, ErrorObjectOwned>(tx) + { + Ok(tx) => Ok(tx), + Err(e) => match e { + jsonrpsee::core::Error::Call(e_owned) => Err(e_owned), + _ => Err(to_jsonrpsee_error_object( + "SEQUENCER_CLIENT_ERROR", + e, + )), + }, + } } Err(e) => { // return error - Err(to_jsonrpsee_error_object(e, ETH_RPC_ERROR)) + Err(e) } } } @@ -852,7 +844,7 @@ pub fn get_latest_git_tag() -> Result { let latest_tag_commit = Command::new("git") .args(["rev-list", "--tags", "--max-count=1"]) .output() - .map_err(|e| to_jsonrpsee_error_object(e, "Failed to get version"))?; + .map_err(|e| to_jsonrpsee_error_object("FULL_NODE_ERROR", e))?; if !latest_tag_commit.status.success() { return Err(to_jsonrpsee_error_object( @@ -868,7 +860,7 @@ pub fn get_latest_git_tag() -> Result { let latest_tag = Command::new("git") .args(["describe", "--tags", &latest_tag_commit]) .output() - .map_err(|e| to_jsonrpsee_error_object(e, "Failed to get version"))?; + .map_err(|e| to_jsonrpsee_error_object("FULL_NODE_ERROR", e))?; if !latest_tag.status.success() { return Err(to_jsonrpsee_error_object( diff --git a/crates/sequencer-client/Cargo.toml b/crates/sequencer-client/Cargo.toml index 1c662cf00..81a87a4e7 100644 --- a/crates/sequencer-client/Cargo.toml +++ b/crates/sequencer-client/Cargo.toml @@ -21,6 +21,7 @@ jsonrpsee = { workspace = true, features = ["http-client"] } serde = { workspace = true } serde_json = { workspace = true } hex = { workspace = true } +citrea-evm = { path = "../evm" } ethers = { workspace = true } tokio = { workspace = true } diff --git a/crates/sequencer-client/src/lib.rs b/crates/sequencer-client/src/lib.rs index 1ec0a1bab..e1e3e39c9 100644 --- a/crates/sequencer-client/src/lib.rs +++ b/crates/sequencer-client/src/lib.rs @@ -44,27 +44,23 @@ impl SequencerClient { } /// Sends raw tx to sequencer - pub async fn send_raw_tx(&self, tx: Bytes) -> anyhow::Result { - let tx_hash: H256 = self - .client + pub async fn send_raw_tx(&self, tx: Bytes) -> Result { + self.client .request("eth_sendRawTransaction", rpc_params![tx]) - .await?; - Ok(tx_hash) + .await } pub async fn get_tx_by_hash( &self, tx_hash: B256, mempool_only: Option, - ) -> anyhow::Result> { - let tx: Option = self - .client + ) -> Result, Error> { + self.client .request( "eth_getTransactionByHash", rpc_params![tx_hash, mempool_only], ) - .await?; - Ok(tx) + .await } } diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 7154fb569..c815808f9 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -33,6 +33,7 @@ reth-interfaces = { workspace = true } reth-db = { workspace = true } reth-trie = { workspace = true } reth-rpc-types-compat = { workspace = true } +reth-rpc = { workspace = true } revm = { workspace = true } diff --git a/crates/sequencer/src/rpc.rs b/crates/sequencer/src/rpc.rs index bc085027b..ec7f04db2 100644 --- a/crates/sequencer/src/rpc.rs +++ b/crates/sequencer/src/rpc.rs @@ -5,18 +5,16 @@ use futures::channel::mpsc::UnboundedSender; use jsonrpsee::types::ErrorObjectOwned; use jsonrpsee::RpcModule; use reth_primitives::{Bytes, FromRecoveredPooledTransaction, IntoRecoveredTransaction, B256}; +use reth_rpc::eth::error::EthApiError; use reth_rpc_types_compat::transaction::from_recovered; use reth_transaction_pool::EthPooledTransaction; use sov_mock_da::{MockAddress, MockDaService}; -use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_modules_api::WorkingSet; use tracing::info; use crate::mempool::CitreaMempool; use crate::utils::recover_raw_transaction; -const ETH_RPC_ERROR: &str = "ETH_RPC_ERROR"; - pub(crate) struct RpcContext { pub mempool: Arc>, pub l2_force_block_tx: UnboundedSender<()>, @@ -44,7 +42,8 @@ pub(crate) fn create_rpc_module( .mempool .add_external_transaction(pool_transaction) .await - .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; + .map_err(EthApiError::from)?; + Ok::(hash) })?; @@ -87,7 +86,7 @@ pub(crate) fn create_rpc_module( match evm.get_transaction_by_hash(hash, &mut working_set) { Ok(tx) => Ok::, ErrorObjectOwned>(tx), - Err(e) => Err(to_jsonrpsee_error_object(e, ETH_RPC_ERROR)), + Err(e) => Err(e), } } }, diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs index 15088a566..70a28d508 100644 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs +++ b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs @@ -48,7 +48,7 @@ where let query_mode = params.optional_next()?.unwrap_or(QueryMode::Compact); ledger .get_head::(query_mode) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; // Primary getters. @@ -56,24 +56,24 @@ where let args: QueryArgs> = extract_query_args(params)?; ledger .get_slots::(&args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getBatches", move |params, ledger| { let args: QueryArgs> = extract_query_args(params)?; ledger .get_batches::(&args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getTransactions", move |params, ledger| { let args: QueryArgs> = extract_query_args(params)?; ledger .get_transactions::(&args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getEvents", move |params, db| { let ids: Vec = params.parse().or_else(|_| params.one())?; db.get_events(&ids) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; // By-hash getters. @@ -81,25 +81,25 @@ where let args: QueryArgs = extract_query_args(params)?; ledger .get_slot_by_hash::(&args.0 .0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getSoftBatchByHash", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_soft_batch_by_hash::(&args.0 .0) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getBatchByHash", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_batch_by_hash::(&args.0 .0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getTransactionByHash", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_tx_by_hash::(&args.0 .0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; // By-number getters. @@ -107,31 +107,31 @@ where let args: QueryArgs = extract_query_args(params)?; ledger .get_slot_by_number::(args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getSoftBatchByNumber", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_soft_batch_by_number::(args.0) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getBatchByNumber", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_batch_by_number::(args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getTransactionByNumber", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_tx_by_number::(args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getEventByNumber", move |params, ledger| { let args: u64 = params.one()?; ledger .get_event_by_number(args) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; // Range getters. @@ -139,31 +139,31 @@ where let args: RangeArgs = params.parse()?; ledger .get_slots_range::(args.0, args.1, args.2) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getBatchesRange", move |params, ledger| { let args: RangeArgs = params.parse()?; ledger .get_batches_range::(args.0, args.1, args.2) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getSoftBatchRange", move |params, ledger| { let args: (u64, u64) = params.parse()?; ledger .get_soft_batches_range(args.0, args.1) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getTransactionsRange", move |params, ledger| { let args: RangeArgs = params.parse()?; ledger .get_transactions_range::(args.0, args.1, args.2) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_method("ledger_getSoftConfirmationStatus", move |params, ledger| { let args: QueryArgs = extract_query_args(params)?; ledger .get_soft_confirmation_status(args.0) - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR)) + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e)) })?; rpc.register_subscription( @@ -174,7 +174,7 @@ where // Register with the ledgerDB to receive callbacks let mut rx = db .subscribe_slots() - .map_err(|e| to_jsonrpsee_error_object(e, LEDGER_RPC_ERROR))?; + .map_err(|e| to_jsonrpsee_error_object(LEDGER_RPC_ERROR, e))?; // Accept the subscription. This message is sent immediately let subscription = pending_subscription.accept().await?; diff --git a/crates/sovereign-sdk/full-node/sov-sequencer/src/lib.rs b/crates/sovereign-sdk/full-node/sov-sequencer/src/lib.rs index df422ecf6..9fcbe7214 100644 --- a/crates/sovereign-sdk/full-node/sov-sequencer/src/lib.rs +++ b/crates/sovereign-sdk/full-node/sov-sequencer/src/lib.rs @@ -78,12 +78,12 @@ where while let Some(tx) = params_iter.optional_next::>()? { batch_builder .accept_tx(tx) - .map_err(|e| to_jsonrpsee_error_object(e, SEQUENCER_RPC_ERROR))?; + .map_err(|e| to_jsonrpsee_error_object(SEQUENCER_RPC_ERROR, e))?; } let num_txs = batch_builder .submit_batch() .await - .map_err(|e| to_jsonrpsee_error_object(e, SEQUENCER_RPC_ERROR))?; + .map_err(|e| to_jsonrpsee_error_object(SEQUENCER_RPC_ERROR, e))?; Ok::(format!("Submitted {} transactions", num_txs)) }, 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 8e76f0e18..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 @@ -7,7 +7,7 @@ pub fn generate_address(key: &str) -> ::Address { C::Address::from(hash) } -pub fn to_jsonrpsee_error_object(err: impl ToString, message: &str) -> ErrorObjectOwned { +pub fn to_jsonrpsee_error_object(message: &str, err: impl ToString) -> ErrorObjectOwned { ErrorObjectOwned::owned( jsonrpsee::types::error::UNKNOWN_ERROR_CODE, message,