-
Notifications
You must be signed in to change notification settings - Fork 342
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
Call migrate method only when there is a change in the contract's state required #2087
Comments
At first, I didn't like it being required, as I've seen this argument that we might want to completely not implement migration because we know the state doesn't change. Then it occurred to me it is not a problem - if the What is the I don't really see a reason to bring any compatibility to In general looks good, mi big issue is the macro name. I understand that simple macro names are more likely to collide, but this one is really long. If you don't like |
Very good stuff. I'm not really sure what the best way is to pass the old
I would say we call migrate whenever the versions are different. This allows the contract to somehow handle downgrades (e.g. old version is 5, new version is 3). I'd probably just error for those cases in the contract but better than just skipping the migrate call. |
Right, I forgot
+1 |
What about such a change in the #[set_contract_state_version(3)]
pub fn migrate(deps: DepsMut, env: Env, state_version_on_chain: Option<u64>, msg: MigrateMsg) -> StdResult<Response> {
// [...]
} So there are two things added:
I agree, it makes sense to call
I was also thinking about it, but rejected that idea for the same reason - the |
It would be nice to create a #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct MigrateInfo {
pub sender: Addr,
// no funds here
pub old_state_version: Option<u64>
}
// [...]
#[set_contract_state_version(3)]
pub fn migrate(deps: DepsMut, env: Env, info: MigrateInfo, msg: MigrateMsg) -> StdResult<Response> {
// [...]
} But this is breaking and not easy to implement |
We could implement it non-breaking by checking for the function arity first before calling into the contract, but it would indeed not be easy because all the abstractions we currently have around calling functions assume that we know the number of arguments beforehand. Also if we do that, we should make |
I like that as it might be a bit of work, but we put the burden on us instead of the contract developer. Developers can then swictch from 3 arg to 4 arg whenever they feel like. In the public wasmvm interface we can have two different calls (like |
This is pretty cool. We can extend the low level call_function to use different params depending on the arity of the function we load anyways. See #2115 |
I've update the issue's description with all those suggestions. Two sub-issues are created to resolve this issue. |
Two PRs to be merged: |
Closing this as the CosmWasm part is done and further development will be done in the two PRs mentioned above. |
Contract's state version in the wasm binary
Currently each time a new contract binary version is uploaded to Cosmwasm it is required to call a
migrate
entry point method. The purpose of this entry point is to let the contract to align the state stored on the blockchain to the new version of the contract. Lack of themigrate
entry point in the contract results in an error.However there are significantly many cases when the binary is uploaded but it doesn't change the state in the process, for e.g. bug fixing, new implementation basing on the current version of the state etc. It is a problem, because each call of a migrate method (even the one that does almost nothing) costs gas. In a big scale it might increase the costs quite significantly.
Required steps
There are two sub-issues to be resolved for this issue:
migrate
call with extraMigrateInfo
argument after contract update #2117Result
CosmWasm will provide the on-chain state version of the contract in the new message:
Once the current version is provided, developers could implement the migration procedure in a new way. The example of the new approach:
The text was updated successfully, but these errors were encountered: