Skip to content

Commit

Permalink
[Supplier] Add MsgUpdateParam to application module (#849)
Browse files Browse the repository at this point in the history
## Summary

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

Adds the `MsgUpdateParam` message so that the supplier module may update
individual parameters following section 0 from the updated docs (see
#839).

## Dependencies

- #809
- #843 
- #844 
- #845
- #847
- #848

## Dependents
  
- #850
- #857
- #852 
- #861 
- #851 
- #863 

## Issue

- #612

## Type of change

Select one or more from the following:

- [x] New feature, functionality or library
- [ ] 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
- [x] **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
- [x] 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
- [x] 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 14, 2024
1 parent b60dac9 commit b975a2a
Show file tree
Hide file tree
Showing 15 changed files with 2,128 additions and 106 deletions.
1,300 changes: 1,250 additions & 50 deletions api/poktroll/supplier/tx.pulsar.go

Large diffs are not rendered by default.

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

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

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

package poktroll.supplier;

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

import "poktroll/supplier/params.proto";
import "poktroll/shared/service.proto";


// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// 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 StakeSupplier (MsgStakeSupplier ) returns (MsgStakeSupplierResponse );
rpc UnstakeSupplier (MsgUnstakeSupplier) returns (MsgUnstakeSupplierResponse);
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/supplier/MsgUpdateParams";

option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/supplier/MsgUpdateParams";
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// TODO_IMPROVE(#322): The requirement to provide all params is adopted from the
// latest Cosmos SDK version. We should look into either improving this ourselves
// or seeing if it is on their roadmap.

// params defines the x/supplier parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Expand All @@ -47,22 +43,37 @@ message MsgUpdateParamsResponse {}

message MsgStakeSupplier {
option (cosmos.msg.v1.signer) = "signer"; // https://docs.cosmos.network/main/build/building-modules/messages-and-queries

string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator)
string owner_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the owner (i.e. custodial, staker)
string operator_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial)
cosmos.base.v1beta1.Coin stake = 4; // The total amount of uPOKT the supplier has staked. Must be ≥ to the current amount that the supplier has staked (if any)
repeated poktroll.shared.SupplierServiceConfig services = 5; // The list of services this supplier is staked to provide service for
string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator)
string owner_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the owner (i.e. custodial, staker)
string operator_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial)
cosmos.base.v1beta1.Coin stake = 4; // The total amount of uPOKT the supplier has staked. Must be ≥ to the current amount that the supplier has staked (if any)
repeated poktroll.shared.SupplierServiceConfig services = 5; // The list of services this supplier is staked to provide service for
}

message MsgStakeSupplierResponse {}

message MsgUnstakeSupplier {
option (cosmos.msg.v1.signer) = "signer";

string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator)
string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator)
string operator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial)
}

message MsgUnstakeSupplierResponse {}

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

message MsgUpdateParamResponse {
Params params = 1;
}

5 changes: 5 additions & 0 deletions tests/integration/application/min_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func TestApplicationMinStakeTestSuite(t *testing.T) {
func (s *applicationMinStakeTestSuite) SetupTest() {
s.keepers, s.ctx = keeper.NewTokenomicsModuleKeepers(s.T(), cosmoslog.NewNopLogger())

proofParams := prooftypes.DefaultParams()
proofParams.ProofRequestProbability = 0
err := s.keepers.ProofKeeper.SetParams(s.ctx, proofParams)
require.NoError(s.T(), err)

s.serviceId = "svc1"
s.appBech32 = sample.AccAddress()
s.supplierBech32 = sample.AccAddress()
Expand Down
2 changes: 2 additions & 0 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ var (
ParamsMsgs: ModuleParamsMessages{
MsgUpdateParams: suppliertypes.MsgUpdateParams{},
MsgUpdateParamsResponse: suppliertypes.MsgUpdateParamsResponse{},
MsgUpdateParam: suppliertypes.MsgUpdateParam{},
MsgUpdateParamResponse: suppliertypes.MsgUpdateParamResponse{},
QueryParamsRequest: suppliertypes.QueryParamsRequest{},
QueryParamsResponse: suppliertypes.QueryParamsResponse{},
},
Expand Down
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 @@ -161,6 +161,15 @@
},
"expiration": "2500-01-01T00:00:00Z"
},
{
"granter": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"grantee": "pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw",
"authorization": {
"@type": "\/cosmos.authz.v1beta1.GenericAuthorization",
"msg": "\/poktroll.supplier.MsgUpdateParam"
},
"expiration": "2500-01-01T00:00:00Z"
},
{
"granter": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"grantee": "pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw",
Expand Down
37 changes: 37 additions & 0 deletions x/supplier/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package keeper

import (
"context"

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

// UpdateParam updates a single parameter in the proof module and returns
// all active parameters.
func (k msgServer) UpdateParam(ctx context.Context, msg *suppliertypes.MsgUpdateParam) (*suppliertypes.MsgUpdateParamResponse, error) {
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

if k.GetAuthority() != msg.Authority {
return nil, suppliertypes.ErrSupplierInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
}

// TODO_UPNEXT(@bryanchriswhite, #612): uncomment & add a min_stake case.

//params := k.GetParams(ctx)

switch msg.Name {
default:
return nil, suppliertypes.ErrSupplierParamInvalid.Wrapf("unsupported param %q", msg.Name)
}

//if err := k.SetParams(ctx, params); err != nil {
// return nil, err
//}
//
//updatedParams := k.GetParams(ctx)
//return &suppliertypes.MsgUpdateParamResponse{
// Params: &updatedParams,
//}, nil
}
6 changes: 6 additions & 0 deletions x/supplier/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-supplier 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/supplier/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
defaultWeightMsgUnstakeSupplier 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
suppliersimulation.SimulateMsgUnstakeSupplier(am.accountKeeper, am.bankKeeper, am.supplierKeeper),
))

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

// 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 {
suppliersimulation.SimulateMsgUpdateParam(am.accountKeeper, am.bankKeeper, am.supplierKeeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}
30 changes: 30 additions & 0 deletions x/supplier/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/supplier/keeper"
"github.com/pokt-network/poktroll/x/supplier/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/supplier/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),
&MsgUnstakeSupplier{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParam{},
)
// this line is used by starport scaffolding # 3

registry.RegisterImplementations((*sdk.Msg)(nil),
Expand Down
1 change: 1 addition & 0 deletions x/supplier/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ var (
ErrSupplierIsUnstaking = sdkerrors.Register(ModuleName, 1109, "supplier is in unbonding period")
ErrSupplierParamsInvalid = sdkerrors.Register(ModuleName, 1110, "invalid supplier params")
ErrSupplierServiceNotFound = sdkerrors.Register(ModuleName, 1111, "service not found")
ErrSupplierParamInvalid = sdkerrors.Register(ModuleName, 1112, "the provided param is invalid")
)
Loading

0 comments on commit b975a2a

Please sign in to comment.