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: migrate challenge module to cosmos sdk v0.47 #199

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,13 @@ func New(
app.ChallengeKeeper = *challengemodulekeeper.NewKeeper(
appCodec,
keys[challengemoduletypes.StoreKey],
memKeys[challengemoduletypes.MemStoreKey],
tKeys[challengemoduletypes.TStoreKey],
app.GetSubspace(challengemoduletypes.ModuleName),
app.BankKeeper,
app.StorageKeeper,
app.SpKeeper,
app.StakingKeeper,
app.PaymentKeeper,
authtypes.NewModuleAddress(challengemoduletypes.ModuleName).String(),
)
challengeModule := challengemodule.NewAppModule(appCodec, app.ChallengeKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down
21 changes: 21 additions & 0 deletions proto/greenfield/challenge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package greenfield.challenge;
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "greenfield/challenge/params.proto";
import "greenfield/challenge/types.proto";

// this line is used by starport scaffolding # proto/tx/import
Expand All @@ -14,6 +15,12 @@ option go_package = "github.com/bnb-chain/greenfield/x/challenge/types";
service Msg {
rpc Submit(MsgSubmit) returns (MsgSubmitResponse);
rpc Attest(MsgAttest) returns (MsgAttestResponse);

// UpdateParams defines a governance operation for updating the x/challenge module parameters.
// The authority is defined in the keeper.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

Expand Down Expand Up @@ -79,4 +86,18 @@ message MsgAttest {
// MsgAttest defines the response of MsgAttestResponse.
message MsgAttestResponse {}

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

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/challenge 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.
message MsgUpdateParamsResponse {}
// this line is used by starport scaffolding # proto/tx/message
196 changes: 0 additions & 196 deletions testutil/keeper/challenge.go

This file was deleted.

12 changes: 7 additions & 5 deletions x/challenge/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ func BeginBlocker(ctx sdk.Context, keeper k.Keeper) {
keeper.RemoveChallengeUntil(ctx, blockHeight)

// delete too old slashes at this height
coolingOff := keeper.SlashCoolingOffPeriod(ctx)
if blockHeight <= coolingOff {
coolingOffPeriod := keeper.GetParams(ctx).SlashCoolingOffPeriod
if blockHeight <= coolingOffPeriod {
return
}

height := blockHeight - coolingOff
height := blockHeight - coolingOffPeriod
keeper.RemoveSlashUntil(ctx, height)
}

func EndBlocker(ctx sdk.Context, keeper k.Keeper) {
count := keeper.GetChallengeCountCurrentBlock(ctx)
needed := keeper.ChallengeCountPerBlock(ctx)

params := keeper.GetParams(ctx)
needed := params.ChallengeCountPerBlock
if count >= needed {
return
}
Expand All @@ -40,7 +42,7 @@ func EndBlocker(ctx sdk.Context, keeper k.Keeper) {
}

segmentSize := keeper.StorageKeeper.MaxSegmentSize(ctx)
expiredHeight := keeper.ChallengeKeepAlivePeriod(ctx) + uint64(ctx.BlockHeight())
expiredHeight := params.ChallengeKeepAlivePeriod + uint64(ctx.BlockHeight())

events := make([]proto.Message, 0) // for events
objectMap := make(map[string]struct{}) // for de-duplication
Expand Down
24 changes: 24 additions & 0 deletions x/challenge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
return cmd
}

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(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdLatestAttestedChallenges() *cobra.Command {
cmd := &cobra.Command{
Use: "latest-attested-challenges",
Expand Down
35 changes: 0 additions & 35 deletions x/challenge/client/cli/query_params.go

This file was deleted.

5 changes: 4 additions & 1 deletion x/challenge/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
err := k.SetParams(ctx, genState.Params)
if err != nil {
panic(err)
}
}

// ExportGenesis returns the module's exported genesis
Expand Down
Loading