Skip to content

Commit

Permalink
Merge branch 'main' into dwedul/1760-sdk-customizations
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	app/upgrades.go
#	app/upgrades_test.go
  • Loading branch information
SpicyLemon committed Apr 16, 2024
2 parents af3e17d + 94add0f commit 9c30aa5
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Bump the SDK to `v0.50.5-pio-1` (from an earlier ephemeral version) [#1897](https://github.com/provenance-io/provenance/pull/1897).
* Removed `rewards` module [#1905](https://github.com/provenance-io/provenance/pull/1905).
* 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)
* Restore the hold module [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930).
Expand Down
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,10 @@ 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(attributetypes.ModuleName) // TODO[1760]: params: Migrate attribute params.
paramsKeeper.Subspace(msgfeestypes.ModuleName) // TODO[1760]: params: Migrate msgFees params.
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(wasmtypes.ModuleName)
paramsKeeper.Subspace(triggertypes.ModuleName) // TODO[1760]: params: Migrate trigger params.

Expand Down
20 changes: 20 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"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"
)

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

migrateAttributeParams(ctx, app)

err = migrateBankParams(ctx, app)
if err != nil {
return nil, err
Expand Down Expand Up @@ -92,10 +95,13 @@ var upgrades = map[string]appUpgrade{
return nil, err
}

migrateAttributeParams(ctx, app)

err = migrateBankParams(ctx, app)
if err != nil {
return nil, err
}

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
return nil, err
Expand Down Expand Up @@ -294,6 +300,20 @@ func migrateBaseappParams(ctx sdk.Context, app *App) error {
return nil
}

// migrateAttributeParams migrates to new Attribute Params store
// TODO: Remove with the umber handlers.
func migrateAttributeParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating attribute params.")
attributeParamSpace := app.ParamsKeeper.Subspace(attributetypes.ModuleName).WithKeyTable(attributetypes.ParamKeyTable())
maxValueLength := uint32(attributetypes.DefaultMaxValueLength)
// TODO: remove attributetypes.ParamStoreKeyMaxValueLength with the umber handlers.
if attributeParamSpace.Has(ctx, attributetypes.ParamStoreKeyMaxValueLength) {
attributeParamSpace.Get(ctx, attributetypes.ParamStoreKeyMaxValueLength, &maxValueLength)
}
app.AttributeKeeper.SetParams(ctx, attributetypes.Params{MaxValueLength: uint32(maxValueLength)})
ctx.Logger().Info("Done migrating attribute params.")
}

// migrateBankParams migrates the bank params from the params module to the bank module's state.
// The SDK has this as part of their bank v4 migration, but we're already on v4, so that one
// won't run on its own. This is the only part of that migration that we still need to have
Expand Down
16 changes: 12 additions & 4 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,16 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Done pruning expired consensus states for IBC.",
"INF Migrating legacy params.",
"INF Done migrating legacy params.",
"INF Migrating attribute params.",
"INF Done migrating attribute params.",
"INF Migrating bank params.",
"INF Done migrating bank 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.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
"INF A total of 0 inactive (unbonded) validators have had all their delegators removed.",
}

s.AssertUpgradeHandlerLogs("umber-rc1", expInLog, nil)
Expand All @@ -396,12 +400,16 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Done pruning expired consensus states for IBC.",
"INF Migrating legacy params.",
"INF Done migrating legacy params.",
"INF Migrating attribute params.",
"INF Done migrating attribute params.",
"INF Migrating bank params.",
"INF Done migrating bank 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.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
"INF A total of 0 inactive (unbonded) validators have had all their delegators removed.",
}

s.AssertUpgradeHandlerLogs("umber", expInLog, nil)
Expand Down
8 changes: 0 additions & 8 deletions x/attribute/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ type Handler func(record types.Attribute) error

// Keeper defines the attribute module Keeper
type Keeper struct {
// The reference to the Paramstore to get and set attribute specific params
paramSpace paramtypes.Subspace

// Used to ensure accounts exist for addresses.
authKeeper types.AccountKeeper
// The keeper used for ensuring names resolve to owners.
Expand All @@ -51,13 +48,8 @@ func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
authKeeper types.AccountKeeper, nameKeeper types.NameKeeper,
) Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

