Skip to content

Commit

Permalink
[On-Chain] Refactor uint64 type individual param update logic (#863)
Browse files Browse the repository at this point in the history
## Summary

In the context of individual param updates (`MsgUpdateParam`), `uint64`
typed params were previously supported via an `MsgUpdateParam_AsInt64`
type for obsolete reasons. This PR aligns all `uint64` type params with
the corresopnding `MsgUpdateParam#AsType`s using a new
`MsgUpdateParam_AsUint64` type.

## Issue

- #859

## Type of change

Select one or more from the following:

- [ ] New feature, functionality or library
- [ ] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [x] 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`
- [x] **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 15, 2024
1 parent 931ae15 commit 3497ff4
Show file tree
Hide file tree
Showing 22 changed files with 573 additions and 893 deletions.
224 changes: 113 additions & 111 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

350 changes: 86 additions & 264 deletions api/poktroll/proof/tx.pulsar.go

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions api/poktroll/shared/tx.pulsar.go

Large diffs are not rendered by default.

22 changes: 3 additions & 19 deletions e2e/tests/parse_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,6 @@ func (s *suite) newTokenomicsMsgUpdateParam(authority string, param paramAny) (m

func (s *suite) newProofMsgUpdateParam(authority string, param paramAny) (msg proto.Message) {
switch param.typeStr {
case "string":
msg = proto.Message(&prooftypes.MsgUpdateParam{
Authority: authority,
Name: param.name,
AsType: &prooftypes.MsgUpdateParam_AsString{
AsString: param.value.(string),
},
})
case "int64":
msg = proto.Message(&prooftypes.MsgUpdateParam{
Authority: authority,
Name: param.name,
AsType: &prooftypes.MsgUpdateParam_AsInt64{
AsInt64: param.value.(int64),
},
})
case "bytes":
msg = proto.Message(&prooftypes.MsgUpdateParam{
Authority: authority,
Expand Down Expand Up @@ -347,12 +331,12 @@ func (s *suite) newSharedMsgUpdateParam(authority string, param paramAny) (msg p
AsString: param.value.(string),
},
})
case "int64":
case "uint64":
msg = proto.Message(&sharedtypes.MsgUpdateParam{
Authority: authority,
Name: param.name,
AsType: &sharedtypes.MsgUpdateParam_AsInt64{
AsInt64: param.value.(int64),
AsType: &sharedtypes.MsgUpdateParam_AsUint64{
AsUint64: param.value.(uint64),
},
})
case "bytes":
Expand Down
4 changes: 2 additions & 2 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ message MsgUpdateParam {

string name = 2;
oneof asType {
int64 as_int64 = 3;
cosmos.base.v1beta1.Coin as_coin = 4;
uint64 as_uint64 = 3 [(gogoproto.jsontag) = "as_uint64"];
cosmos.base.v1beta1.Coin as_coin = 4 [(gogoproto.jsontag) = "as_coin"];
};
}

Expand Down
2 changes: 0 additions & 2 deletions proto/poktroll/proof/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ message MsgUpdateParam {
// specified in the `Params`` message in `proof/params.proto.`
string name = 2;
oneof as_type {
string as_string = 3 [(gogoproto.jsontag) = "as_string"];
int64 as_int64 = 6 [(gogoproto.jsontag) = "as_int64"];
bytes as_bytes = 7 [(gogoproto.jsontag) = "as_bytes"];
float as_float = 8 [(gogoproto.jsontag) = "as_float"];
cosmos.base.v1beta1.Coin as_coin = 9 [(gogoproto.jsontag) = "as_coin"];
Expand Down
2 changes: 1 addition & 1 deletion proto/poktroll/shared/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ message MsgUpdateParam {
string name = 2;
oneof as_type {
string as_string = 3 [(gogoproto.jsontag) = "as_string"];
int64 as_int64 = 6 [(gogoproto.jsontag) = "as_int64"];
uint64 as_uint64 = 6 [(gogoproto.jsontag) = "as_uint64"];
bytes as_bytes = 7 [(gogoproto.jsontag) = "as_bytes"];
}
}
Expand Down
10 changes: 2 additions & 8 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ var (
QueryParamsResponse: sharedtypes.QueryParamsResponse{},
},
ParamTypes: map[ParamType]any{
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
ParamTypeUint64: sharedtypes.MsgUpdateParam_AsInt64{},
ParamTypeInt64: sharedtypes.MsgUpdateParam_AsInt64{},
ParamTypeUint64: sharedtypes.MsgUpdateParam_AsUint64{},
ParamTypeString: sharedtypes.MsgUpdateParam_AsString{},
ParamTypeBytes: sharedtypes.MsgUpdateParam_AsBytes{},
},
Expand Down Expand Up @@ -147,8 +145,7 @@ var (
MinStake: &ValidActorMinStake,
},
ParamTypes: map[ParamType]any{
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
ParamTypeUint64: apptypes.MsgUpdateParam_AsInt64{},
ParamTypeUint64: apptypes.MsgUpdateParam_AsUint64{},
ParamTypeCoin: apptypes.MsgUpdateParam_AsCoin{},
},
DefaultParams: apptypes.DefaultParams(),
Expand Down Expand Up @@ -209,9 +206,6 @@ var (
ProofSubmissionFee: &ValidProofSubmissionFeeCoin,
},
ParamTypes: map[ParamType]any{
ParamTypeUint64: prooftypes.MsgUpdateParam_AsInt64{},
ParamTypeInt64: prooftypes.MsgUpdateParam_AsInt64{},
ParamTypeString: prooftypes.MsgUpdateParam_AsString{},
ParamTypeBytes: prooftypes.MsgUpdateParam_AsBytes{},
ParamTypeFloat32: prooftypes.MsgUpdateParam_AsFloat{},
ParamTypeCoin: prooftypes.MsgUpdateParam_AsCoin{},
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/suites/update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (s *ParamsSuite) RunUpdateParamAsSigner(
switch paramType {
case ParamTypeUint64:
// NB: MsgUpdateParam doesn't currently support uint64 param type.
msgAsTypeValue.Elem().FieldByName("AsInt64").SetInt(int64(paramReflectValue.Interface().(uint64)))
msgAsTypeValue.Elem().FieldByName("AsUint64").Set(paramReflectValue)
case ParamTypeInt64:
msgAsTypeValue.Elem().FieldByName("AsInt64").Set(paramReflectValue)
case ParamTypeFloat32:
Expand Down
15 changes: 12 additions & 3 deletions x/application/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ func (k msgServer) UpdateParam(ctx context.Context, msg *apptypes.MsgUpdateParam
params := k.GetParams(ctx)

switch msg.Name {
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
case apptypes.ParamMaxDelegatedGateways:
logger = logger.With("param_value", msg.GetAsInt64())
params.MaxDelegatedGateways = uint64(msg.GetAsInt64())
logger = logger.With("param_value", msg.GetAsUint64())

params.MaxDelegatedGateways = msg.GetAsUint64()
if _, ok := msg.AsType.(*apptypes.MsgUpdateParam_AsUint64); !ok {
return nil, apptypes.ErrAppParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}
maxDelegatedGateways := msg.GetAsUint64()

if err := apptypes.ValidateMaxDelegatedGateways(maxDelegatedGateways); err != nil {
return nil, apptypes.ErrAppParamInvalid.Wrapf("maxdelegegated_gateways (%d): %v", maxDelegatedGateways, err)
}
params.MaxDelegatedGateways = maxDelegatedGateways
case apptypes.ParamMinStake:
logger = logger.With("param_value", msg.GetAsCoin())
params.MinStake = msg.GetAsCoin()
Expand Down
2 changes: 1 addition & 1 deletion x/application/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMsgUpdateParam_UpdateMaxDelegatedGatewaysOnly(t *testing.T) {
updateParamMsg := &apptypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: apptypes.ParamMaxDelegatedGateways,
AsType: &apptypes.MsgUpdateParam_AsInt64{AsInt64: int64(expectedMaxDelegatedGateways)},
AsType: &apptypes.MsgUpdateParam_AsUint64{AsUint64: expectedMaxDelegatedGateways},
}
res, err := msgSrv.UpdateParam(ctx, updateParamMsg)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions x/application/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewMsgUpdateParam(authority string, name string, asType any) *MsgUpdatePara

switch t := asType.(type) {
case uint64:
asTypeIface = &MsgUpdateParam_AsInt64{AsInt64: int64(t)}
asTypeIface = &MsgUpdateParam_AsUint64{AsUint64: t}
case *cosmostypes.Coin:
asTypeIface = &MsgUpdateParam_AsCoin{AsCoin: t}
default:
Expand Down Expand Up @@ -46,7 +46,7 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
if err := msg.paramTypeIsUint64(); err != nil {
return err
}
return ValidateMaxDelegatedGateways(uint64(msg.GetAsInt64()))
return ValidateMaxDelegatedGateways(msg.GetAsUint64())
case ParamMinStake:
if err := msg.paramTypeIsCoin(); err != nil {
return err
Expand All @@ -58,10 +58,10 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
}

func (msg *MsgUpdateParam) paramTypeIsUint64() error {
if _, ok := msg.AsType.(*MsgUpdateParam_AsInt64); !ok {
if _, ok := msg.AsType.(*MsgUpdateParam_AsUint64); !ok {
return ErrAppParamInvalid.Wrapf(""+
"invalid type for param %q; expected %T, got %T",
msg.Name, &MsgUpdateParam_AsInt64{}, msg.AsType,
msg.Name, &MsgUpdateParam_AsUint64{}, msg.AsType,
)
}
return nil
Expand Down
Loading

0 comments on commit 3497ff4

Please sign in to comment.