Skip to content

Commit

Permalink
rustftm
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Aug 4, 2023
1 parent fa0590c commit 8ca27f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
9 changes: 5 additions & 4 deletions crates/rpc/rpc-api/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use reth_primitives::{
AccessListWithGasUsed, Address, BlockId, BlockNumberOrTag, Bytes, H256, H64, U256, U64,
};
use reth_rpc_types::{
state::StateOverride, BlockOverrides, Bundle, CallRequest, EIP1186AccountProofResponse, FeeHistory,
Index, RichBlock, SyncStatus, Transaction, TransactionReceipt, TransactionRequest, Work, StateContext, EthCallResponse,
state::StateOverride, BlockOverrides, Bundle, CallRequest, EIP1186AccountProofResponse,
EthCallResponse, FeeHistory, Index, RichBlock, StateContext, SyncStatus, Transaction,
TransactionReceipt, TransactionRequest, Work,
};

/// Eth rpc interface: <https://ethereum.github.io/execution-apis/api-documentation/>
Expand Down Expand Up @@ -153,8 +154,8 @@ pub trait EthApi {
block_overrides: Option<Box<BlockOverrides>>,
) -> RpcResult<Bytes>;

/// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the optionality
/// of state overrides
/// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the
/// optionality of state overrides
#[method(name = "callMany")]
async fn call_many(
&self,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-types/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod work;

pub use account::*;
pub use block::*;
pub use call::{Bundle, CallInput, CallInputError, CallRequest, StateContext, EthCallResponse};
pub use call::{Bundle, CallInput, CallInputError, CallRequest, EthCallResponse, StateContext};
pub use fee::{FeeHistory, TxGasAndReward};
pub use filter::*;
pub use index::Index;
Expand Down
30 changes: 14 additions & 16 deletions crates/rpc/rpc/src/eth/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ where
ensure_success(res.result)
}

/// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the optionality
/// of state overrides
/// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the
/// optionality of state overrides
pub async fn call_many(
&self,
bundle: Bundle,
Expand All @@ -76,7 +76,7 @@ where
) -> EthResult<Vec<EthCallResponse>> {
let Bundle { transactions, block_override } = bundle;
if transactions.is_empty() {
return Err(EthApiError::InvalidParams(String::from("transactions are empty.")));
return Err(EthApiError::InvalidParams(String::from("transactions are empty.")))
}

let StateContext { transaction_index, block_number } = state_context.unwrap_or_default();
Expand All @@ -102,8 +102,8 @@ where
}

let this = self.clone();
let res = self
.inner

self.inner
.tracing_call_pool
.spawn(move || {
let state = this.state_at(at.into())?;
Expand All @@ -129,8 +129,8 @@ where
let overrides =
EvmOverrides::new(state_override.clone(), block_override.map(Box::new));

let mut transactions = transactions.into_iter().peekable();
while let Some(tx) = transactions.next() {
let transactions = transactions.into_iter().peekable();
for tx in transactions {
let env = prepare_call_env(
cfg.clone(),
block_env.clone(),
Expand Down Expand Up @@ -168,9 +168,7 @@ where
// Ok(Vec::new())
})
.await
.map_err(|_| EthApiError::InternalEthError)?;

res
.map_err(|_| EthApiError::InternalEthError)?
}

/// Estimates the gas usage of the `request` with the state.
Expand Down Expand Up @@ -220,9 +218,9 @@ where
if env.tx.value > available_funds {
return Err(
RpcInvalidTransactionError::InsufficientFundsForTransfer.into()
);
)
}
return Ok(U256::from(MIN_TRANSACTION_GAS));
return Ok(U256::from(MIN_TRANSACTION_GAS))
}
}
}
Expand Down Expand Up @@ -254,7 +252,7 @@ where
// if price or limit was included in the request then we can execute the request
// again with the block's gas limit to check if revert is gas related or not
if request_gas.is_some() || request_gas_price.is_some() {
return Err(map_out_of_gas_err(env_gas_limit, env, &mut db));
return Err(map_out_of_gas_err(env_gas_limit, env, &mut db))
}
}

Expand All @@ -274,7 +272,7 @@ where
} else {
// the transaction did revert
Err(RpcInvalidTransactionError::Revert(RevertError::new(output)).into())
};
}
}
}

Expand Down Expand Up @@ -311,7 +309,7 @@ where

// new midpoint
mid_gas_limit = ((highest_gas_limit as u128 + lowest_gas_limit as u128) / 2) as u64;
continue;
continue
}

let (res, _) = ethres?;
Expand All @@ -333,7 +331,7 @@ where
err => {
// these should be unreachable because we know the transaction succeeds,
// but we consider these cases an error
return Err(RpcInvalidTransactionError::EvmHalt(err).into());
return Err(RpcInvalidTransactionError::EvmHalt(err).into())
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions crates/rpc/rpc/src/eth/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use reth_provider::{
use reth_rpc_api::EthApiServer;
use reth_rpc_types::{
state::StateOverride, BlockOverrides, Bundle, CallRequest, EIP1186AccountProofResponse,
FeeHistory, Index, RichBlock, StateContext, SyncStatus, TransactionReceipt, TransactionRequest,
Work, EthCallResponse,
EthCallResponse, FeeHistory, Index, RichBlock, StateContext, SyncStatus, TransactionReceipt,
TransactionRequest, Work,
};
use reth_transaction_pool::TransactionPool;
use serde_json::Value;
Expand Down Expand Up @@ -302,13 +302,13 @@ where
/// Handler for: `eth_gasPrice`
async fn gas_price(&self) -> Result<U256> {
trace!(target: "rpc::eth", "Serving eth_gasPrice");
return Ok(EthApi::gas_price(self).await?);
return Ok(EthApi::gas_price(self).await?)
}

/// Handler for: `eth_maxPriorityFeePerGas`
async fn max_priority_fee_per_gas(&self) -> Result<U256> {
trace!(target: "rpc::eth", "Serving eth_maxPriorityFeePerGas");
return Ok(EthApi::suggested_priority_fee(self).await?);
return Ok(EthApi::suggested_priority_fee(self).await?)
}

// FeeHistory is calculated based on lazy evaluation of fees for historical blocks, and further
Expand All @@ -327,13 +327,8 @@ where
reward_percentiles: Option<Vec<f64>>,
) -> Result<FeeHistory> {
trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
return Ok(EthApi::fee_history(
self,
block_count.as_u64(),
newest_block,
reward_percentiles,
)
.await?);
return Ok(EthApi::fee_history(self, block_count.as_u64(), newest_block, reward_percentiles)
.await?)
}

/// Handler for: `eth_mining`
Expand Down

0 comments on commit 8ca27f8

Please sign in to comment.