Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: exact gasUsed for eth_createAccessList #10422

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,31 +259,24 @@ pub trait EthCall: Call + LoadPendingBlock {
let precompiles = get_precompiles(env.handler_cfg.spec_id);
let mut inspector = AccessListInspector::new(initial, from, to, precompiles);

let (result, env) = self.inspect(&mut db, env, &mut inspector)?;
let (_, mut env) = self.inspect(&mut db, env, &mut inspector)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now ignores the result of the initial call, I'd like to keep that and only apply the transact after the match.

I'm fine with having another match result for the transact call

let access_list = inspector.into_access_list();

match result.result {
env.tx.access_list = access_list.to_vec();
let (res, _) = self.transact(&mut db, env.clone())?;
match res.result {
ExecutionResult::Halt { reason, gas_used } => {
let error =
Some(RpcInvalidTransactionError::halt(reason, env.tx.gas_limit).to_string());
return Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error })
Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error })
}
ExecutionResult::Revert { output, gas_used } => {
let error = Some(RevertError::new(output).to_string());
return Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error })
Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error })
}
ExecutionResult::Success { .. } => {}
};

let cfg_with_spec_id =
CfgEnvWithHandlerCfg { cfg_env: env.cfg.clone(), handler_cfg: env.handler_cfg };

// calculate the gas used using the access list
request.access_list = Some(access_list.clone());
let gas_used =
self.estimate_gas_with(cfg_with_spec_id, env.block.clone(), request, &*db.db, None)?;

Ok(AccessListResult { access_list, gas_used, error: None })
ExecutionResult::Success { gas_used, .. } => {
Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error: None })
}
}
}
}

Expand Down
Loading