-
Notifications
You must be signed in to change notification settings - Fork 198
Estimate gas price #299
Estimate gas price #299
Conversation
@spalladino Could you take a look at this and let me know if it seems reasonable so far? |
@zachzundel looks good so far! A few comments:
let fixedGasPrice = checkGasPrice(txParams)
if (fixedGasPrice) {
txParams.gasPrice = fixedGasPrice
} |
Hi @spalladino -- I've updated my PR and I think I've fixed everything you pointed out. There was already a test for estimateGas that seems to cover my use case, please let me know if that's not correct and I will write another one! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @zachzundel, sorry for the delay on the review! We were offline during the past two weeks (devcon + team offsite), but we are now back on track.
The code looks good, thanks for addressing the concerns! There are only two things I think we need to review:
ethgasstation
provides gas price info for mainnet only, and its figures may not make sense for testnets. We should only execute the gas price query if we are on mainnet (ienetwork_id=1
), and use the default gas price value if on testnet.- The tests for estimateGas only check gas usage, not gas price; we should add a test that checks that the gas price from ethgasstation is used if no gas price is provided. I'd suggest stubbing the axios response using
sinon
(check out other tests inTransactions.test.js
for inspiration). And since we're at it, another test to check that ethgasstation is not queried if a gasPrice is provided.
Last but not least, I'd add a safeguard on the gas price in case ethgasstation returns a ridiculously high value. For instance, if the suggested gas price is over 100 gwei, let's throw an exception similar to what we're doing now, and ask the user to set a fixed gas price themselves.
How can we tell testnet vs. mainnet here? Is it something in |
The following line returns the network ID (I think that as a string, not a number), by querying the node to retrieve it. If it's equal to
Make sure we don't perform that query to node on every transaction. It should be enough to make it once, and cache the result. |
bfa6c00
to
89f40c2
Compare
@spalladino I've added in tests, this is ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @zachzundel! I left some minor comments, mostly regarding style. There are two changes I'd like to ask of you:
1- Can you revert changes to package-lock.json files that should not have been changed, except for zos-lib?
2- Can you add a test for the API returning a gas price value over 100 gwei?
Thanks a lot!!
- don't return txParams, just modify argument - use BigNumber functions instead of math - modify an error mssage
- also fix indentation - refactor tests to use beforeEach, afterEach
I've pushed commits to address all your changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @zachzundel!! Thanks a lot for the contribution, and for accommodating to all requests :-)
* Add axios and update package{,-lock}.json * Query for gas price * Persist gasPrice in state * Refactor and test * let -> const; safeLow -> average * Ensure gasPrice api doesn't pick a huge value * Check network * Cache network * Add test * Test update * Rollback all package-lock.json files * Package locks * Finalize tests * Remove unnecessary dependency * Minor stylistic changes - don't return txParams, just modify argument - use BigNumber functions instead of math - modify an error mssage * Add additional test for extreme API response - also fix indentation - refactor tests to use beforeEach, afterEach * Revert package lock changes
* Fix truffle dependencies versions and add truffle-provider * Fix runWithTruffle promise resolution * v2.0.2 * Uncomment git tag checkout (#402) * Update CLI package lock * Changelog for v2.0.1 (#403) [ci skip] * Rename versioned md links to html (#407) * Update testing guide (#406) * Add token mechanics section to the docs (#408) * Add token mechanics section to the docs * Update packages/docs/docs/docs/token_mechanics.md Co-Authored-By: facuspagnuolo <facuspagnuolo@users.noreply.github.com> * Add more tests for create command in CLI * Do not delete deployment info from other networks in truffle artifacts (#415) Upon creating a proxy for a contract, the current implementation clears all deployment information before adding the new one. It should only replace the info for the current network. * Example with truffle migrations (#416) * Estimate gas price (#299) * Add axios and update package{,-lock}.json * Query for gas price * Persist gasPrice in state * Refactor and test * let -> const; safeLow -> average * Ensure gasPrice api doesn't pick a huge value * Check network * Cache network * Add test * Test update * Rollback all package-lock.json files * Package locks * Finalize tests * Remove unnecessary dependency * Minor stylistic changes - don't return txParams, just modify argument - use BigNumber functions instead of math - modify an error mssage * Add additional test for extreme API response - also fix indentation - refactor tests to use beforeEach, afterEach * Revert package lock changes * Add Etherscan as remote verification application for 'verify' command (#413) * add etherscan as remote verification application for verify command * Add test for etherchain network parameter, improve output in Verifier, move etherscan verification status function out of main etherscan verify function * add how to get etherscan api key in description of verify's --api-key option * add tests for etherscan verification and return tests for etherchain verification * fix typo in etherscan tests * Minor code style changes * Use contract method `estimateGas` function (#310) Instead of using web3 estimateGas (only for contract method calls) * Fixed typo (#442) Line 131 typo on Adnd fixed * [CI skip] Fixed several typos and made minor improvements to the docs. * Remove legacy code from App and Lib distinction (#449) * Remove all `lib` references from scripts * Remove deprecated init-lib script * Remove `lib` references from scripts tests * Remove network and local `lib` controllers * Merge base and app controllers Merged base and app for both local and network controllers * Remove/rename deprecated mock contracts * Remove remaining `lib` references in cli models * Remove `lib` remaining references from cli tests * Rename all `lib` variables and references. Renamed all `lib`, `libToLink`, and their derivatives Renamed scripts and commands `lib` referencies, e.g., `deployLibs` variable to `deployDependencies` Renamed Network and Local controllers functions (e.g., `linkLibs` to `linkDependencies`) * Rename LibProject to PackageProject In both cli ProjectDeployer and lib Project classes * Update vouching deploy script * Preserve parameters compatibility in cli scripts * Rename dependenciesNames to dependencies * Add gas and gasPrice to mainnet docs instructions (#446) Attempting to deploy (and EVM package) using zos following the mainnet recomendations as listed here fails with the error: Cowardly refusing to execute transaction with excessively high default gas price of 100 gwei. Consider explicitly setting a different gasPrice value in your truffle.js config file. You can check reasonable values for gas price in https://ethgasstation.info/. We need to set the gas value and gas price. I added an example above, however this is not always enough either and can fail with either: ProviderError: insufficient funds for gas * price + value or Error: Contract transaction couldn't be found after 50 blocks or Error: ProviderError: gas required exceeds allowance or always failing transaction They contract may still be deployed however in the case of the final error example. * docs: add chai to the testing guide (#404) * Added encodeCall import (#422) * Added encodeCall import * Improve encodeCall import * Fix BigNumber promise call in doc site example (#444) * myContract.x().toString() does not return a number myContract.x().toString() does not return a number, it returns a promise object. myContract.x().toString() returns a pending promise: '[object Promise]' myContract.x() returns a bigNumber object: BigNumber { s: 1, e: 1, c: [ 42 ] } To return a string format of the returned promise object we need: myContract.x().then((num)=> num.toString()) will return '42' * Update v2.0.0 doc example * Delete mock contracts when publishing package (#293) Fixes zeppelinos/zos-lib#208 * Update v2.0.0 docs * Fix HTTP request to ethgasstation response handler * Change capital letters from test's descriptions * Add truffle-hdwallet-provider to integration tests * Remove sinon as main dependency from CLI * Remove truffle-workflow-compile in favour of shell compilation * Extend CLI Truffle dependency range to accept versions 4 & 5 * Add truffle bin check before compiling * Extend Initializable pragma version to support solc 0.5 * v2.1.0-rc.0 * Fix encodeCall address handling (#569) * Fix encodeCall address handling * Remove .only from encodeCall tests * Update truffle-migrate example to v2.1.0-rc.0 (#574) * v2.1.0 * Fix verify bad merge * Remove old NetworkController.js file
So far, I have the gas price being queried from the API if the default is being used. I still need to fix the tests and maybe add a
--gasPrice
flag to the CLI. This is for issue #56 .