Skip to content

Commit

Permalink
chore: Call only MigrateWithInfo and move arity check to cw-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Aug 28, 2024
1 parent 797cfa0 commit adda66f
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 277 deletions.
23 changes: 3 additions & 20 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (k Keeper) callMigrateEntrypoint(
msg []byte,
newCodeID uint64,
senderAddress sdk.AccAddress,
OldMigrateVersion *uint64,
oldMigrateVersion *uint64,
) (*wasmvmtypes.Response, error) {
setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(sdkCtx, newCodeID), len(msg))
sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: migrate")
Expand All @@ -570,26 +570,9 @@ func (k Keeper) callMigrateEntrypoint(

migrateInfo := wasmvmtypes.MigrateInfo{
Sender: senderAddress.String(),
OldMigrateVersion: OldMigrateVersion,
}
var res *wasmvmtypes.ContractResult
var gasUsed uint64
var err error
if OldMigrateVersion == nil {
res, gasUsed, err = k.wasmVM.Migrate(newChecksum, env, msg, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)
if err != nil {
if strings.Contains(err.Error(), "The called function args arity does not match") {
res, gasUsed, err = k.wasmVM.MigrateWithInfo(newChecksum, env, msg, migrateInfo, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)
}
}
} else {
res, gasUsed, err = k.wasmVM.MigrateWithInfo(newChecksum, env, msg, migrateInfo, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)
if err != nil {
if strings.Contains(err.Error(), "The called function args arity does not match") {
res, gasUsed, err = k.wasmVM.Migrate(newChecksum, env, msg, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)
}
}
OldMigrateVersion: oldMigrateVersion,
}
res, gasUsed, err := k.wasmVM.MigrateWithInfo(newChecksum, env, msg, migrateInfo, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gasLeft, costJSONDeserialization)

k.consumeRuntimeGas(sdkCtx, gasUsed)
if err != nil {
Expand Down
Loading

0 comments on commit adda66f

Please sign in to comment.