CosmWasm / wasmd

Basic cosmos-sdk app with web assembly smart contracts
Other
364 stars 395 forks source link

Optional migrate entry point – allow more gas efficient migrations #1813

Closed webmaster128 closed 3 days ago

webmaster128 commented 6 months ago

When CosmWasm migrations were designed, we had 1 instance – 1 dev team in mind. The whole system assumes a small number of instances to handle. Recently we learned that more and more use cases are poping up in which many instances of a contract are created, dozens of pools, hundreds or DAOs, thousands of accounts. Having to send a MsgMigrateContract cand calling the contract for each message is gas intense and hard to manage.

While this ticket does no solve the full problem at once, it is a first step and actionable. The idea is this: not every migration needs a state change. Often times state changes can be done lazily or are not required at all. In those cases we can avoid calling the migrate entry point of the contract. Just swap out the code and call it a day.

This means not executing those lines: https://github.com/CosmWasm/wasmd/blob/7ea00e2ea858ed599141e322bd68171998a3259a/x/wasm/keeper/keeper.go#L475-L479

In such cases the msg field of MsgMigrateContract becomes optional.

If a call to the migrate entry point is needed or not should be decided by the new code. There the contract author can decide if the state needs to change or not. Luckily we have Entrypoints in AnalysisReport and can implement the following logic:

This avoids situations in which an expected msg is missing or a provided msg is ignored.

webmaster128 commented 4 months ago

In https://github.com/CosmWasm/cosmwasm/issues/2087 we discuss a more powerful solution that makes it easier to migrate from various old version of the contract

webmaster128 commented 3 days ago

Done in #1924. With that if two contracts have the same migrate version, the migrate entry point is not called