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

[Gateway] chore: add MsgUpdateParam to gateway module #808

Merged
merged 8 commits into from
Sep 30, 2024
1,213 changes: 1,166 additions & 47 deletions api/poktroll/gateway/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/poktroll/gateway/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions proto/poktroll/gateway/tx.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package poktroll.gateway;

option go_package = "github.com/pokt-network/poktroll/x/gateway/types";
Expand All @@ -9,7 +10,6 @@ import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

import "poktroll/gateway/params.proto";

// Msg defines the Msg service.
Expand All @@ -21,11 +21,12 @@ service Msg {
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc StakeGateway (MsgStakeGateway ) returns (MsgStakeGatewayResponse );
rpc UnstakeGateway (MsgUnstakeGateway) returns (MsgUnstakeGatewayResponse);
rpc UpdateParam (MsgUpdateParam ) returns (MsgUpdateParamResponse );
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/gateway/MsgUpdateParams";
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/gateway/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Expand All @@ -45,8 +46,8 @@ message MsgUpdateParamsResponse {}

message MsgStakeGateway {
option (cosmos.msg.v1.signer) = "address"; // see: https://docs.cosmos.network/main/build/building-modules/protobuf-annotations#signer
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the gateway is staking. Must be ≥ to the current amount that the gateway has staked (if any)
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the gateway is staking. Must be ≥ to the current amount that the gateway has staked (if any)
}

message MsgStakeGatewayResponse {}
Expand All @@ -58,3 +59,18 @@ message MsgUnstakeGateway {

message MsgUnstakeGatewayResponse {}

// MsgUpdateParam is the Msg/UpdateParam request type to update a single param.
message MsgUpdateParam {
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"];

string name = 2;
string as_type = 3;
}

message MsgUpdateParamResponse {
Params params = 1;
}

17 changes: 17 additions & 0 deletions x/gateway/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pokt-network/poktroll/x/gateway/types"
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
)

func (k msgServer) UpdateParam(goCtx context.Context, msg *types.MsgUpdateParam) (*types.MsgUpdateParamResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

return &types.MsgUpdateParamResponse{}, nil
}
6 changes: 6 additions & 0 deletions x/gateway/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
// Short: "Send a unstake_gateway tx",
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
// },
// {
// RpcMethod: "UpdateParam",
// Use: "update-param [name] [as-type]",
// Short: "Send a update-param tx",
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "name"}, {ProtoField: "asType"}},
// },
// this line is used by ignite scaffolding # autocli/tx
},
},
Expand Down
23 changes: 23 additions & 0 deletions x/gateway/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgUnstakeGateway int = 100

opWeightMsgUpdateParam = "op_weight_msg_update_param"
// TODO: Determine the simulation weight value
defaultWeightMsgUpdateParam int = 100

// this line is used by starport scaffolding # simapp/module/const
)

Expand Down Expand Up @@ -81,6 +85,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
gatewaysimulation.SimulateMsgUnstakeGateway(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgUpdateParam int
simState.AppParams.GetOrGenerate(opWeightMsgUpdateParam, &weightMsgUpdateParam, nil,
func(_ *rand.Rand) {
weightMsgUpdateParam = defaultWeightMsgUpdateParam
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUpdateParam,
gatewaysimulation.SimulateMsgUpdateParam(am.accountKeeper, am.bankKeeper, am.keeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
Expand All @@ -105,6 +120,14 @@ func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Wei
return nil
},
),
simulation.NewWeightedProposalMsg(
opWeightMsgUpdateParam,
defaultWeightMsgUpdateParam,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
gatewaysimulation.SimulateMsgUpdateParam(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}
29 changes: 29 additions & 0 deletions x/gateway/simulation/update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package simulation

import (
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/pokt-network/poktroll/x/gateway/keeper"
"github.com/pokt-network/poktroll/x/gateway/types"
)

func SimulateMsgUpdateParam(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgUpdateParam{
Authority: simAccount.Address.String(),
}

// TODO: Handling the UpdateParam simulation

return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "UpdateParam simulation not implemented"), nil, nil
}
}
3 changes: 3 additions & 0 deletions x/gateway/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUnstakeGateway{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParam{},
)
// this line is used by starport scaffolding # 3

registry.RegisterImplementations((*sdk.Msg)(nil),
Expand Down
25 changes: 25 additions & 0 deletions x/gateway/types/message_update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

import (
errorsmod "cosmossdk.io/errors"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var _ cosmostypes.Msg = (*MsgUpdateParam)(nil)

func NewMsgUpdateParam(authority string, name string, asType string) *MsgUpdateParam {
return &MsgUpdateParam{
Authority: authority,
Name: name,
AsType: asType,
}
}

func (msg *MsgUpdateParam) ValidateBasic() error {
_, err := cosmostypes.AccAddressFromBech32(msg.Authority)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err)
}
return nil
}
40 changes: 40 additions & 0 deletions x/gateway/types/message_update_param_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package types

import (
"testing"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/pokt-network/poktroll/testutil/sample"
"github.com/stretchr/testify/require"
)

func TestMsgUpdateParam_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgUpdateParam
err error
}{
{
name: "invalid address",
msg: MsgUpdateParam{
Authority: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgUpdateParam{
Authority: sample.AccAddress(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
})
}
}
Loading
Loading