Skip to content

Commit

Permalink
fix: x/params is deprecated, let each module manage its params
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Dec 22, 2023
1 parent 0fa7185 commit 25b076f
Show file tree
Hide file tree
Showing 52 changed files with 2,581 additions and 427 deletions.
10 changes: 4 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (
"github.com/Nolus-Protocol/nolus-core/wasmbinding"
mintkeeper "github.com/Nolus-Protocol/nolus-core/x/mint/keeper"
minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types"
"github.com/Nolus-Protocol/nolus-core/x/tax"
taxmodulekeeper "github.com/Nolus-Protocol/nolus-core/x/tax/keeper"
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
"github.com/Nolus-Protocol/nolus-core/x/vestings"
Expand Down Expand Up @@ -181,7 +180,6 @@ type AppKeepers struct {
InterchainQueriesModule interchainqueries.AppModule
TransferModule transferSudo.AppModule
FeeRefunderModule feerefunder.AppModule
TaxModule tax.AppModule
VestingsModule vestings.AppModule
<<<<<<< HEAD
IcaModule ica.AppModule
Expand Down Expand Up @@ -280,10 +278,10 @@ func (appKeepers *AppKeepers) NewAppKeepers(
mintKeeper := mintkeeper.NewKeeper(
appCodec,
appKeepers.keys[minttypes.StoreKey],
appKeepers.GetSubspace(minttypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.MintKeeper = &mintKeeper

Expand Down Expand Up @@ -482,13 +480,13 @@ func (appKeepers *AppKeepers) NewAppKeepers(
// Set legacy router for backwards compatibility with gov v1beta1
appKeepers.GovKeeper.SetLegacyRouter(govRouter)

appKeepers.TaxKeeper = taxmodulekeeper.NewKeeper(
taxKeeper := taxmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[taxmoduletypes.StoreKey],
appKeepers.keys[taxmoduletypes.MemStoreKey],
appKeepers.GetSubspace(taxmoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.TaxModule = tax.NewAppModule(appCodec, *appKeepers.TaxKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper)
appKeepers.TaxKeeper = &taxKeeper

appKeepers.VestingsKeeper = vestingskeeper.NewKeeper(
appCodec,
Expand Down
8 changes: 4 additions & 4 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func appModules(
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distribution.NewAppModule(appCodec, *app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
Expand All @@ -153,9 +153,9 @@ func appModules(
evidence.NewAppModule(*app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
sdkparams.NewAppModule(*app.ParamsKeeper),
tax.NewAppModule(appCodec, *app.TaxKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(taxmoduletypes.ModuleName)),
app.AppKeepers.TransferModule,
app.AppKeepers.VestingsModule,
app.AppKeepers.TaxModule,
app.AppKeepers.IcaModule,
app.AppKeepers.InterchainQueriesModule,
app.AppKeepers.InterchainTxsModule,
Expand All @@ -180,8 +180,8 @@ func simulationModules(
bank.NewAppModule(appCodec, *app.BankKeeper, *app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper),
tax.NewAppModule(appCodec, *app.TaxKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, app.GetSubspace(minttypes.ModuleName)),
tax.NewAppModule(appCodec, *app.TaxKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(taxmoduletypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
distribution.NewAppModule(appCodec, *app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
slashing.NewAppModule(appCodec, *app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
Expand Down
5 changes: 2 additions & 3 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var (
)

func init() {
SetAddressPrefixes()
RegisterDenoms()
}

Expand All @@ -46,10 +45,10 @@ func RegisterDenoms() {
}
}

func SetAddressPrefixes() {
func SetAddressPrefixes() *sdk.Config {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.Seal()
return config
}
13 changes: 8 additions & 5 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ func CreateTestApp(isCheckTx bool, tempDir string) (*App, sdk.Context) {
sims.EmptyAppOptions{},
)

// cosmoscmd.SetPrefixes(nolusapp.AccountAddressPrefix)
// sdk.GetConfig().SetBech32PrefixForAccount(nolusapp.AccountAddressPrefix, nolusapp.AccountAddressPrefixPub)
params.SetAddressPrefixes()

testapp := app
ctx := testapp.BaseApp.NewContext(isCheckTx, tmproto.Header{})
testapp.TaxKeeper.SetParams(ctx, taxtypes.DefaultParams())
testapp.MintKeeper.SetParams(ctx, minttypes.DefaultParams())
// refactor: (fix linter) do not ignore SetParams error
_ = testapp.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())
_ = testapp.BankKeeper.SetParams(ctx, banktypes.DefaultParams())

err := testapp.AccountKeeper.SetParams(ctx, authtypes.DefaultParams())
if err != nil {
panic(err)
}
err = testapp.BankKeeper.SetParams(ctx, banktypes.DefaultParams())
if err != nil {
panic(err)
}
return testapp, ctx
}
3 changes: 3 additions & 0 deletions cmd/nolusd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/Nolus-Protocol/nolus-core/app"
"github.com/Nolus-Protocol/nolus-core/app/params"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
)

func main() {
config := params.SetAddressPrefixes()
config.Seal()
// we must override the wasm variables here because we want to upload contracts on genesis
// and in our scripts, we use the cli command add-wasm-genesis-message before the chain is started in order to load the contracts
overrideWasmVariables()
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.0.1
github.com/gogo/protobuf v1.3.3
github.com/cosmos/cosmos-proto v1.0.0-beta.2
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529
)

Expand Down Expand Up @@ -59,7 +59,6 @@ require (
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/admin-module v0.0.0-20220204080909-475a98e03f31 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/gaia/v11 v11.0.0-00010101000000-000000000000 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand Down Expand Up @@ -87,6 +86,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down Expand Up @@ -211,7 +211,4 @@ replace (

// https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#replaces
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

// https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc2/UPGRADING.md#go-api-changes
// google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
39 changes: 39 additions & 0 deletions proto/nolus/mint/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
syntax = "proto3";
package nolus.mint.v1beta1;

option go_package = "github.com/Nolus-Protocol/nolus-core/x/mint/types";

import "cosmos/msg/v1/msg.proto";
import "nolus/mint/v1beta1/mint.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

// Msg defines the x/mint Msg service.
service Msg {
// UpdateParams defines a governance operation for updating the x/mint module
// parameters. The authority is hard-coded to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/mint parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
40 changes: 40 additions & 0 deletions proto/nolus/tax/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package nolus.tax.v1beta1;

option go_package = "github.com/Nolus-Protocol/nolus-core/x/tax/types";

import "cosmos/msg/v1/msg.proto";
import "nolus/tax/v1beta1/params.proto";

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

// Msg defines the x/tax Msg service.
service Msg {
// UpdateParams defines a governance operation for updating the x/tax module
// parameters. The authority is hard-coded to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/tax parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
13 changes: 4 additions & 9 deletions testutil/keeper/tax.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
sdktypes "github.com/cosmos/cosmos-sdk/store/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"
)

Expand All @@ -31,23 +32,17 @@ func TaxKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"TaxParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
return &k, ctx
}
4 changes: 3 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func New(t *testing.T, configs ...network.Config) *network.Network {
// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig.
func DefaultConfig() network.Config {
encoding := app.MakeEncodingConfig(app.ModuleBasics)
chainID := "chain-" + tmrand.NewRand().Str(6)
return network.Config{
Codec: encoding.Marshaler,
TxConfig: encoding.TxConfig,
Expand All @@ -63,11 +64,12 @@ func DefaultConfig() network.Config {
sims.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
baseapp.SetChainID(chainID),
)
},
GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler),
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.NewRand().Str(6),
ChainID: chainID,
NumValidators: 1,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
Expand Down
Loading

0 comments on commit 25b076f

Please sign in to comment.