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

Estimate_gas return issues #363

Merged
merged 5 commits into from
May 18, 2021

Conversation

boundless-forest
Copy link
Collaborator

If OutOfFund happened, should return right now instead of continuing with the estimating process.

@boundless-forest
Copy link
Collaborator Author

@sorpaas This pr is ready for review. Should I update the crate version?

@sorpaas
Copy link
Member

sorpaas commented Apr 22, 2021

Should I update the crate version?

Yeah. But I don't quiet understand the PR. With or without this condition it always returns. The difference is the error value the parent gets. Can you explain more about the PR?

@boundless-forest
Copy link
Collaborator Author

boundless-forest commented Apr 22, 2021

Can you explain more about the PR?

Sure, let me explain more details about this. Firstly, we have a pre-compile contract in which the transfer operation is performed.
Here and the transfer value comes from the input value.

So, when somebody estimates the gas used of calling this precompile contract, if the balance is not sufficient, an OutOfFund error will return. However, the estimate gas used logic here will misinterpret this as a result of insufficient gas and use more gas to estimate again util to the max. This is not the case in fact. The error occurs due to insufficient balance in the execution process instead of out of gas.

@cla-bot-2021
Copy link

cla-bot-2021 bot commented May 8, 2021

User @AsceticBear, please sign the CLA here.

@boundless-forest boundless-forest changed the title Return error when estimate_gas run into OutOfFund stimate_gas return issues May 8, 2021
@boundless-forest boundless-forest changed the title stimate_gas return issues Estimate_gas return issues May 8, 2021
@boundless-forest
Copy link
Collaborator Author

There is an estimate_gas bug when the calculate_gas_used(test_request) return error due to OutOfGas.

match calculate_gas_used(test_request) {
	// if Ok -- try to reduce the gas used
	Ok(used_gas) => {
		old_best = best;
		best = used_gas;
		change_pct = (U256::from(100) * (old_best - best)) / old_best;
		upper = mid;
		mid = (lower + upper + 1) / 2;
                log::debug!("bear: --- [Ok]: upper {:?}, mid {:?}", upper, mid);
	}

	Err(err) => {
                log::debug!("bear: --- the calculate gas used err! {:?}", err);
		// if Err == OutofGas or OutofFund, we need more gas
		if err.code == ErrorCode::ServerError(0) {
	             lower = mid;
		    mid = (lower + upper + 1) / 2;
		    log::debug!("bear: --- [err]: lower {:?}, mid {:?}", lower, mid);
		    if mid == lower {
			 break;
		    }
		}
	        // Other errors, return directly
	       return Err(err);
	}
}

debug info:

2021-05-08 15:16:01.710 DEBUG        http.worker10 dc_rpc::eth: bear: --- the calculate gas used err! Error { code: ServerError(0), message: "out of gas or fund", data: None }
2021-05-08 15:16:01.710 DEBUG        http.worker10 dc_rpc::eth: bear: --- [err]: lower 500010500, mid 750005250
2021-05-08 15:16:01.710 DEBUG        http.worker10 dc_rpc::eth: bear: --- change_pct 37, threshold_pct 10
2021-05-08 15:16:01.803 DEBUG        http.worker10 dc_rpc::eth: bear: --- [Ok]: upper 750005250, mid 625007875
2021-05-08 15:16:01.803 DEBUG        http.worker10 dc_rpc::eth: bear: --- change_pct 0, threshold_pct 10

As we can see above, The estimate process return error when calculate_gas_used result error code is ServerError(0) & mid != lower. That's incorrect behavior. @sorpaas Please take a review later.

@sorpaas
Copy link
Member

sorpaas commented May 14, 2021

Please modify the comment in L824. It's outdated!

@sorpaas sorpaas merged commit 6617295 into polkadot-evm:master May 18, 2021
@boundless-forest boundless-forest deleted the fix-estimate-gas-refund branch May 18, 2021 05:40
abhijeetbhagat pushed a commit to web3labs/frontier that referenced this pull request Jan 11, 2023
* Return error when OutOfFund

* Fix estimate_gas early return

* Update comments

* Update changelog

* Update message info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants