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

Fix gas calculation error. #908

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Changes from all 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
21 changes: 9 additions & 12 deletions cita-executor/core/src/cita_executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {

match result {
Ok(InterpreterResult::Normal(output, gas_left, logs)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
if let Err(e) = liquidtion(
self.state_provider.clone(),
store.clone(),
sender,
gas_price,
gas_limit.as_u64(),
gas_left,
refund,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand All @@ -280,14 +280,15 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
finalize_result.quota_left = U256::from(gas_left);
Copy link
Contributor

Choose a reason for hiding this comment

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

这了的finalize_result跟268行的finalize_result,在gas_left上处理不一致。
是否要一致处理?
还有254行的match的其他分支是否也要做同样的修改?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,是需要相应的更改。

finalize_result.logs = transform_logs(logs);
finalize_result.logs_bloom = logs_to_bloom(&finalize_result.logs);

trace!(
"Get data after executed the transaction [Normal]: {:?}",
output
);
finalize_result.output = output;
}
Ok(InterpreterResult::Revert(output, gas_left)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
if let Err(e) = liquidtion(
self.state_provider.clone(),
Expand All @@ -296,7 +297,6 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
gas_price,
gas_limit.as_u64(),
gas_left,
0,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand All @@ -315,16 +315,16 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
);
}
Ok(InterpreterResult::Create(output, gas_left, logs, addr)) => {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
let gas_left = gas_left + refund;
if self.payment_required() {
let refund = get_refund(store.clone(), sender, gas_limit.as_u64(), gas_left);
if let Err(e) = liquidtion(
self.state_provider.clone(),
store.clone(),
sender,
gas_price,
gas_limit.as_u64(),
gas_left,
refund,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand Down Expand Up @@ -357,7 +357,6 @@ impl<'a, B: DB + 'static> CitaExecutive<'a, B> {
gas_price,
gas_limit.as_u64(),
0,
0,
) {
finalize_result.exception = Some(ExecutedException::VM(e));
return finalize_result;
Expand Down Expand Up @@ -753,21 +752,19 @@ fn liquidtion<B: DB + 'static>(
gas_price: U256,
gas_limit: u64,
gas_left: u64,
refund: u64,
) -> Result<(), VMError> {
trace!(
"gas_price: {:?}, gas limit:{:?}, gas left: {:?}, refund: {:?}",
"gas_price: {:?}, gas limit:{:?}, gas left: {:?}",
gas_price,
gas_limit,
gas_left,
refund
);
state_provider
.borrow_mut()
.add_balance(&sender, gas_price * (gas_left + refund))?;
.add_balance(&sender, gas_price * gas_left)?;
state_provider.borrow_mut().add_balance(
&store.borrow().evm_context.coinbase,
gas_price * (gas_limit - gas_left - refund),
gas_price * (gas_limit - gas_left),
)?;
Ok(())
}
Expand Down