From 76c3da26a248c111779862c79f2edabeeed6a11a Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Sat, 15 Jul 2023 12:12:10 -0500 Subject: [PATCH 1/3] pin code to the wasm VM cache --- modules/light-clients/08-wasm/keeper/keeper.go | 5 +++++ modules/light-clients/08-wasm/types/errors.go | 1 + 2 files changed, 6 insertions(+) diff --git a/modules/light-clients/08-wasm/keeper/keeper.go b/modules/light-clients/08-wasm/keeper/keeper.go index 87f588c17d0..e1523406337 100644 --- a/modules/light-clients/08-wasm/keeper/keeper.go +++ b/modules/light-clients/08-wasm/keeper/keeper.go @@ -98,6 +98,11 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte) ([]byte, error) { return nil, errorsmod.Wrap(err, "failed to store contract") } + // pin the code in the vm + if err := k.wasmVM.Pin(codeHash); err != nil { + return nil, errorsmod.Wrap(types.ErrPinContractFailed, err.Error()) + } + // safety check to assert that code ID returned by WasmVM equals to code hash if !bytes.Equal(codeHash, expectedHash) { return nil, errorsmod.Wrapf(types.ErrInvalidCodeID, "expected %s, got %s", hex.EncodeToString(expectedHash), hex.EncodeToString(codeHash)) diff --git a/modules/light-clients/08-wasm/types/errors.go b/modules/light-clients/08-wasm/types/errors.go index 44d31fbe688..55c0c2ab27d 100644 --- a/modules/light-clients/08-wasm/types/errors.go +++ b/modules/light-clients/08-wasm/types/errors.go @@ -11,4 +11,5 @@ var ( ErrWasmCodeTooLarge = errorsmod.Register(ModuleName, 5, "wasm code too large") ErrWasmCodeExists = errorsmod.Register(ModuleName, 6, "wasm code already exists") ErrWasmCodeIDNotFound = errorsmod.Register(ModuleName, 7, "wasm code id not found") + ErrPinContractFailed = errorsmod.Register(ModuleName, 8, "pinning contract failed") ) From e18cd55eadd98b2f8f50be8063d638fece987967 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Sat, 15 Jul 2023 15:33:34 -0500 Subject: [PATCH 2/3] follow ibc-go error wrapping standards --- modules/light-clients/08-wasm/keeper/keeper.go | 2 +- modules/light-clients/08-wasm/types/errors.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/light-clients/08-wasm/keeper/keeper.go b/modules/light-clients/08-wasm/keeper/keeper.go index e1523406337..b40d85c87e4 100644 --- a/modules/light-clients/08-wasm/keeper/keeper.go +++ b/modules/light-clients/08-wasm/keeper/keeper.go @@ -100,7 +100,7 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte) ([]byte, error) { // pin the code in the vm if err := k.wasmVM.Pin(codeHash); err != nil { - return nil, errorsmod.Wrap(types.ErrPinContractFailed, err.Error()) + return nil, errorsmod.Wrap(err, "pinning contract failed") } // safety check to assert that code ID returned by WasmVM equals to code hash diff --git a/modules/light-clients/08-wasm/types/errors.go b/modules/light-clients/08-wasm/types/errors.go index 55c0c2ab27d..44d31fbe688 100644 --- a/modules/light-clients/08-wasm/types/errors.go +++ b/modules/light-clients/08-wasm/types/errors.go @@ -11,5 +11,4 @@ var ( ErrWasmCodeTooLarge = errorsmod.Register(ModuleName, 5, "wasm code too large") ErrWasmCodeExists = errorsmod.Register(ModuleName, 6, "wasm code already exists") ErrWasmCodeIDNotFound = errorsmod.Register(ModuleName, 7, "wasm code id not found") - ErrPinContractFailed = errorsmod.Register(ModuleName, 8, "pinning contract failed") ) From ae182c97310b6af8b9b9f8d9c93fa14d1a83bda2 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 18 Jul 2023 10:31:22 +0200 Subject: [PATCH 3/3] Update modules/light-clients/08-wasm/keeper/keeper.go Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> --- modules/light-clients/08-wasm/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/light-clients/08-wasm/keeper/keeper.go b/modules/light-clients/08-wasm/keeper/keeper.go index b40d85c87e4..f1d4939d782 100644 --- a/modules/light-clients/08-wasm/keeper/keeper.go +++ b/modules/light-clients/08-wasm/keeper/keeper.go @@ -98,9 +98,9 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte) ([]byte, error) { return nil, errorsmod.Wrap(err, "failed to store contract") } - // pin the code in the vm + // pin the code to the vm in-memory cache if err := k.wasmVM.Pin(codeHash); err != nil { - return nil, errorsmod.Wrap(err, "pinning contract failed") + return nil, errorsmod.Wrapf(err, "failed to pin contract to vm cache %s", codeHash) } // safety check to assert that code ID returned by WasmVM equals to code hash