keeper := Keeper{
storeKey: key,
paramSpace: paramSpace,
authKeeper: authKeeper,
nameKeeper: nameKeeper,
cdc: cdc,
Expand Down
52 changes: 52 additions & 0 deletions x/attribute/keeper/param_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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/attribute/types"
"github.com/stretchr/testify/suite"
)

type ParamTestSuite struct {
suite.Suite

app *app.App
ctx sdk.Context

startBlockTime time.Time
}

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

func TestParamTestSuite(t *testing.T) {
suite.Run(t, new(ParamTestSuite))
}

func (s *ParamTestSuite) TestGetSetParams() {
defaultParams := s.app.AttributeKeeper.GetParams(s.ctx)
s.Require().Equal(int(types.DefaultMaxValueLength), int(defaultParams.MaxValueLength), "GetParams() Default max value length should match")

defaultValueLength := s.app.AttributeKeeper.GetMaxValueLength(s.ctx)
s.Require().Equal(int(types.DefaultMaxValueLength), int(defaultValueLength), "GetMaxValueLength() Default max value length should match")

newMaxValueLength := uint32(2048)
newParams := types.Params{
MaxValueLength: newMaxValueLength,
}
s.app.AttributeKeeper.SetParams(s.ctx, newParams)

updatedParams := s.app.AttributeKeeper.GetParams(s.ctx)
s.Require().Equal(int(newMaxValueLength), int(updatedParams.MaxValueLength), "GetParams() Updated max value length should match")

updatedValueLength := s.app.AttributeKeeper.GetMaxValueLength(s.ctx)
s.Require().Equal(int(newMaxValueLength), int(updatedValueLength), "GetMaxValueLength() Updated max value length should match")
}
33 changes: 22 additions & 11 deletions x/attribute/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ import (
"github.com/provenance-io/provenance/x/attribute/types"
)

// GetParams returns the total set of account parameters.
// GetParams returns the attribute Params.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.Params{
MaxValueLength: k.GetMaxValueLength(ctx),
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.AttributeParamPrefix)
if bz == nil {
return types.Params{
MaxValueLength: types.DefaultMaxValueLength,
}
}
err := k.cdc.Unmarshal(bz, &params)
if err != nil {
panic(err)
}
return params
}

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

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

// GetMaxValueLength returns the current distribution community tax (or default if unset)
// GetMaxValueLength returns the max value for attribute length.
func (k Keeper) GetMaxValueLength(ctx sdk.Context) (maxValueLength uint32) {
maxValueLength = types.DefaultMaxValueLength
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxValueLength) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxValueLength, &maxValueLength)
}
return
return k.GetParams(ctx).MaxValueLength
}
5 changes: 1 addition & 4 deletions x/attribute/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ var _ types.QueryServer = Keeper{}
// Params queries params of attribute module
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
var params types.Params
k.paramSpace.GetParamSet(ctx, &params)

return &types.QueryParamsResponse{Params: params}, nil
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
}

// Attribute queries for a specific attribute
Expand Down
1 change: 1 addition & 0 deletions x/attribute/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
AttributeKeyPrefix = []byte{0x02}
AttributeAddrLookupKeyPrefix = []byte{0x03}
AttributeExpirationKeyPrefix = []byte{0x04}
AttributeParamPrefix = []byte{0x05}
)

// AddrAttributeKey creates a key for an account attribute
Expand Down
3 changes: 3 additions & 0 deletions x/attribute/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
)

// Parameter store keys
// TODO: remove with the umber (v1.19.x) handlers.
var (
ParamStoreKeyMaxValueLength = []byte("MaxValueLength")
)
Expand All @@ -25,6 +26,7 @@ func (params Params) String() string {
}

// ParamKeyTable for slashing module
// TODO: remove with the umber (v1.19.x) handlers.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
Expand All @@ -39,6 +41,7 @@ func NewParams(
}

// ParamSetPairs - Implements params.ParamSet
// TODO: remove with the umber (v1.19.x) handlers.
func (params *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMaxValueLength, &params.MaxValueLength, validateMaxValueLength),
Expand Down

0 comments on commit 9c30aa5

Please sign in to comment.