Skip to content

Commit

Permalink
[Application] chore: add MsgUpdateParam to application module (#844)
Browse files Browse the repository at this point in the history
## Summary

```bash
ignite scaffold message update-param --module gateway --signer authority name as_type --response params
```

Adds the `MsgUpdateParam` message so that the application module may
update individual parameters. The application module's min_stake param
will be added in a subsequent PR.

## Dependencies

- #809
- #843 

## Dependents

- #845 
- #847 
- #848 
- #849
- #850
- #857

## Issue

Add individual param updates support to the application module

- #612

## Type of change

Select one or more from the following:

- [x] New feature, functionality or library
- [x] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [ ] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [ ] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [ ] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: Redouane Lakrache <[email protected]>
Co-authored-by: Daniel Olshansky <[email protected]>
Co-authored-by: red-0ne <[email protected]>
  • Loading branch information
4 people authored Oct 4, 2024
1 parent a752b66 commit 8076e80
Show file tree
Hide file tree
Showing 13 changed files with 2,087 additions and 141 deletions.
1,350 changes: 1,266 additions & 84 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.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ require (
golang.org/x/sync v0.7.0
golang.org/x/text v0.16.0
golang.org/x/tools v0.23.0
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/grpc v1.65.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0
google.golang.org/protobuf v1.34.2
Expand Down
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 @@ -97,3 +99,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)(nil)

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"
)

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

0 comments on commit 8076e80

Please sign in to comment.