fix: handle access list gas requirements (#54)

This commit is contained in:
Noah Citron 2022-09-23 20:37:28 -04:00 committed by GitHub
parent 4a347e3b2c
commit 1196c0181d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

@ -36,7 +36,7 @@ impl<R: Rpc> Evm<R> {
}
pub fn call(&mut self, opts: &CallOpts) -> Result<Vec<u8>> {
let account_map = self.batch_fetch_accounts(opts);
let account_map = self.batch_fetch_accounts(opts)?;
self.evm.db.as_mut().unwrap().set_accounts(account_map);
self.evm.env = self.get_env(opts);
@ -54,7 +54,7 @@ impl<R: Rpc> Evm<R> {
}
pub fn estimate_gas(&mut self, opts: &CallOpts) -> Result<u64> {
let account_map = self.batch_fetch_accounts(opts);
let account_map = self.batch_fetch_accounts(opts)?;
self.evm.db.as_mut().unwrap().set_accounts(account_map);
self.evm.env = self.get_env(opts);
@ -68,7 +68,7 @@ impl<R: Rpc> Evm<R> {
Ok(gas_scaled)
}
fn batch_fetch_accounts(&self, opts: &CallOpts) -> HashMap<Address, Account> {
fn batch_fetch_accounts(&self, opts: &CallOpts) -> Result<HashMap<Address, Account>> {
let db = self.evm.db.as_ref().unwrap();
let rpc = db.execution.rpc.clone();
let payload = db.payload.clone();
@ -124,7 +124,7 @@ impl<R: Rpc> Evm<R> {
Ok::<_, eyre::Error>(accounts)
});
let accounts = handle.join().unwrap().unwrap();
let accounts = handle.join().unwrap()?;
let mut account_map = HashMap::new();
accounts.iter().for_each(|account| {
let addr = account.0;
@ -132,7 +132,7 @@ impl<R: Rpc> Evm<R> {
account_map.insert(addr, account);
});
account_map
Ok(account_map)
}
fn get_env(&self, opts: &CallOpts) -> Env {

View File

@ -58,18 +58,19 @@ impl Rpc for HttpRpc {
async fn create_access_list(&self, opts: &CallOpts, block: u64) -> Result<AccessList> {
let block = Some(BlockId::from(block));
let mut tx = Eip1559TransactionRequest::new();
tx.to = Some(opts.to.into());
tx.from = opts.from;
tx.value = opts.value;
// TODO: better way to set gas limit
tx.gas = Some(U256::from(10_000_000));
tx.data = opts
let mut raw_tx = Eip1559TransactionRequest::new();
raw_tx.to = Some(opts.to.into());
raw_tx.from = opts.from;
raw_tx.value = opts.value;
raw_tx.gas = Some(opts.gas.unwrap_or(U256::from(100_000_000)));
raw_tx.max_fee_per_gas = Some(U256::zero());
raw_tx.max_priority_fee_per_gas = Some(U256::zero());
raw_tx.data = opts
.data
.as_ref()
.map(|data| Bytes::from(data.as_slice().to_owned()));
let tx = TypedTransaction::Eip1559(tx);
let tx = TypedTransaction::Eip1559(raw_tx);
let list = self.provider.create_access_list(&tx, block).await?;
Ok(list.access_list)

View File

@ -2,7 +2,6 @@ use std::collections::BTreeMap;
use std::str::FromStr;
use ethers::types::{Address, H256, U256};
use ethers::utils::keccak256;
use ssz_rs::{List, Vector};
use common::utils::hex_str_to_bytes;