Closed tochka closed 5 years ago
Correct and this is documented (albeit poorly) (e.g. https://cosmos.network/docs/cosmos-hub/gaiacli.html#gaia-cli). Gas estimation is not accurate and hence we have the gas-adjustment
flag. This is because during simulation:
What are you looking to propose here?
I assume to add:
gas= round(simulated_gas_amount * min_gas_price,1)/min_gas_price
for example:
min_gas_price=0.001atom
simulated_gas_amount=26432
fee =round(0.001atom * 26432,1)= 27atom - rounding to a larger integer
gas = (27atom/0.001atom) = 27000
@tochka not sure I follow. The ante handler has nothing to do (directly) with variations in gas costs between simulation and actual execution. Also, I don't see how you would come up with min_gas_price
-- this value is not part of consensus.
@alexanderbez you can add minimal fees when you send Tx to simulation it'll help enter inside this condition. GasMeter used for read and write data to the storage (there is the table of operation gas price.
@tochka you can already provide fees when simulating.
@alexanderbez you cannot do that when you set --gas auto
so txBld.gas is 0 so fees is 0.
It happens when you execute the following command
cli tx send {from_address} {to_address} --gas auto --gas-prices 1atom
@tochka yes, you can.
$ gaiacli tx send cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f 10stake --chain-id=chain-ZTQObJ -b block -y --home ./build/node0/gaiacli --gas=auto --dry-run
BUILDING TX FOR SIMULATION
FEES: { 0}
gas estimate: 26812
$ gaiacli tx send cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f 10stake --chain-id=chain-ZTQObJ -b block -y --home ./build/node0/gaiacli --gas=auto --dry-run --fees=2stake
BUILDING TX FOR SIMULATION
FEES: {2stake 0}
gas estimate: 43513
Notice how I pass --gas=auto
and --fees
.
@alexanderbez so when I want to send Tx I need do two operations:
gaiacli tx send cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f 10stake --chain-id=chain-ZTQObJ -b block -y --home ./build/node0/gaiacli --gas=auto --dry-run --fees=1stake
)gaiacli tx send cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f cosmos1dfp05pasnts7a4lupn889vptjtrxzkk5f7027f 10stake --chain-id=chain-ZTQObJ -b block -y --home ./build/node0/gaiacli --gas=43513 --gas-prices 0.0001stake
)Do you think it's an easy way for customers? Please look at your estimated gas with and without fees they differ by two orders of magnitude.
@tochka
so when I want to send Tx I need do two operations: ...
No, you misunderstand. Just a single command/request. My post demonstrates that you can supply fees when simulating gas. The --dry-run
flag in my post just prohibits the tx from being broadcast. It is just showing the gas difference between using fees and no fees which you stated was not possible, but it is.
Please look at your estimated gas with and without fees they differ by two orders of magnitude.
Yes, exactly the point. Showing that gas simulation does take fees into account.
I recommend reading up on this issue: https://github.com/cosmos/cosmos-sdk/issues/4938 for further details on what we plan on improving.
Summary of Bug
The function of Automatic gas calculation works incorrectly. When a client sends
--gas auto
from the CLI the client gets the incorrect amount which is rejected after sending the real Tx. It's related to the reward of a node (fee). The gas is used to move from a signer account to the fee pool (get and write account data to a store). When the CLI sends a simulation Tx the fee amount is empty so the program skips fee movement (~13000 of gas) for more details see https://github.com/cosmos/cosmos-sdk/blob/v0.36.0-rc3/x/auth/ante.go#L120Version
github.com/cosmos/cosmos-sdk v0.36.0-rc3
Steps to Reproduce
Build cli and create tx with --gas auto.
For Admin Use