From 3ce50f6c85ca1d57996728920d712c5e0246bdd3 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 22 Mar 2023 06:16:08 -0400 Subject: [PATCH] chore: add traces to rpc (#1904) --- crates/rpc/rpc/src/eth/api/server.rs | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index e48dee853d..05f3c46155 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -23,6 +23,7 @@ use reth_rpc_types::{ use reth_transaction_pool::TransactionPool; use serde_json::Value; use std::collections::BTreeMap; +use tracing::trace; #[async_trait::async_trait] impl EthApiServer for EthApi @@ -34,11 +35,13 @@ where { /// Handler for: `eth_protocolVersion` async fn protocol_version(&self) -> Result { + trace!(target: "rpc::eth", "Serving eth_protocolVersion"); EthApiSpec::protocol_version(self).await.to_rpc_result() } /// Handler for: `eth_syncing` fn syncing(&self) -> Result { + trace!(target: "rpc::eth", "Serving eth_syncing"); EthApiSpec::sync_status(self).to_rpc_result() } @@ -49,11 +52,13 @@ where /// Handler for: `eth_accounts` async fn accounts(&self) -> Result> { + trace!(target: "rpc::eth", "Serving eth_accounts"); Ok(EthApiSpec::accounts(self)) } /// Handler for: `eth_blockNumber` fn block_number(&self) -> Result { + trace!(target: "rpc::eth", "Serving eth_blockNumber"); Ok(U256::from( EthApiSpec::chain_info(self).with_message("failed to read chain info")?.best_number, )) @@ -61,11 +66,13 @@ where /// Handler for: `eth_chainId` async fn chain_id(&self) -> Result> { + trace!(target: "rpc::eth", "Serving eth_chainId"); Ok(Some(EthApiSpec::chain_id(self))) } /// Handler for: `eth_getBlockByHash` async fn block_by_hash(&self, hash: H256, full: bool) -> Result> { + trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash"); Ok(EthApi::block(self, hash, full).await?) } @@ -75,11 +82,13 @@ where number: BlockNumberOrTag, full: bool, ) -> Result> { + trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber"); Ok(EthApi::block(self, number, full).await?) } /// Handler for: `eth_getBlockTransactionCountByHash` async fn block_transaction_count_by_hash(&self, hash: H256) -> Result> { + trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockTransactionCountByHash"); Ok(EthApi::block_transaction_count(self, hash).await?.map(U256::from)) } @@ -88,16 +97,19 @@ where &self, number: BlockNumberOrTag, ) -> Result> { + trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber"); Ok(EthApi::block_transaction_count(self, number).await?.map(U256::from)) } /// Handler for: `eth_getUncleCountByBlockHash` async fn block_uncles_count_by_hash(&self, hash: H256) -> Result> { + trace!(target: "rpc::eth", ?hash, "Serving eth_getUncleCountByBlockHash"); Ok(EthApi::ommers(self, hash)?.map(|ommers| U256::from(ommers.len()))) } /// Handler for: `eth_getUncleCountByBlockNumber` async fn block_uncles_count_by_number(&self, number: BlockNumberOrTag) -> Result> { + trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber"); Ok(EthApi::ommers(self, number)?.map(|ommers| U256::from(ommers.len()))) } @@ -107,6 +119,7 @@ where hash: H256, index: Index, ) -> Result> { + trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex"); Ok(EthApi::ommer_by_block_and_index(self, hash, index).await?) } @@ -116,11 +129,13 @@ where number: BlockNumberOrTag, index: Index, ) -> Result> { + trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex"); Ok(EthApi::ommer_by_block_and_index(self, number, index).await?) } /// Handler for: `eth_getTransactionByHash` async fn transaction_by_hash(&self, hash: H256) -> Result> { + trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash"); Ok(EthTransactions::transaction_by_hash(self, hash).await?.map(Into::into)) } @@ -130,6 +145,7 @@ where hash: H256, index: Index, ) -> Result> { + trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex"); Ok(EthApi::transaction_by_block_and_tx_index(self, hash, index).await?) } @@ -139,6 +155,7 @@ where number: BlockNumberOrTag, index: Index, ) -> Result> { + trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex"); Ok(EthApi::transaction_by_block_and_tx_index(self, number, index).await?) } @@ -149,6 +166,7 @@ where /// Handler for: `eth_getBalance` async fn balance(&self, address: Address, block_number: Option) -> Result { + trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance"); Ok(EthApi::balance(self, address, block_number)?) } @@ -159,6 +177,7 @@ where index: U256, block_number: Option, ) -> Result { + trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt"); Ok(EthApi::storage_at(self, address, index, block_number)?) } @@ -168,11 +187,13 @@ where address: Address, block_number: Option, ) -> Result { + trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount"); Ok(EthApi::get_transaction_count(self, address, block_number)?) } /// Handler for: `eth_getCode` async fn get_code(&self, address: Address, block_number: Option) -> Result { + trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode"); Ok(EthApi::get_code(self, address, block_number)?) } @@ -183,6 +204,7 @@ where block_number: Option, state_overrides: Option, ) -> Result { + trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, "Serving eth_call"); let (res, _env) = self .execute_call_at( request, @@ -200,6 +222,7 @@ where mut request: CallRequest, block_number: Option, ) -> Result { + trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_createAccessList"); let block_id = block_number.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending)); let access_list = self.create_access_list_at(request.clone(), block_number).await?; request.access_list = Some(access_list.clone()); @@ -213,6 +236,7 @@ where request: CallRequest, block_number: Option, ) -> Result { + trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas"); Ok(EthApi::estimate_gas_at( self, request, @@ -241,6 +265,7 @@ where newest_block: BlockId, _reward_percentiles: Option>, ) -> Result { + trace!(target: "rpc::eth", ?block_count, ?newest_block, ?_reward_percentiles, "Serving eth_feeHistory"); let block_count = block_count.as_u64(); if block_count == 0 { @@ -368,11 +393,13 @@ where /// Handler for: `eth_sendRawTransaction` async fn send_raw_transaction(&self, tx: Bytes) -> Result { + trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction"); Ok(EthApi::send_raw_transaction(self, tx).await?) } /// Handler for: `eth_sign` async fn sign(&self, address: Address, message: Bytes) -> Result { + trace!(target: "rpc::eth", ?address, ?message, "Serving eth_sign"); Ok(EthApi::sign(self, address, message).await?) } @@ -383,6 +410,7 @@ where /// Handler for: `eth_signTypedData` async fn sign_typed_data(&self, address: Address, data: Value) -> Result { + trace!(target: "rpc::eth", ?address, ?data, "Serving eth_signTypedData"); Ok(EthApi::sign_typed_data(self, data, address).await?) } @@ -393,6 +421,7 @@ where keys: Vec, block_number: Option, ) -> Result { + trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof"); let res = EthApi::get_proof(self, address, keys, block_number); Ok(res.map_err(|e| match e {