Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev committed Sep 13, 2024
1 parent 3b48492 commit 1d8a5ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ r2d2_sqlite = "0.24.0"
rand = "0.8.5"
reth-ipc = { tag = "v0.2.0-beta.5", git = "https://github.com/paradigmxyz/reth.git"}
reth-rpc-types = { tag = "v1.0.6", git = "https://github.com/paradigmxyz/reth.git"}
revm = { version = "14.0.1", default-features = false, features = ["std", "secp256k1", "serde-json", "optional_block_gas_limit"] }
revm = { version = "14.0.1", default-features = false, features = ["std", "secp256k1", "serde-json"] }
revm-primitives = { version = "9.0.1", default-features = false, features = ["std", "serde"] }
rpc = { path = "rpc"}
rstest = "0.18.2"
Expand Down
16 changes: 9 additions & 7 deletions rpc/src/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethportal_api::{
ContentValue, EthApiServer, Header, HistoryContentKey, HistoryContentValue,
};
use trin_execution::evm::{
async_db::{execute_transaction_with_evm_modifier, AsyncDatabase},
async_db::{execute_transaction, AsyncDatabase},
create_block_env,
};
use trin_validation::constants::CHAIN_ID;
Expand Down Expand Up @@ -94,6 +94,7 @@ impl EthApiServer for EthApi {
};
Ok(account_info.balance)
}

async fn get_storage_at(
&self,
address: Address,
Expand Down Expand Up @@ -128,17 +129,18 @@ impl EthApiServer for EthApi {
Ok(bytecode.original_bytes())
}

async fn call(&self, transaction: TransactionRequest, block: BlockId) -> RpcResult<Bytes> {
async fn call(&self, mut transaction: TransactionRequest, block: BlockId) -> RpcResult<Bytes> {
let evm_block_state = self.evm_block_state(block).await?;

let result_and_state = execute_transaction_with_evm_modifier(
// If gas limit is not set, set it to block's limit
transaction
.gas
.get_or_insert(evm_block_state.block_header().gas_limit.to());

let result_and_state = execute_transaction(
create_block_env(evm_block_state.block_header()),
transaction,
evm_block_state,
|evm| {
// Allow unlimited gas
evm.cfg_mut().disable_block_gas_limit = true;
},
)
.await
.map_err(|err| RpcServeError::Message(err.to_string()))?;
Expand Down
17 changes: 1 addition & 16 deletions trin-execution/src/evm/async_db.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::future::Future;

use revm::{Database, Evm};
use revm::Database;
use revm_primitives::{AccountInfo, Address, BlockEnv, Bytecode, EVMError, EVMResult, B256, U256};
use tokio::{runtime, task};

Expand Down Expand Up @@ -76,20 +76,6 @@ pub async fn execute_transaction<DB, DBError, Tx>(
tx: Tx,
db: DB,
) -> EVMResult<DB::Error>
where
DB: AsyncDatabase<Error = DBError> + Send + 'static,
DBError: Send + 'static,
Tx: TxEnvModifier + Send + 'static,
{
execute_transaction_with_evm_modifier(block_env, tx, db, |_| {}).await
}

pub async fn execute_transaction_with_evm_modifier<DB, DBError, Tx>(
block_env: BlockEnv,
tx: Tx,
db: DB,
evm_modifier: impl FnOnce(&mut Evm<'_, (), &mut WrapAsyncDatabase<DB>>) + Send + 'static,
) -> EVMResult<DB::Error>
where
DB: AsyncDatabase<Error = DBError> + Send + 'static,
DBError: Send + 'static,
Expand All @@ -99,7 +85,6 @@ where
let rt = runtime::Runtime::new().expect("to create Runtime within spawn_blocking");
let mut db = WrapAsyncDatabase::new(db, rt);
let mut evm = create_evm(block_env, &tx, &mut db);
evm_modifier(&mut evm);
evm.transact()
})
.await
Expand Down

0 comments on commit 1d8a5ad

Please sign in to comment.