-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Using gas value provided by estimateGas triggers error even though tx succeeds #3175
Comments
@cgewecke Thanks for opening this issue! The gas check got completely fixed in 2.x and does only slightly differ from the gas check we have in 1.x. 1.x does throw the Btw.: I think to cover the gas validation logic would it require some smaller additional test cases. |
@cgewecke @nivida actually #3123 fixes a comparison that had been broken for a long time. As a side-effect, it looks like it also revealed another issue with the gas-checking logic. In order to handle both pre and post-byzantimum fork in a better way, additional checks have to be added. This is what we are currently using in our projects: --- a/node_modules/web3-core-method/src/index.js
+++ b/node_modules/web3-core-method/src/index.js
@@ -203,6 +203,7 @@ Method.prototype._confirmTransaction = function(defer, result, payload) {
lastBlock = null,
receiptJSON = '',
gasProvided = (_.isObject(payload.params[0]) && payload.params[0].gas) ? payload.params[0].gas : null,
+ isContractCall = _.isObject(payload.params[0]) && !!payload.params[0].data,
isContractDeployment = _.isObject(payload.params[0]) &&
payload.params[0].data &&
payload.params[0].from &&
@@ -394,8 +395,8 @@ Method.prototype._confirmTransaction = function(defer, result, payload) {
.then(function(receipt) {
if (!isContractDeployment && !promiseResolved) {
if (!receipt.outOfGas &&
- (!gasProvided || gasProvided !== utils.numberToHex(receipt.gasUsed)) &&
- (receipt.status === true || receipt.status === '0x1' || typeof receipt.status === 'undefined')) {
+ (!gasProvided || gasProvided !== utils.numberToHex(receipt.gasUsed) || !isContractCall || (isContractCall && receipt.events)) &&
+ (receipt.status === true || receipt.status === '0x1' || receipt.status === null || typeof receipt.status === 'undefined')) {
defer.eventEmitter.emit('receipt', receipt);
defer.resolve(receipt); I have not sent a PR with this because it needs to be tested thoroughly. In summary, if you have Is there a good test suite for this in |
Thanks @nivida @gabmontes! |
Does anyone know what client or fork actually attaches this field to the receipt? receipt.outOfGas |
This property doesn't exist officially only the ganache client does have it. |
This logic doesn't reject successfully mined transactions who exactly used the provided gas. The rules behind the status property are:
|
Well, this was unexpected. It behaved differently in version v1.2.1. (https://github.com/oceanprotocol/squid-js/pull/331/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L62) I was not expecting such a change in a patch release. |
Description
In 1.2.2, perfect gas throws an error. This problem was introduced in #3123. It looks like the modified logic is meant to handle pre-byzantium chain behavior where
gasUsed === gasSent
is a signal that the transaction was reverted. Post-byzantium, thestatus
field on the receipt is a more definitive check. There are also gas refunds which may make these estimates less useful overall.Perhaps there should be some community discussion about how to address this. Is there agreement that the estimates are imperfect and
estimate + something
should always be provided? If so, perhaps a docs clarification is all that is required.Conversely, the change could be see as de-facto breaking and reverted on those grounds.
@gabmontes What is your view of this? Could you provide more background on what execution contexts this gas check is necessary for?
Actual behavior
Versions
The text was updated successfully, but these errors were encountered: