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

Pin code to the wasm VM cache #4093

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/light-clients/08-wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know I wrote this in the issue, but now that I look at it, I think it's better if we do (because it's more consistent with error wrapping standards in ibc-go):

Suggested change
return nil, errorsmod.Wrap(types.ErrPinContractFailed, err.Error())
return nil, errorsmod.Wrap(err, "pinning contract failed")

And the we don't need to ErrPinContractFailed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in e18cd55

Copy link
Member

@damiannolan damiannolan Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to pin the contract to the vm LRU cache, correct? nit from me, but maybe we could adjust the in-line code comment and error msg to reflect that?

maybe something like: errorsmod.Wrap(err, "failed to pin contract to vm cache")

could be good to check if the err returned from wasmvm.Pin() includes the codeHash or if we should include that also as a Wrapf() arg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// 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))
Expand Down
1 change: 1 addition & 0 deletions modules/light-clients/08-wasm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)