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

Web3 crashes in time-based gas price strategies with empty chain #1149

Closed
fredo opened this issue Nov 29, 2018 · 2 comments · Fixed by #3103
Closed

Web3 crashes in time-based gas price strategies with empty chain #1149

fredo opened this issue Nov 29, 2018 · 2 comments · Fixed by #3103

Comments

@fredo
Copy link

fredo commented Nov 29, 2018

  • Version: 4.7.1
  • Python: 3.6
  • OS: linux

What was wrong?

Running our test suite web3 crashes when estimating time based gas price. Probably it is caused by not having any transactions in our test chain. However when probabilities are calculated they are empty (empty tuple) which causes then an Index Error in '104, in _compute_gas_price\r\n first = probabilities[0]\r\nIndexError: tuple index out of range\

It might be the case that there is a problem with our geth client during runtime.

File “/home/circleci/raiden/raiden/network/rpc/client.py”, line 346, in gas_price
return int(self.web3.eth.generateGasPrice())
File “/home/circleci/venv-3.7/lib/python3.7/site-packages/web3/eth.py”, line 385, in generateGasPrice
return self.gasPriceStrategy(self.web3, transaction_params)
File “/home/circleci/venv-3.7/lib/python3.7/site-packages/web3/gas_strategies/time_based.py”, line 168, in time_based_gas_price_strategy
gas_price = _compute_gas_price(probabilities, probability / 100)
File “/home/circleci/venv-3.7/lib/python3.7/site-packages/web3/gas_strategies/time_based.py”, line 104, in _compute_gas_price
first = probabilities[0]
IndexError: tuple index out of range

How can it be fixed?

However I would suggest handling the edge case that there is an empty tuple and not unconditionally access first = probabilities[0]

I'm happy to give more information when needed

@carver
Copy link
Collaborator

carver commented Dec 11, 2018

Yes, I believe this is a known issue. I'll leave it open for tracking.

I think the current solution is: don't try to estimate gas if you don't have any transactions to go on (which is obviously unsatisfying).

But, I'm also not sure what the estimate function should do otherwise. I don't think it would be appropriate to return any number, or None (requiring return value checking is bad:tm:).

The only better option I can think of is to raise a ValidationError that is clearly saying that there are no transactions to base an estimate on.

Any other ideas?

@palango
Copy link
Contributor

palango commented Apr 16, 2019

I'd argue that the best fallback would be to use web3.eth.gasPrice.

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 a pull request may close this issue.

3 participants