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

[Application] chore: add MsgUpdateParam to application module #844

Open
wants to merge 9 commits into
base: issues/612/gateway/logic
Choose a base branch
from
1,575 changes: 1,378 additions & 197 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

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

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

30 changes: 24 additions & 6 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ service Msg {

// UpdateParams defines a (governance) operation for updating the module
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams (MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc StakeApplication (MsgStakeApplication) returns (MsgStakeApplicationResponse);
rpc UnstakeApplication (MsgUnstakeApplication) returns (MsgUnstakeApplicationResponse);
rpc DelegateToGateway (MsgDelegateToGateway) returns (MsgDelegateToGatewayResponse);
rpc UndelegateFromGateway (MsgUndelegateFromGateway) returns (MsgUndelegateFromGatewayResponse);
rpc TransferApplication (MsgTransferApplication) returns (MsgTransferApplicationResponse);
rpc UpdateParams (MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc StakeApplication (MsgStakeApplication) returns (MsgStakeApplicationResponse);
rpc UnstakeApplication (MsgUnstakeApplication) returns (MsgUnstakeApplicationResponse);
rpc DelegateToGateway (MsgDelegateToGateway) returns (MsgDelegateToGatewayResponse);
rpc UndelegateFromGateway (MsgUndelegateFromGateway) returns (MsgUndelegateFromGatewayResponse);
rpc TransferApplication (MsgTransferApplication) returns (MsgTransferApplicationResponse);
rpc UpdateParam (MsgUpdateParam) returns (MsgUpdateParamResponse);
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
Expand Down Expand Up @@ -53,6 +54,7 @@ message MsgStakeApplication {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application.
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked. Must be ≥ to the current amount that the application has staked (if any)
repeated poktroll.shared.ApplicationServiceConfig services = 3; // The list of services this application is staked to request service for

// TODO_POST_MAINNET_CONSIDERATION: Consdier allowing appplications to delegate
// to gateways at time of staking for a better developer experience.
// repeated string gateway_addresss
Expand Down Expand Up @@ -93,3 +95,19 @@ message MsgTransferApplicationResponse {
poktroll.application.Application application = 1;
}

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;
oneof asType {
cosmos.base.v1beta1.Coin as_coin = 3;
};
}

message MsgUpdateParamResponse {
string params = 1;
}

9 changes: 9 additions & 0 deletions tools/scripts/authz/dao_genesis_authorizations.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@
},
"expiration": "2500-01-01T00:00:00Z"
},
{
"granter": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"grantee": "pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw",
"authorization": {
"@type": "\/cosmos.authz.v1beta1.GenericAuthorization",
"msg": "\/poktroll.application.MsgUpdateParam"
},
"expiration": "2500-01-01T00:00:00Z"
},
{
"granter": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"grantee": "pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw",
Expand Down
18 changes: 18 additions & 0 deletions x/application/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pokt-network/poktroll/x/application/types"
)

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/application/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Short: "Transfer the application from [source app address] to [destination app address] and remove the source application",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "source_address"}, {ProtoField: "destination_address"}},
},
//{
// 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/application/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgTransferApplication 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 @@ -126,6 +130,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
applicationsimulation.SimulateMsgTransferApplication(am.accountKeeper, am.bankKeeper, am.applicationKeeper),
))

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

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

return operations
Expand Down Expand Up @@ -174,6 +189,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 {
applicationsimulation.SimulateMsgUpdateParam(am.accountKeeper, am.bankKeeper, am.applicationKeeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}
30 changes: 30 additions & 0 deletions x/application/simulation/update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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/application/keeper"
"github.com/pokt-network/poktroll/x/application/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/application/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgTransferApplication{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParam{},
)
// this line is used by starport scaffolding # 3

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

import (
"fmt"

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

var _ cosmostypes.Msg = &MsgUpdateParam{}

func NewMsgUpdateParam(authority string, name string, asType any) *MsgUpdateParam {
var asTypeIface isMsgUpdateParam_AsType

switch t := asType.(type) {
case *cosmostypes.Coin:
asTypeIface = &MsgUpdateParam_AsCoin{AsCoin: t}
default:
panic(fmt.Sprintf("unexpected param value type: %T", asType))
}

return &MsgUpdateParam{
Authority: authority,
Name: name,
AsType: asTypeIface,
}
}

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
}
41 changes: 41 additions & 0 deletions x/application/types/message_update_param_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types

import (
"testing"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/sample"
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
)

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