Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

escape inifinite loop in estimte_gas #7075

Merged
merged 1 commit into from
Dec 4, 2017
Merged

escape inifinite loop in estimte_gas #7075

merged 1 commit into from
Dec 4, 2017

Conversation

miyao-gmo
Copy link
Contributor

@parity-cla-bot
Copy link

It looks like @miyao-gmo hasn'signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, plesae reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@miyao-gmo
Copy link
Contributor Author

[clabot:check]

@parity-cla-bot
Copy link

It looks like @miyao-gmo signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API. labels Nov 17, 2017
@5chdn 5chdn added this to the 1.9 milestone Nov 17, 2017
@rphmeier
Copy link
Contributor

I don't think this configuration belongs in the chain spec. It's also not really an infinite loop, just one bounded at an arbitrary 1 Trillion gas. We could reasonably set the upper limit to block_gas_limit * 100 or something like that without requiring additional configuration.

@rphmeier rphmeier added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 17, 2017
@miyao-gmo
Copy link
Contributor Author

I see.
I agree that upper limit is changed from 1 Trillion gas.
However, I think block_gas_limit * 100 is too large value, so block_gas_limit * 2 is enough.

@rphmeier
Copy link
Contributor

I think it'd be better if we had the upper limit still significantly greater than the block gas limit.

@miyao-gmo
Copy link
Contributor Author

OK.
I changed PR as you say.

@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Nov 27, 2017
let initial_upper = env_info.gas_limit;
env_info.gas_limit = UPPER_CEILING.into();
(initial_upper, env_info)
let upper = env_info.gas_limit * U256::from(100); // enough gas for estimate_gas
Copy link
Collaborator

Choose a reason for hiding this comment

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

The loggic is quite different now.

Previously:

  1. Start with block_gas_limit
  2. If that's not enough proceed with UPPER_CEILING.

Currently:

  1. Start with block_gas_limit * 100

I think we should keep the starting point at block_gas_limit, since it will converge much faster for valid transactions and fallback to 100 * limit only if the first fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a execution time in estimate_gas of a valid transaction with block_gas_limit is a same with block_gas_limit * 100, therefore, I changed to one phase estimate_gas from two phases.

I compared a execution time with block_gas_limit and block_gas_limit * 100.

> var calcValid = function() {
... var start = new Date().getTime();
... sample.validTx.estimateGas(function (err, gas) {
..... var end = new Date().getTime();
..... console.log(end - start);
..... });
... }

The following result is a execution time with block_gas_limit.

> calcValid()
undefined
> 75

The following is with block_gas_limit * 100.

> calcValid()
undefined
> 80

These result shows a execution time in estimate_gas of a valid transaction with block_gas_limit is a same with block_gas_limit * 100.

Copy link
Collaborator

@tomusdrw tomusdrw Dec 1, 2017

Choose a reason for hiding this comment

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

This time will depend on complexity of the transaction (CPU, IO). You can see that there is even a special case for transfer transactions (they will return immediately, by checking the lower bound first). I'm pretty positive that block_gas_limit will be faster by not running the transaction at least 6 times upfront. So if each transaction run takes 50ms it's a gain of 300ms which is huge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understood.
I will change PR as you say.

By the way, I think block_gas_limit * 100 is so large, but what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's pretty big, but afair users requested that estimate gas should work way over block gas limit. It's a significant improvement (in terms of time to fail) over what we have now, so I'm in favour of including this PR (or block_gas_limit * 10) for 1.9 and probably re-visiting it if we see that it still takes too much time for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, thank you.
I fixed.

@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 30, 2017
@tomusdrw
Copy link
Collaborator

tomusdrw commented Dec 1, 2017

Adding patch label, since we should also "fix" this in stable and beta.

@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Dec 1, 2017
@tomusdrw
Copy link
Collaborator

tomusdrw commented Dec 1, 2017

@miyao-gmo Thank you!

@rphmeier rphmeier merged commit e85c98e into openethereum:master Dec 4, 2017
tomusdrw pushed a commit that referenced this pull request Dec 4, 2017
tomusdrw pushed a commit that referenced this pull request Dec 5, 2017
arkpar pushed a commit that referenced this pull request Dec 8, 2017
* Merge pull request #7075 from miyao-gmo/feature/estimate_gas_limit

escape inifinite loop in estimte_gas

* Merge pull request #7006 from paritytech/no-uncles

Disable uncles by default

* Maximum uncle count transition (#7196)

* Enable delayed maximum_uncle_count activation.

* Fix tests.

* Defer kovan HF.

* Bump version.

* Kovan HF.

* Update Kovan HF block.

* Fix compilation issues.

* Fix aura test.

* Add missing byzantium builtins.

* Fix tests.

* Bump version for installers.

* Increase allowed time drift to 10s. (#7238)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants