Skip to content
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

feat: add payment module params #893

Merged
merged 47 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9b70f9a
feat: define protobuf file for params
rahulghangas Oct 20, 2022
89afc7a
feat: define protobuf file for querying params
rahulghangas Oct 20, 2022
fe4d7b0
feat: define protobuf file for genesis value for params
rahulghangas Oct 20, 2022
82edaad
feat: type defs for params and relevant protobuf generated files
rahulghangas Oct 20, 2022
6858ad2
feat: add cli command to query params
rahulghangas Oct 20, 2022
34eba8c
feat: getter and setter methods to get/set params from keeper
rahulghangas Oct 20, 2022
2a2b702
feat: define param stores in keeper
rahulghangas Oct 20, 2022
47d6859
chore: pass releavnt stores when initializing payment keeper
rahulghangas Oct 20, 2022
32bc44c
feat: implement callback to query params
rahulghangas Oct 20, 2022
9dda2ea
chore: typo
rahulghangas Oct 20, 2022
aa34b4d
chore: grammar
rahulghangas Oct 20, 2022
55b8908
chore: line ending
rahulghangas Oct 20, 2022
b65e1f3
fix: assign storeKey and memKey
rahulghangas Oct 20, 2022
bfda77e
fix: follow standard while naming proto var
rahulghangas Oct 20, 2022
1e4175b
chore: documentation comment
rahulghangas Oct 20, 2022
a5e258e
chore: run gofumpt
rahulghangas Oct 20, 2022
f2500ea
fix: generate pb files using correct version
rahulghangas Oct 20, 2022
243f1f4
chore: make params uint32 instead of int32 and set default values
rahulghangas Oct 20, 2022
986848c
chore: typo
rahulghangas Oct 20, 2022
6fa6d87
chore: better comment
rahulghangas Oct 20, 2022
feac963
fix: min/max square size validation
rahulghangas Oct 20, 2022
726d58c
chore: define genesis state params
rahulghangas Oct 20, 2022
3aef9c7
chore: set key table for subspace if not already set
rahulghangas Oct 20, 2022
31af6a5
test: define dummy payment keeper for testing
rahulghangas Oct 25, 2022
b61e873
test: define nullify module to set data to nil
rahulghangas Oct 25, 2022
7e670ab
test: params query test
rahulghangas Oct 25, 2022
0cf6e09
test: genesis test
rahulghangas Oct 25, 2022
129d26f
test: add params keeper test
rahulghangas Oct 25, 2022
79a1a72
chore: cleanup
rahulghangas Oct 31, 2022
b769d07
test: removing fill assertions and unsafe code
rahulghangas Nov 3, 2022
7d38d90
chore: assert that min/max sqaure size is not 0
rahulghangas Nov 3, 2022
0cb7a09
test: add equality check for genesis params
rahulghangas Nov 3, 2022
885bc1e
chore update dependency
rahulghangas Nov 3, 2022
5a43a68
test: fix test by defining min/max square size
rahulghangas Nov 3, 2022
d3957ce
Merge branch 'main' into feat/payment-module-params
rahulghangas Nov 10, 2022
ea2a421
fix: proto file package
rahulghangas Nov 10, 2022
f8787a4
fix: proto file go_package
rahulghangas Nov 10, 2022
1fb9d96
chore: generate files fromn protobuf
rahulghangas Nov 10, 2022
743d610
fix: query params url
rahulghangas Nov 10, 2022
713ca62
chore: generate files fromn protobuf
rahulghangas Nov 10, 2022
807bc7d
chore: grammar
rahulghangas Nov 10, 2022
1bb4b1e
chore: grammar
rahulghangas Nov 10, 2022
cab4172
chore: rename payment to blob
rahulghangas Nov 10, 2022
d8617cd
chore: rename payment to blob
rahulghangas Nov 10, 2022
7b93b93
chore: add order validation for min/max square size
rahulghangas Nov 10, 2022
837bdaa
chore: min and max square size can be same
rahulghangas Nov 10, 2022
17669da
fix: typo
rahulghangas Nov 10, 2022
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
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func New(

app.BlobKeeper = *blobmodulekeeper.NewKeeper(
appCodec,
keys[blobmoduletypes.StoreKey],
keys[blobmoduletypes.MemStoreKey],
app.GetSubspace(blobmoduletypes.ModuleName),
)
blobmod := blobmodule.NewAppModule(appCodec, app.BlobKeeper)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/regen-network/cosmos-proto v0.3.1
github.com/tendermint/tendermint v0.34.20
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down Expand Up @@ -173,7 +174,6 @@ require (
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
7 changes: 6 additions & 1 deletion proto/blob/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
syntax = "proto3";
package blob;

import "gogoproto/gogo.proto";
import "blob/params.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/blob/types";

// GenesisState defines the capability module's genesis state.
message GenesisState {}
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
}
14 changes: 14 additions & 0 deletions proto/blob/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package blob;

import "gogoproto/gogo.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/blob/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;

uint32 min_square_size = 1 [(gogoproto.moretags) = "yaml:\"min_square_size\""];
uint32 max_square_size = 2 [(gogoproto.moretags) = "yaml:\"max_square_size\""];
}
19 changes: 17 additions & 2 deletions proto/blob/query.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
syntax = "proto3";
package blob;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "blob/params.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/blob/types";

// Query defines the gRPC querier service.
service Query {}
// Query defines the gRPC query service.
service Query {
// Params queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/blob/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}
53 changes: 53 additions & 0 deletions testutil/keeper/payment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package keeper
rahulghangas marked this conversation as resolved.
Show resolved Hide resolved

import (
"testing"

"github.com/celestiaorg/celestia-app/testutil"
"github.com/celestiaorg/celestia-app/x/blob/keeper"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)

func BlobKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
testutil.MakeTestCodec(),
storeKey,
memStoreKey,
"Blob",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
)

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

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

return k, ctx
}
2 changes: 2 additions & 0 deletions x/blob/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())

return cmd
}
34 changes: 34 additions & 0 deletions x/blob/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cli

import (
"context"

"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
3 changes: 2 additions & 1 deletion x/blob/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()

genesis.Params = k.GetParams(ctx)
return genesis
}
22 changes: 22 additions & 0 deletions x/blob/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package blob_test

import (
"testing"

keepertest "github.com/celestiaorg/celestia-app/testutil/keeper"
"github.com/celestiaorg/celestia-app/x/blob"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/stretchr/testify/require"
)

func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
}

k, ctx := keepertest.BlobKeeper(t)
blob.InitGenesis(ctx, *k, genesisState)
got := blob.ExportGenesis(ctx, *k)
require.NotNil(t, got)
require.Equal(t, types.DefaultParams(), got.Params)
}
7 changes: 7 additions & 0 deletions x/blob/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package keeper

import (
"github.com/celestiaorg/celestia-app/x/blob/types"
)

var _ types.QueryServer = Keeper{}
19 changes: 19 additions & 0 deletions x/blob/keeper/grpc_query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package keeper

import (
"context"

"github.com/celestiaorg/celestia-app/x/blob/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
}
21 changes: 21 additions & 0 deletions x/blob/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper_test

import (
"testing"

testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper"
"github.com/celestiaorg/celestia-app/x/blob/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.BlobKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)

response, err := keeper.Params(wctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsResponse{Params: params}, response)
}
23 changes: 20 additions & 3 deletions x/blob/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

const (
Expand All @@ -24,12 +26,27 @@ const (

// Keeper handles all the state changes for the blob module.
type Keeper struct {
cdc codec.BinaryCodec
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramStore paramtypes.Subspace
}

func NewKeeper(cdc codec.BinaryCodec) *Keeper {
func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
) *Keeper {
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}

return &Keeper{
cdc: cdc,
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramStore: ps,
}
}

Expand Down
31 changes: 31 additions & 0 deletions x/blob/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package keeper

import (
"github.com/celestiaorg/celestia-app/x/blob/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// GetParams gets all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(
k.MinSquareSize(ctx),
k.MaxSquareSize(ctx),
)
}

// SetParams sets the params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramStore.SetParamSet(ctx, &params)
}

// MinSquareSize returns the MinSquareSize param
func (k Keeper) MinSquareSize(ctx sdk.Context) (res uint32) {
k.paramStore.Get(ctx, types.KeyMinSquareSize, &res)
return
}

// MaxSquareSize returns the MaxSquareSize param
func (k Keeper) MaxSquareSize(ctx sdk.Context) (res uint32) {
k.paramStore.Get(ctx, types.KeyMaxSquareSize, &res)
return
}
20 changes: 20 additions & 0 deletions x/blob/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package keeper_test

import (
"testing"

testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/stretchr/testify/require"
)

func TestGetParams(t *testing.T) {
k, ctx := testkeeper.BlobKeeper(t)
params := types.DefaultParams()

k.SetParams(ctx, params)

require.EqualValues(t, params, k.GetParams(ctx))
require.EqualValues(t, params.MinSquareSize, k.MinSquareSize(ctx))
require.EqualValues(t, params.MaxSquareSize, k.MaxSquareSize(ctx))
}
6 changes: 4 additions & 2 deletions x/blob/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const DefaultIndex uint64 = 1

// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{}
return &GenesisState{
Params: DefaultParams(),
}
}

// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
return nil
return gs.Params.Validate()
}
Loading