Skip to content

Commit

Permalink
Metadata os param store addition (#1932)
Browse files Browse the repository at this point in the history
* start migration of os params, remove empty param keeper

* change os locator params to use module store

* add test

* add migrations

* add upgrade handler

* remove attributes params, fix upgrade handler, add tests

* add change log

* remove unneeded struct start time
  • Loading branch information
nullpointer0x00 authored Apr 16, 2024
1 parent 94add0f commit 55a96da
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Remove unused navs [#1920](https://github.com/provenance-io/provenance/issues/1920).
* Migrate module params from param space to module store.
* Attribute module param migration [#1927](https://github.com/provenance-io/provenance/pull/1927)
* Metadata module param migration [#1932](https://github.com/provenance-io/provenance/pull/1932)

### Dependencies

Expand Down
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func New(
)

app.MetadataKeeper = metadatakeeper.NewKeeper(
appCodec, keys[metadatatypes.StoreKey], app.GetSubspace(metadatatypes.ModuleName), app.AccountKeeper, app.AuthzKeeper, app.AttributeKeeper, app.MarkerKeeper,
appCodec, keys[metadatatypes.StoreKey], app.AccountKeeper, app.AuthzKeeper, app.AttributeKeeper, app.MarkerKeeper,
)

app.HoldKeeper = holdkeeper.NewKeeper(
Expand Down Expand Up @@ -1361,10 +1361,9 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)

paramsKeeper.Subspace(metadatatypes.ModuleName) // TODO[1760]: params: Migrate metadata params.
paramsKeeper.Subspace(markertypes.ModuleName) // TODO[1760]: params: Migrate marker params.
paramsKeeper.Subspace(nametypes.ModuleName) // TODO[1760]: params: Migrate name params.
paramsKeeper.Subspace(msgfeestypes.ModuleName) // TODO[1760]: params: Migrate msgFees params.
paramsKeeper.Subspace(markertypes.ModuleName) // TODO[1760]: params: Migrate marker params.
paramsKeeper.Subspace(nametypes.ModuleName) // TODO[1760]: params: Migrate name params.
paramsKeeper.Subspace(msgfeestypes.ModuleName) // TODO[1760]: params: Migrate msgFees params.
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(triggertypes.ModuleName) // TODO[1760]: params: Migrate trigger params.

Expand Down
17 changes: 17 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
)

// appUpgrade is an internal structure for defining all things for an upgrade.
Expand Down Expand Up @@ -57,6 +58,7 @@ var upgrades = map[string]appUpgrade{
}

migrateAttributeParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -89,6 +91,7 @@ var upgrades = map[string]appUpgrade{
}

migrateAttributeParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -301,3 +304,17 @@ func migrateAttributeParams(ctx sdk.Context, app *App) {
app.AttributeKeeper.SetParams(ctx, attributetypes.Params{MaxValueLength: uint32(maxValueLength)})
ctx.Logger().Info("Done migrating attribute params.")
}

// migrateAttributeParams migrates to new Metadata Os Locator Params store
// TODO: Remove with the umber handlers.
func migrateMetadataOSLocatorParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating metadata os locator params.")
metadataParamSpace := app.ParamsKeeper.Subspace(metadatatypes.ModuleName).WithKeyTable(metadatatypes.ParamKeyTable())
maxValueLength := uint32(metadatatypes.DefaultMaxURILength)
// TODO: remove metadatatypes.ParamStoreKeyMaxValueLength with the umber handlers.
if metadataParamSpace.Has(ctx, metadatatypes.ParamStoreKeyMaxValueLength) {
metadataParamSpace.Get(ctx, metadatatypes.ParamStoreKeyMaxValueLength, &maxValueLength)
}
app.MetadataKeeper.SetOSLocatorParams(ctx, metadatatypes.OSLocatorParams{MaxUriLength: uint32(maxValueLength)})
ctx.Logger().Info("Done migrating metadata os locator params.")
}
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Done migrating legacy params.",
"INF Migrating attribute params.",
"INF Done migrating attribute params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand All @@ -400,6 +402,8 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Done migrating legacy params.",
"INF Migrating attribute params.",
"INF Done migrating attribute params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand Down
4 changes: 1 addition & 3 deletions x/metadata/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

// InitGenesis creates the initial genesis state for the metadata module.
func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
k.SetParams(ctx, data.Params)
k.SetOSLocatorParams(ctx, data.OSLocatorParams)
if err := data.Validate(); err != nil {
panic(err)
Expand Down Expand Up @@ -78,7 +77,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {

// ExportGenesis exports the current keeper state of the metadata module.ExportGenesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
params := k.GetParams(ctx)
oslocatorparams := k.GetOSLocatorParams(ctx)
scopes := make([]types.Scope, 0)
sessions := make([]types.Session, 0)
Expand Down Expand Up @@ -163,5 +161,5 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
markerNetAssetValues[i] = markerNavs
}

return types.NewGenesisState(params, oslocatorparams, scopes, sessions, records, scopeSpecs, contractSpecs, recordSpecs, objectStoreLocators, markerNetAssetValues)
return types.NewGenesisState(types.Params{}, oslocatorparams, scopes, sessions, records, scopeSpecs, contractSpecs, recordSpecs, objectStoreLocators, markerNetAssetValues)
}
15 changes: 4 additions & 11 deletions x/metadata/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/provenance-io/provenance/x/metadata/types"
)
Expand Down Expand Up @@ -108,9 +107,8 @@ type MetadataKeeperI interface {
// Keeper is the concrete state-based API for the metadata module.
type Keeper struct {
// Key to access the key-value store from sdk.Context
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
storeKey storetypes.StoreKey
cdc codec.BinaryCodec

// To check if accounts exist and set public keys.
authKeeper AuthKeeper
Expand All @@ -127,17 +125,12 @@ type Keeper struct {

// NewKeeper creates new instances of the metadata Keeper.
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
authKeeper AuthKeeper, authzKeeper AuthzKeeper, attrKeeper AttrKeeper, markerKeeper MarkerKeeper,
cdc codec.BinaryCodec, key storetypes.StoreKey, authKeeper AuthKeeper,
authzKeeper AuthzKeeper, attrKeeper AttrKeeper, markerKeeper MarkerKeeper,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.OSParamKeyTable())
}
return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
authKeeper: authKeeper,
authzKeeper: authzKeeper,
attrKeeper: attrKeeper,
Expand Down
5 changes: 1 addition & 4 deletions x/metadata/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ func ownerPartyList(addresses ...string) []types.Party {
}

func (s *KeeperTestSuite) TestParams() {
s.T().Run("param tests", func(t *testing.T) {
p := s.app.MetadataKeeper.GetParams(s.ctx)
assert.NotNil(t, p)

s.T().Run("os param tests", func(t *testing.T) {
osp := s.app.MetadataKeeper.GetOSLocatorParams(s.ctx)
assert.NotNil(t, osp)
assert.Equal(t, osp.MaxUriLength, s.app.MetadataKeeper.GetMaxURILength(s.ctx))
Expand Down
33 changes: 22 additions & 11 deletions x/metadata/keeper/oslocatorparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ import (
"github.com/provenance-io/provenance/x/metadata/types"
)

// GetParams returns the total set of metadata parameters.
// GetOSLocatorParams returns the metadata OSLocatorParams.
func (k Keeper) GetOSLocatorParams(ctx sdk.Context) (osLocatorParams types.OSLocatorParams) {
return types.OSLocatorParams{
MaxUriLength: k.GetMaxURILength(ctx),
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.OSLocatorParamPrefix)
if bz == nil {
return types.OSLocatorParams{
MaxUriLength: types.DefaultMaxURILength,
}
}
err := k.cdc.Unmarshal(bz, &osLocatorParams)
if err != nil {
panic(err)
}
return osLocatorParams
}

// SetParams sets the distribution parameters to the param space.
// SetOSLocatorParams sets the metadata OSLocator parameters to the store.
func (k Keeper) SetOSLocatorParams(ctx sdk.Context, params types.OSLocatorParams) {
k.paramSpace.SetParamSet(ctx, &params)
bz, err := k.cdc.Marshal(&params)
if err != nil {
panic(err)
}

store := ctx.KVStore(k.storeKey)
store.Set(types.OSLocatorParamPrefix, bz)
}

// GetMaxURILength gets the configured parameter for max uri length on a locator record (or the default if unset)
// GetMaxURILength returns the configured parameter for max URI length on a locator record
func (k Keeper) GetMaxURILength(ctx sdk.Context) (max uint32) {
max = types.DefaultMaxURILength
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxValueLength) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxValueLength, &max)
}
return
return k.GetOSLocatorParams(ctx).MaxUriLength
}
49 changes: 49 additions & 0 deletions x/metadata/keeper/oslocatorparams_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package keeper_test

import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/app"
simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/x/metadata/types"
"github.com/stretchr/testify/suite"
)

type OSLocatorParamTestSuite struct {
suite.Suite

app *app.App
ctx sdk.Context
}

func (s *OSLocatorParamTestSuite) SetupTest() {
s.app = simapp.Setup(s.T())
s.ctx = s.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()})
}

func TestOSLocatorParamTestSuite(t *testing.T) {
suite.Run(t, new(OSLocatorParamTestSuite))
}

func (s *OSLocatorParamTestSuite) TestGetSetOSLocatorParams() {
defaultParams := s.app.MetadataKeeper.GetOSLocatorParams(s.ctx)
s.Require().Equal(int(types.DefaultMaxURILength), int(defaultParams.MaxUriLength), "GetOSLocatorParams() Default max URI length should match")

defaultUriLength := s.app.MetadataKeeper.GetMaxURILength(s.ctx)
s.Require().Equal(int(types.DefaultMaxURILength), int(defaultUriLength), "GetMaxURILength() Default max URI length should match")

newMaxUriLength := uint32(2048)
newParams := types.OSLocatorParams{
MaxUriLength: newMaxUriLength,
}
s.app.MetadataKeeper.SetOSLocatorParams(s.ctx, newParams)

updatedParams := s.app.MetadataKeeper.GetOSLocatorParams(s.ctx)
s.Require().Equal(int(newMaxUriLength), int(updatedParams.MaxUriLength), "GetOSLocatorParams() Updated max URI length should match")

updatedUriLength := s.app.MetadataKeeper.GetMaxURILength(s.ctx)
s.Require().Equal(int(newMaxUriLength), int(updatedUriLength), "GetMaxURILength() Updated max URI length should match")
}
15 changes: 0 additions & 15 deletions x/metadata/keeper/params.go

This file was deleted.

10 changes: 2 additions & 8 deletions x/metadata/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ var _ types.QueryServer = Keeper{}
// Params queries params of metadata module.
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Params")
ctx := sdk.UnwrapSDKContext(c)
var params types.Params
k.paramSpace.GetParamSet(ctx, &params)

resp := &types.QueryParamsResponse{Params: params}
resp := &types.QueryParamsResponse{Params: types.Params{}}
if req != nil && req.IncludeRequest {
resp.Request = req
}
Expand Down Expand Up @@ -1046,9 +1042,7 @@ func (k Keeper) GetByAddr(c context.Context, req *types.GetByAddrRequest) (*type
func (k Keeper) OSLocatorParams(c context.Context, request *types.OSLocatorParamsRequest) (*types.OSLocatorParamsResponse, error) {
defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSLocatorParams")
ctx := sdk.UnwrapSDKContext(c)
var params types.OSLocatorParams
k.paramSpace.GetParamSet(ctx, &params)

params := k.GetOSLocatorParams(ctx)
resp := &types.OSLocatorParamsResponse{Params: params}
if request != nil && request.IncludeRequest {
resp.Request = request
Expand Down
3 changes: 3 additions & 0 deletions x/metadata/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ var (

// NetAssetValuePrefix prefix for net asset values of scopes
NetAssetValuePrefix = []byte{0x22}

// OSLocatorParamPrefix prefix for os locator params
OSLocatorParamPrefix = []byte{0x23}
)

// GetAddressScopeCacheIteratorPrefix returns an iterator prefix for all scope cache entries assigned to a given address
Expand Down
2 changes: 2 additions & 0 deletions x/metadata/types/oslocatorparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
)

// ParamKeyTable for metadata module
// TODO: remove with the umber (v1.19.x) handlers.
func OSParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&OSLocatorParams{})
}
Expand All @@ -28,6 +29,7 @@ func NewOSLocatorParams(maxURILength uint32) OSLocatorParams {

// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of auth module's parameters.
// TODO: remove with the umber (v1.19.x) handlers.
func (p *OSLocatorParams) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMaxValueLength, &p.MaxUriLength, validateMaxURILength),
Expand Down

0 comments on commit 55a96da

Please sign in to comment.