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 the gas cost of a SC call #439

Open
peterjah opened this issue Aug 3, 2023 · 5 comments
Open

estimate the gas cost of a SC call #439

peterjah opened this issue Aug 3, 2023 · 5 comments

Comments

@peterjah
Copy link
Collaborator

peterjah commented Aug 3, 2023

In order to set appropriate gas fee and "coins" when calling a SC function (write call with callSmartContract) I need a way to estimate it given the actual network conditions.
Prior to submit my operation, i was said that i can use "readSmartContract" to get this estimation.

So I tried and it seems there is a bug with maxGas:

when i put a random amount a got something like
Not enough gas, limit reached at: increaseAllowance | Init cost is 266754
I precise that i tried with a value > 266754

if i put a big value like 1000000000000
The gas submitted 1000000000000 exceeds the max. allowed block gas of 4294967295

if i put the max allowed value 4294967295, the function throws

image

So i think there is a bug to fix. and also, what is the meaning of "maxGas" here ??? readonly is supposed to be free, right ?

@Ben-Rey Ben-Rey self-assigned this Aug 3, 2023
@peterjah
Copy link
Collaborator Author

peterjah commented Aug 3, 2023

nb: maybe 266754 is the value i am searching and to be used in "coin" parameter of callSmartContract, but it would be nice to return it withour throwing :)

@peterjah
Copy link
Collaborator Author

peterjah commented Aug 3, 2023

Something that will be greatly improve the developer experience, is to make the "fee" and "coins" parameters optionnal in callSmartContract. and it not provided web3 will internally call that "estimategas" function and set the appropriate values.
It will allow developer to not bother of these and it will fit their need most of the time. It will also avoid forcing user to set value when they have no idea of what is the good one.

@AurelienFT
Copy link
Contributor

You should always place the max in maxgas of a readCallSmartContract so that it will return you the gas used that you can use for your estimation.

The maxGas could be useful in readCallSmartContract in case you want to try if an amount of gas is enough for an execution.

Maybe the exact max doesn't work try a bit lower.

@Ben-Rey Ben-Rey removed their assignment Aug 28, 2023
@Thykof
Copy link
Contributor

Thykof commented Mar 11, 2024

You should always place the max in maxgas of a readCallSmartContract so that it will return you the gas used that you can use for your estimation.

The maxGas could be useful in readCallSmartContract in case you want to try if an amount of gas is enough for an execution.

Maybe the exact max doesn't work try a bit lower.

about mas gas estimation, we see in practice that sometimes the gas estimated by massa-web3 just before submitting the operation is not enough. The read only return a amount of gas and it's not enough for the actual call executed just after. To prevent this, either fix a bug in the node or add +20 % to the estimation.

@Ben-Rey
Copy link
Collaborator

Ben-Rey commented Mar 12, 2024

You should always place the max in maxgas of a readCallSmartContract so that it will return you the gas used that you can use for your estimation.
The maxGas could be useful in readCallSmartContract in case you want to try if an amount of gas is enough for an execution.
Maybe the exact max doesn't work try a bit lower.

about mas gas estimation, we see in practice that sometimes the gas estimated by massa-web3 just before submitting the operation is not enough. The read only return a amount of gas and it's not enough for the actual call executed just after. To prevent this, either fix a bug in the node or add +20 % to the estimation.

@AurelienFT How the read could return less gas than needed to make the call ?

@Thykof Thykof changed the title estimate the gas and storage cost of a SC call estimate the gas cost of a SC call Mar 21, 2024
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

No branches or pull requests

4 participants