From fd241fadc38d924eeae5de967d3ebbd731993456 Mon Sep 17 00:00:00 2001 From: 8times4 <46720448+8times4@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:32:35 +0200 Subject: [PATCH 1/3] if fork_url is defined, use that for the fork_url and avoid getting it from chain_id_to_fork --- src/simulation.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/simulation.rs b/src/simulation.rs index 1595d5c..f1a101f 100644 --- a/src/simulation.rs +++ b/src/simulation.rs @@ -227,9 +227,11 @@ async fn run( } pub async fn simulate(transaction: SimulationRequest, config: Config) -> Result { - let fork_url = config - .fork_url - .unwrap_or(chain_id_to_fork_url(transaction.chain_id)?); + let fork_url = if let Some(url) = config.fork_url { + url + } else { + chain_id_to_fork_url(transaction.chain_id)? + }; let mut evm = Evm::new( None, fork_url, @@ -239,6 +241,10 @@ pub async fn simulate(transaction: SimulationRequest, config: Config) -> Result< config.etherscan_key, ); + // println!("EVM Config: {:?}", evm); + + log::debug!("Current Chain ID: {}", evm.get_chain_id()); + if evm.get_chain_id() != Uint::from(transaction.chain_id) { return Err(warp::reject::custom(IncorrectChainIdError())); } @@ -262,9 +268,11 @@ pub async fn simulate_bundle( let first_block_number = transactions[0].block_number; let first_block_timestamp = transactions[0].block_timestamp; - let fork_url = config - .fork_url - .unwrap_or(chain_id_to_fork_url(first_chain_id)?); + let fork_url = if let Some(url) = config.fork_url { + url + } else { + chain_id_to_fork_url(first_chain_id)? + }; let mut evm = Evm::new( None, fork_url, @@ -315,9 +323,11 @@ pub async fn simulate_stateful_new( config: Config, state: Arc, ) -> Result { - let fork_url = config - .fork_url - .unwrap_or(chain_id_to_fork_url(stateful_simulation_request.chain_id)?); + let fork_url = if let Some(url) = config.fork_url { + url + } else { + chain_id_to_fork_url(stateful_simulation_request.chain_id)? + }; let mut evm = Evm::new( None, fork_url, From 43ee555a52eefecd5a864728975ebb49662abbfe Mon Sep 17 00:00:00 2001 From: 8x4 <46720448+8times4@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:55:53 +0200 Subject: [PATCH 2/3] Add notes about `FORK_URL` and `chainId` relationship --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d5b8a31..1d96790 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Example response: ``` Notes: - +- `chainId` must be the same as the `chainId` of the `FORK_URL` environment variable, if defined. - `blockNumber` can be omitted and the latest block will be used, however providing a `blockNumber` is recommended where possible to use the cache. ### POST /api/v1/simulate-bundle @@ -82,7 +82,7 @@ Example response: Notes: -- `chainId` must be the same in all transactions. +- `chainId` must be the same in all transactions and it must match the `chainId` of `FORK_URL` environment variable, if defined. - `blockNumber` can be included and incremented when a multi-block simulation is required, or omitted in all transactions to use latest. ### POST /api/v1/simulate-stateful @@ -148,7 +148,7 @@ Example response: ``` Notes: -- `chainId` must be the same in all transactions. +- `chainId` must be the same in all transactions and it must match the `chainId` of `FORK_URL` environment variable, if defined. - `blockNumber` can be included and incremented when a multi-block simulation is required, or omitted in all transactions to use latest. From 20636e35a5981c13c78b4246975d2c5869cacd1c Mon Sep 17 00:00:00 2001 From: 8x4 <46720448+8times4@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:39:46 +0200 Subject: [PATCH 3/3] remove debug logs --- src/simulation.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/simulation.rs b/src/simulation.rs index f1a101f..642fdfa 100644 --- a/src/simulation.rs +++ b/src/simulation.rs @@ -241,10 +241,6 @@ pub async fn simulate(transaction: SimulationRequest, config: Config) -> Result< config.etherscan_key, ); - // println!("EVM Config: {:?}", evm); - - log::debug!("Current Chain ID: {}", evm.get_chain_id()); - if evm.get_chain_id() != Uint::from(transaction.chain_id) { return Err(warp::reject::custom(IncorrectChainIdError())); }