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

[Research] Gas settings in mainnet #53

Closed
Tracked by #52
daniel-farina opened this issue Jun 28, 2022 · 6 comments
Closed
Tracked by #52

[Research] Gas settings in mainnet #53

daniel-farina opened this issue Jun 28, 2022 · 6 comments
Labels
⚙️ task A task belongs to an epic

Comments

@daniel-farina
Copy link
Contributor

No description provided.

@daniel-farina daniel-farina added the ⚙️ task A task belongs to an epic label Jun 28, 2022
@iboss-ptk iboss-ptk self-assigned this Jun 28, 2022
@ValarDragon
Copy link
Member

For some more context: I believe I was concerned about on mainnet you can't easily submit txs that take > 25M gas.

How much gas do contract uploads / proposals take? If more than this, we need to start asking validators / nodes to increase this config param

@iboss-ptk
Copy link
Collaborator

iboss-ptk commented Jun 30, 2022

I think let's look at biggest code stored on terra / juno and try submitting that on our testnet, monitor gas consumption? That should give us good hints. The gas consumption calc logic is consistent across the chains (local/testnet/mainnet), am I correct?

@apollo-sturdy
Copy link

apollo-sturdy commented Jun 30, 2022

I think let's look at biggest code stored on terra / juno and try submitting that on our testnet, monitor gas consumption? That should give us good hints. The gas consumption calc logic is consistent across the chains (local/testnet/mainnet), am I correct?

I can give some insight on this. On Terra, the max_contract_size parameter was set to 614400 bytes. We were constantly bumping up against this and needed to do a bunch of optimizations and workarounds to keep one of our contracts below this size. Here's an example of a MsgStoreCode where we upload a contract that is 612Kb.

The gas used was 7,437,249. At the standard Terra gas price of 0.15uusd this should have cost $1.11 if unused gas would have been refunded (any insight on if gas refunds are being worked on?). This feels like an okay price for uploading a contract, but I would say that the cost of uploading contracts is not very important since it won't be done very often. Instead it makes more sense to look at how much gas a typical CosmWasm contract execution takes. This of course varies a lot depending on how complex the execution is, but as an example here is a transaction where someone is exiting an Apollo vault. This used 3,994,206 gas and would have cost $0.59, which I personally feel is somewhat high. What I've discovered is that most code in CosmWasm use almost no gas at all, and that almost all the gas is used by doing SmartQueries and returning CosmosMsgs from ExecuteMsg handlers. @ethanfrey has told me that it needs to be this way because loading those called contracts into memory takes time for the validator's and thus if this were cheap to do the block time could increase (Ethan: please correct me if I misremember your explanation). He suggested a workaround for this would be to flag certain contracts as always staying in the validators' memory. This seems like it could be a viable solution on Osmosis since it is permissioned and likely won't have many contracts.

@ValarDragon
Copy link
Member

The osmosis gas cost is about 100x cheaper today then were Terra was at, so in terms of gas USD costs I don't think we need to be super worried.

On Osmosis, the current max contract size is 800kB as far as I understand: https://github.com/CosmWasm/wasmd/blob/main/x/wasm/types/validation.go#L11-L12

Looks like for contract uploads we maybe don't need to be worried? (Frey mentioned at one point that theres is a notably gas overhead for the governance proposals over a normal upload. Can someone post once they try that) We run into 25M limits at the moment, which seems fine.

There is no unused gas refund work going on, its blocked on subsequent SDK releases right now.

Those gas counts do look excessive for exiting an apollo vault, we should look into we can tune down that gas amount. Or get those contracts in a cache, especially as in Osmosis we have bounded amounts of wasm code. Right now, 4M gas / contract call would lead to Osmosis blocks getting filled rather quickly.

@daniel-farina
Copy link
Contributor Author

Ok great I'll report on the progress on #59 as we test the gas settings.

@iboss-ptk iboss-ptk removed their assignment Jul 6, 2022
@apollo-sturdy
Copy link

Those gas counts do look excessive for exiting an apollo vault, we should look into we can tune down that gas amount. Or get those contracts in a cache, especially as in Osmosis we have bounded amounts of wasm code. Right now, 4M gas / contract call would lead to Osmosis blocks getting filled rather quickly.

Yeah as mentioned I think almost all of the gas is due to SmartQuery and returning CosmosMsgs from ExecuteMsg handlers. This can be optimized somewhat, but often leads to more complex code. Pinning/caching seems like the best option to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ task A task belongs to an epic
Projects
Status: Done
Development

No branches or pull requests

4 participants