Skip to content

Commit

Permalink
nit: add documentation for store/migrate contract on Keeper (#6162)
Browse files Browse the repository at this point in the history
* nit: add documentation for private methods that are too spicy (re: complex) to not document.

* Update modules/light-clients/08-wasm/keeper/keeper.go

Co-authored-by: Damian Nolan <[email protected]>

---------

Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
DimitrisJim and damiannolan authored Apr 16, 2024
1 parent 27ec802 commit 8af554c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/light-clients/08-wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (k Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler
return newQueryHandler(ctx, k.GetQueryPlugins(), callerID)
}

// storeWasmCode stores the contract to the VM, pins the checksum in the VM's in memory cache and stores the checksum
// in the 08-wasm store. The checksum identifying it is returned if successful. The following checks are made to the
// contract code before storing:
// - Size bounds are checked. Contract length must not be 0 or exceed a specific size (maxWasmSize).
// - The contract must not have already been stored in store.
func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wasmvm.WasmCode, gasLimit uint64) (wasmvm.Checksum, uint64, error)) ([]byte, error) {
var err error
if types.IsGzip(code) {
Expand Down Expand Up @@ -134,6 +139,8 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wa
return checksum, nil
}

// migrateContractCode migrates the contract for a given light client to one denoted by the given new checksum. The checksum we
// are migrating to must first be stored using storeWasmCode and must not match the checksum currently stored for this light client.
func (k Keeper) migrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error {
wasmClientState, err := k.GetWasmClientState(ctx, clientID)
if err != nil {
Expand Down

0 comments on commit 8af554c

Please sign in to comment.