Skip to content

refactor: use pointer receivers consistently for 08-wasm keeper methods #8312

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package keeper
import sdk "github.com/cosmos/cosmos-sdk/types"

// MigrateContractCode is a wrapper around k.migrateContractCode to allow the method to be directly called in tests.
func (k Keeper) MigrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error {
func (k *Keeper) MigrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error {
return k.migrateContractCode(ctx, clientID, newChecksum, migrateMsg)
}

// GetQueryPlugins is a wrapper around k.getQueryPlugins to allow the method to be directly called in tests.
func (k Keeper) GetQueryPlugins() QueryPlugins {
func (k *Keeper) GetQueryPlugins() QueryPlugins {
return k.getQueryPlugins()
}

Expand Down
26 changes: 13 additions & 13 deletions modules/light-clients/08-wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ type Keeper struct {
}

// Codec returns the 08-wasm module's codec.
func (k Keeper) Codec() codec.BinaryCodec {
func (k *Keeper) Codec() codec.BinaryCodec {
return k.cdc
}

// GetAuthority returns the 08-wasm module's authority.
func (k Keeper) GetAuthority() string {
func (k *Keeper) GetAuthority() string {
return k.authority
}

// Logger returns a module-specific logger.
func (Keeper) Logger(ctx sdk.Context) log.Logger {
func (k *Keeper) Logger(ctx sdk.Context) log.Logger {
return moduleLogger(ctx)
}

Expand All @@ -57,17 +57,17 @@ func moduleLogger(ctx sdk.Context) log.Logger {
}

// GetVM returns the keeper's vm engine.
func (k Keeper) GetVM() types.WasmEngine {
func (k *Keeper) GetVM() types.WasmEngine {
return k.vm
}

// GetChecksums returns the stored checksums.
func (k Keeper) GetChecksums() collections.KeySet[[]byte] {
func (k *Keeper) GetChecksums() collections.KeySet[[]byte] {
return k.checksums
}

// getQueryPlugins returns the set query plugins.
func (k Keeper) getQueryPlugins() QueryPlugins {
func (k *Keeper) getQueryPlugins() QueryPlugins {
return k.queryPlugins
}

Expand All @@ -76,7 +76,7 @@ func (k *Keeper) setQueryPlugins(plugins QueryPlugins) {
k.queryPlugins = plugins
}

func (k Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler {
func (k *Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler {
return newQueryHandler(ctx, k.getQueryPlugins(), callerID)
}

Expand All @@ -85,7 +85,7 @@ func (k Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler
// 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) {
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) {
ctx.GasMeter().ConsumeGas(types.VMGasRegister.UncompressCosts(len(code)), "Uncompress gzip bytecode")
Expand Down Expand Up @@ -139,7 +139,7 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wa

// 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 {
func (k *Keeper) migrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error {
clientStore := k.clientKeeper.ClientStore(ctx, clientID)
wasmClientState, found := types.GetClientState(clientStore, k.cdc)
if !found {
Expand Down Expand Up @@ -184,7 +184,7 @@ func (k Keeper) migrateContractCode(ctx sdk.Context, clientID string, newChecksu
}

// GetWasmClientState returns the 08-wasm client state for the given client identifier.
func (k Keeper) GetWasmClientState(ctx sdk.Context, clientID string) (*types.ClientState, error) {
func (k *Keeper) GetWasmClientState(ctx sdk.Context, clientID string) (*types.ClientState, error) {
clientState, found := k.clientKeeper.GetClientState(ctx, clientID)
if !found {
return nil, errorsmod.Wrapf(clienttypes.ErrClientTypeNotFound, "clientID %s", clientID)
Expand All @@ -200,7 +200,7 @@ func (k Keeper) GetWasmClientState(ctx sdk.Context, clientID string) (*types.Cli

// GetAllChecksums is a helper to get all checksums from the store.
// It returns an empty slice if no checksums are found
func (k Keeper) GetAllChecksums(ctx sdk.Context) ([]types.Checksum, error) {
func (k *Keeper) GetAllChecksums(ctx sdk.Context) ([]types.Checksum, error) {
iterator, err := k.GetChecksums().Iterate(ctx, nil)
if err != nil {
return nil, err
Expand All @@ -221,7 +221,7 @@ func (k Keeper) GetAllChecksums(ctx sdk.Context) ([]types.Checksum, error) {

// HasChecksum returns true if the given checksum exists in the store and
// false otherwise.
func (k Keeper) HasChecksum(ctx sdk.Context, checksum types.Checksum) bool {
func (k *Keeper) HasChecksum(ctx sdk.Context, checksum types.Checksum) bool {
found, err := k.GetChecksums().Has(ctx, checksum)
if err != nil {
return false
Expand All @@ -231,7 +231,7 @@ func (k Keeper) HasChecksum(ctx sdk.Context, checksum types.Checksum) bool {
}

// InitializePinnedCodes updates wasmvm to pin to cache all contracts marked as pinned
func (k Keeper) InitializePinnedCodes(ctx sdk.Context) error {
func (k *Keeper) InitializePinnedCodes(ctx sdk.Context) error {
checksums, err := k.GetAllChecksums(ctx)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions modules/light-clients/08-wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func newQueryHandler(ctx sdk.Context, plugins QueryPlugins, callerID string) *qu

// GasConsumed implements the wasmvmtypes.Querier interface.
func (q *queryHandler) GasConsumed() uint64 {
return VMGasRegister.ToWasmVMGas(q.Ctx.GasMeter().GasConsumed())
return types.VMGasRegister.ToWasmVMGas(q.Ctx.GasMeter().GasConsumed())
}

// Query implements the wasmvmtypes.Querier interface.
func (q *queryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64) ([]byte, error) {
sdkGas := VMGasRegister.FromWasmVMGas(gasLimit)
sdkGas := types.VMGasRegister.FromWasmVMGas(gasLimit)

// discard all changes/events in subCtx by not committing the cached context
subCtx, _ := q.Ctx.WithGasMeter(storetypes.NewGasMeter(sdkGas)).CacheContext()
Expand All @@ -75,7 +75,7 @@ func (q *queryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64)
return res, nil
}

moduleLogger(q.Ctx).Debug("Redacting query error", "cause", err)
q.Ctx.Logger().With("module", "x/ibc-wasm").Debug("Redacting query error", "cause", err)
return nil, redactError(err)
}

Expand All @@ -91,10 +91,10 @@ type (
)

// Merge merges the query plugin with a provided one.
func (e QueryPlugins) Merge(x *QueryPlugins) QueryPlugins {
func (e *QueryPlugins) Merge(x *QueryPlugins) QueryPlugins {
// only update if this is non-nil and then only set values
if x == nil {
return e
return *e
}

if x.Custom != nil {
Expand All @@ -105,11 +105,11 @@ func (e QueryPlugins) Merge(x *QueryPlugins) QueryPlugins {
e.Stargate = x.Stargate
}

return e
return *e
}

// HandleQuery implements the ibcwasm.QueryPluginsI interface.
func (e QueryPlugins) HandleQuery(ctx sdk.Context, caller string, request wasmvmtypes.QueryRequest) ([]byte, error) {
func (e *QueryPlugins) HandleQuery(ctx sdk.Context, caller string, request wasmvmtypes.QueryRequest) ([]byte, error) {
if request.Stargate != nil {
return e.Stargate(ctx, request.Stargate)
}
Expand Down