Skip to content

Commit

Permalink
remove param space from msgfees module, move param functions in param…
Browse files Browse the repository at this point in the history
…s.go
  • Loading branch information
nullpointer0x00 committed Apr 16, 2024
1 parent 3d1eae1 commit 7227c71
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 61 deletions.
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ func New(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, govAuthority)

app.MsgFeesKeeper = msgfeeskeeper.NewKeeper(
appCodec, keys[msgfeestypes.StoreKey], app.GetSubspace(msgfeestypes.ModuleName),
authtypes.FeeCollectorName, pioconfig.GetProvenanceConfig().FeeDenom,
app.SimulateProv, app.txConfig.TxDecoder(), interfaceRegistry,
appCodec, keys[msgfeestypes.StoreKey], authtypes.FeeCollectorName,
pioconfig.GetProvenanceConfig().FeeDenom, app.SimulateProv,
app.txConfig.TxDecoder(), interfaceRegistry,
)

pioMsgFeesRouter := app.MsgServiceRouter().(*piohandlers.PioMsgServiceRouter)
Expand Down Expand Up @@ -1361,8 +1361,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)

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

Expand Down
43 changes: 0 additions & 43 deletions x/msgfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
cosmosauthtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/provenance-io/provenance/x/msgfees/types"
)
Expand All @@ -28,7 +27,6 @@ type baseAppSimulateFunc func(txBytes []byte) (sdk.GasInfo, *sdk.Result, sdk.Con
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
feeCollectorName string // name of the FeeCollector ModuleAccount
defaultFeeDenom string
simulateFunc baseAppSimulateFunc
Expand All @@ -42,21 +40,15 @@ type Keeper struct {
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
paramSpace paramtypes.Subspace,
feeCollectorName string,
defaultFeeDenom string,
simulateFunc baseAppSimulateFunc,
txDecoder sdk.TxDecoder,
registry cdctypes.InterfaceRegistry,
) Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
feeCollectorName: feeCollectorName,
defaultFeeDenom: defaultFeeDenom,
simulateFunc: simulateFunc,
Expand All @@ -80,41 +72,6 @@ func (k Keeper) GetFeeCollectorName() string {
return k.feeCollectorName
}

// GetFloorGasPrice returns the current minimum gas price in sdk.Coin used in calculations for charging additional fees
func (k Keeper) GetFloorGasPrice(ctx sdk.Context) sdk.Coin {
min := types.DefaultFloorGasPrice()
if k.paramSpace.Has(ctx, types.ParamStoreKeyFloorGasPrice) {
k.paramSpace.Get(ctx, types.ParamStoreKeyFloorGasPrice, &min)
}
return min
}

// GetNhashPerUsdMil returns the current nhash amount per usd mil.
//
// Conversions:
// - x nhash/usd-mil = 1,000,000/x usd/hash
// - y usd/hash = 1,000,000/y nhash/usd-mil
//
// Examples:
// - 40,000,000 nhash/usd-mil = 1,000,000/40,000,000 usd/hash = $0.025/hash,
// - $0.040/hash = 1,000,000/0.040 nhash/usd-mil = 25,000,000 nhash/usd-mil
func (k Keeper) GetNhashPerUsdMil(ctx sdk.Context) uint64 {
rateInMils := types.DefaultParams().NhashPerUsdMil
if k.paramSpace.Has(ctx, types.ParamStoreKeyNhashPerUsdMil) {
k.paramSpace.Get(ctx, types.ParamStoreKeyNhashPerUsdMil, &rateInMils)
}
return rateInMils
}

// GetConversionFeeDenom returns the conversion fee denom
func (k Keeper) GetConversionFeeDenom(ctx sdk.Context) string {
conversionFeeDenom := types.DefaultParams().ConversionFeeDenom
if k.paramSpace.Has(ctx, types.ParamStoreKeyConversionFeeDenom) {
k.paramSpace.Get(ctx, types.ParamStoreKeyConversionFeeDenom, &conversionFeeDenom)
}
return conversionFeeDenom
}

// SetMsgFee sets the additional fee schedule for a Msg
func (k Keeper) SetMsgFee(ctx sdk.Context, msgFees types.MsgFee) error {
store := ctx.KVStore(k.storeKey)
Expand Down
43 changes: 37 additions & 6 deletions x/msgfees/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,45 @@ import (

// GetParams returns the total set of distribution parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.Params{
FloorGasPrice: k.GetFloorGasPrice(ctx),
NhashPerUsdMil: k.GetNhashPerUsdMil(ctx),
ConversionFeeDenom: k.GetConversionFeeDenom(ctx),
store := ctx.KVStore(k.storeKey)
params = types.DefaultParams() // Initialize with defaults

bz := store.Get(types.ParamStoreKey)
if bz != nil {
k.cdc.MustUnmarshal(bz, &params) // Deserialize parameters
}
return params
}

// SetParams sets the account parameters to the param space.
// SetParams sets the account parameters to the store.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&params) // Serialize parameters
store.Set(types.ParamStoreKey, bz)
}

// GetFloorGasPrice returns the current minimum gas price in sdk.Coin used in calculations for charging additional fees
func (k Keeper) GetFloorGasPrice(ctx sdk.Context) sdk.Coin {
params := k.GetParams(ctx)
return params.FloorGasPrice
}

// GetNhashPerUsdMil returns the current nhash amount per usd mil.
//
// Conversions:
// - x nhash/usd-mil = 1,000,000/x usd/hash
// - y usd/hash = 1,000,000/y nhash/usd-mil
//
// Examples:
// - 40,000,000 nhash/usd-mil = 1,000,000/40,000,000 usd/hash = $0.025/hash,
// - $0.040/hash = 1,000,000/0.040 nhash/usd-mil = 25,000,000 nhash/usd-mil
func (k Keeper) GetNhashPerUsdMil(ctx sdk.Context) uint64 {
params := k.GetParams(ctx)
return params.NhashPerUsdMil
}

// GetConversionFeeDenom returns the conversion fee denom
func (k Keeper) GetConversionFeeDenom(ctx sdk.Context) string {
params := k.GetParams(ctx)
return params.ConversionFeeDenom
}
2 changes: 1 addition & 1 deletion x/msgfees/keeper/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IntegrationTestSuite struct {
func (s *IntegrationTestSuite) SetupSuite() {
s.app = provenance.Setup(s.T())
s.ctx = s.app.BaseApp.NewContext(false)
s.k = msgfeeskeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(msgfeestypes.ModuleName), s.app.GetSubspace(msgfeestypes.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, s.app.InterfaceRegistry())
s.k = msgfeeskeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(msgfeestypes.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, s.app.InterfaceRegistry())
s.accountAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
}

Expand Down
5 changes: 1 addition & 4 deletions x/msgfees/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ var _ types.QueryServer = Keeper{}

func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
var params types.Params
k.paramSpace.GetParamSet(c, &params)

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

func (k Keeper) QueryAllMsgFees(c context.Context, req *types.QueryAllMsgFeesRequest) (*types.QueryAllMsgFeesResponse, error) {
Expand Down
3 changes: 1 addition & 2 deletions x/msgfees/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func TestProposalContents(t *testing.T) {
accounts := simtypes.RandomAccounts(r, 3)

// execute ProposalContents function
weightedProposalContent := simulation.ProposalContents(keeper.NewKeeper(app.AppCodec(), app.GetKey(types.ModuleName),
app.GetSubspace(types.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, app.InterfaceRegistry()))
weightedProposalContent := simulation.ProposalContents(keeper.NewKeeper(app.AppCodec(), app.GetKey(types.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, app.InterfaceRegistry()))
require.Len(t, weightedProposalContent, 2)

w0 := weightedProposalContent[0]
Expand Down
2 changes: 2 additions & 0 deletions x/msgfees/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func GetMsgFeeKey(msgType string) []byte {

var (
MsgFeeKeyPrefix = []byte{0x00}

ParamStoreKey = []byte{0x01}
)

func GetCompositeKey(msgType string, recipient string) string {
Expand Down

0 comments on commit 7227c71

Please sign in to comment.