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

[Shared] Refresh shared module params logic #852

Merged
merged 197 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 192 commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
d1cd5e6
scaffold: message update-param --module gateway --signer authority na…
bryanchriswhite Sep 9, 2024
91eecfc
chore: update gateway MsgUpdateParam fields
bryanchriswhite Sep 9, 2024
ef62280
chore: update MsgUpdateParamResponse fields
bryanchriswhite Sep 23, 2024
f7a6e5b
chore: comment out autocli for gateway module param updates
bryanchriswhite Sep 10, 2024
8957f1c
fix: linter error
bryanchriswhite Sep 26, 2024
3016ca3
revert: premature changes
bryanchriswhite Sep 26, 2024
899effb
feat: add min_stake gateway module param
bryanchriswhite Sep 26, 2024
83c1d74
chore: cleanup makefiles and param update JSON files
bryanchriswhite Sep 23, 2024
55e6a31
chore: add gateway module param make targets
bryanchriswhite Sep 23, 2024
ddd68bb
refctor: consolidate param config types
bryanchriswhite Sep 26, 2024
fa8caf6
tests: improve error messaging
bryanchriswhite Sep 26, 2024
ae006e2
tests: add coverage over gateway min stake param updates
bryanchriswhite Sep 26, 2024
e92e3b1
chore: add as_coin as_type type 😉
bryanchriswhite Sep 26, 2024
b2e1267
chore: add app MsgUpdateParam to genesis authorizations
bryanchriswhite Sep 26, 2024
0373fa2
fix: typo
bryanchriswhite Sep 26, 2024
da7894a
chore: cleanup makefiles
bryanchriswhite Sep 26, 2024
015c537
wip: fixing tests
bryanchriswhite Sep 26, 2024
1ac6c48
tests: add tests
bryanchriswhite Sep 26, 2024
db366f6
tests: remove erroneous case
bryanchriswhite Sep 26, 2024
60bef17
test: gateway staking below minimum fails
bryanchriswhite Sep 27, 2024
a21687f
feat: gateway min stake validation & grpc status error returns
bryanchriswhite Sep 27, 2024
7e9f857
chore: cleanup comments
bryanchriswhite Sep 27, 2024
4140710
scaffold: message update-param --module examplemod --signer authority…
bryanchriswhite Sep 27, 2024
0a8d922
chore: update MsgUpdateParam fields
bryanchriswhite Sep 27, 2024
c88edd6
chore: comment out application MsgUpdateParam autocli
bryanchriswhite Sep 27, 2024
da51239
chore: add application MsgUpdateParam to dao genesis authorizations
bryanchriswhite Sep 27, 2024
45c5a99
chore: update NewMsgUpdateParam constructor
bryanchriswhite Sep 27, 2024
d987e09
fix: simulations generated code
bryanchriswhite Sep 27, 2024
0da255d
chore: add min_stake param to application module params
bryanchriswhite Sep 27, 2024
4542628
chore: update params config for param updates test suite
bryanchriswhite Sep 27, 2024
b81ca9e
chore: add parameter validation
bryanchriswhite Sep 27, 2024
cdff4b3
chore: add param update make targets and JSON msgs
bryanchriswhite Sep 27, 2024
be24753
chore: add default application min_stake param of 1 POKT to genesis c…
bryanchriswhite Sep 27, 2024
45b6e5c
chore: update MsgUpdateParamResponse & add AsUint64 AsType type
bryanchriswhite Sep 27, 2024
b3e139a
feat: implement MsgUpdateParam handler
bryanchriswhite Sep 27, 2024
872202b
test: MsgUpdateParam handler
bryanchriswhite Sep 27, 2024
a49d69b
feat: implement NewMsgUpdateParam constructor
bryanchriswhite Sep 27, 2024
d63a429
chore: add min_stake validation
bryanchriswhite Sep 27, 2024
9040bf0
chore: tidy up
bryanchriswhite Sep 27, 2024
4340590
chore: review feedback improvements
bryanchriswhite Sep 30, 2024
4b8e95b
Merge branch 'main' into issues/612/chore/gateway-msg-update-param
bryanchriswhite Sep 30, 2024
352afa1
chore: review feedback improvements
bryanchriswhite Sep 30, 2024
6afdaef
fix: linter errors
bryanchriswhite Sep 30, 2024
0839ae4
chore: review feedback improvements
bryanchriswhite Sep 30, 2024
34b0d6d
Merge remote-tracking branch 'pokt/issues/612/chore/gateway-msg-updat…
bryanchriswhite Sep 30, 2024
f48fa66
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Sep 30, 2024
6c5e13f
chore: review feedback improvements
bryanchriswhite Sep 30, 2024
a77877b
fix: test error message
bryanchriswhite Sep 30, 2024
9f65d25
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Sep 30, 2024
28962ba
Merge remote-tracking branch 'pokt/main' into issues/612/param/min-st…
bryanchriswhite Sep 30, 2024
497ecd9
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Sep 30, 2024
d92eb59
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Sep 30, 2024
941b801
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Sep 30, 2024
36e5f2e
chore: update message_update_param_test.go
bryanchriswhite Sep 30, 2024
2baa173
fix: genesis tests
bryanchriswhite Sep 30, 2024
7018149
chore: use AsInt64 to update MaxDelegatedGateways for consistency
bryanchriswhite Sep 30, 2024
c36fe79
chore: ensure application stake handler returns grpc status errors
bryanchriswhite Sep 30, 2024
eab9417
tests: update app stake msg handler unit tests
bryanchriswhite Sep 30, 2024
da9b322
feat: enforce application min stake when staking
bryanchriswhite Sep 30, 2024
5e47c98
fix: failing unit tests
bryanchriswhite Sep 30, 2024
323299e
chore: add PreGeneratedAccountIterator#MustNext()
bryanchriswhite Oct 1, 2024
d888548
chore: update require deps for RingClient
bryanchriswhite Oct 1, 2024
e87564d
refactor: extract application unbonding to method
bryanchriswhite Oct 1, 2024
7d5c17b
test: app is unbonded when settlement lowers stake below min
bryanchriswhite Oct 1, 2024
030f2ef
feat: unbond app when stake drops below min when settling
bryanchriswhite Oct 1, 2024
3e77f7c
chore: add TODO_NEXT comments
bryanchriswhite Oct 1, 2024
090ca9a
fix: failing tests
bryanchriswhite Oct 1, 2024
c14ad46
chore: add TODOs & update comments
bryanchriswhite Oct 1, 2024
d0b4187
chore: add TODOs & update comments
bryanchriswhite Oct 1, 2024
891a858
chore: review feedback improvements
bryanchriswhite Oct 2, 2024
08e99ba
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Oct 2, 2024
da9a240
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 2, 2024
d85d969
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Oct 2, 2024
47da555
Merge branch 'issues/612/application/min-stake-param' into issues/612…
bryanchriswhite Oct 2, 2024
0f55e91
Merge branch 'issues/612/application/staking' into issues/612/applica…
bryanchriswhite Oct 2, 2024
d98b22b
test: simplify
bryanchriswhite Oct 2, 2024
ccc3f53
fix: e2e test
bryanchriswhite Oct 2, 2024
47e0993
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Oct 2, 2024
c08abfd
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 2, 2024
8336d76
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Oct 2, 2024
9386791
Merge branch 'issues/612/application/min-stake-param' into issues/612…
bryanchriswhite Oct 2, 2024
0a72a83
Merge branch 'issues/612/application/staking' into issues/612/applica…
bryanchriswhite Oct 2, 2024
ce5b693
chore: increase genesis app stakes so E2E tests don't burn them out
bryanchriswhite Oct 2, 2024
2d2e815
scaffold: message update-param --module examplemod --signer authority…
bryanchriswhite Oct 2, 2024
bb0267d
chore: update MsgUpdateParam & MsgUpdateParamResponse field types
bryanchriswhite Oct 2, 2024
83b7311
chore: comment out autoCLI
bryanchriswhite Oct 2, 2024
fd42c5e
chore: add supplier MsgUpdateParam to DAO genesis authorizations
bryanchriswhite Oct 2, 2024
63bc125
chore: add supplier param invalid error
bryanchriswhite Oct 2, 2024
f3bb3e0
chore: update NewMsgUpdateParam() & MsgUpdateParam#ValidateBasic()
bryanchriswhite Oct 2, 2024
acb6622
chore: update msgServer#UpdateParam()
bryanchriswhite Oct 2, 2024
935a40f
chore: update param update test module param config
bryanchriswhite Oct 2, 2024
b29843e
Empty commit
bryanchriswhite Oct 2, 2024
8c25061
Empty commit
bryanchriswhite Oct 2, 2024
3f59041
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Oct 2, 2024
ce328bb
fix: linter errors
bryanchriswhite Oct 2, 2024
17b6420
fix: failing tests & add TODO_UPNEXT comments
bryanchriswhite Oct 2, 2024
4583b75
chore: add min_stake param to supplier module
bryanchriswhite Oct 2, 2024
e84643d
test: add min_stake to supplier ModuleParamConfig
bryanchriswhite Oct 2, 2024
f694bad
chore: add min_stake genesis param to config.yml
bryanchriswhite Oct 2, 2024
000c330
chore: add min_stake defaults and validation
bryanchriswhite Oct 2, 2024
5e72e47
chore: add min_stake case to MsgUpdateParam handler
bryanchriswhite Oct 2, 2024
c5ede9d
chore: update MsgUpdateParams, MsgUpdateParam, & Params unit tests
bryanchriswhite Oct 2, 2024
698712b
chore: add make targets and JSON files
bryanchriswhite Oct 2, 2024
b94cd63
fix: unit tests
bryanchriswhite Oct 2, 2024
fcc18c6
chore: return gRPC status errors from msgServer methods
bryanchriswhite Oct 2, 2024
6c18b75
fix: genesis test
bryanchriswhite Oct 2, 2024
4e259c9
chore: apply improvements
bryanchriswhite Oct 2, 2024
2808925
chore: add godoc style comment to min_stake params field
bryanchriswhite Oct 2, 2024
197af04
chore: add godoc style comment to min_stake params field
bryanchriswhite Oct 2, 2024
2a33127
chore: improvements:
bryanchriswhite Oct 4, 2024
3280142
chore: improve logging & ensure gRPC status error returns
bryanchriswhite Oct 4, 2024
98d1c96
chore: improve logging & ensure gRPC status error returns
bryanchriswhite Oct 4, 2024
955b28f
chore: improve logging, validate params in MsgUpdateParam handler, & …
bryanchriswhite Oct 4, 2024
c256eae
chore: review feedback improvements
bryanchriswhite Oct 4, 2024
0d36e0f
Merge remote-tracking branch 'pokt/main' into issues/612/param/min-st…
bryanchriswhite Oct 4, 2024
00914b0
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Oct 4, 2024
f3fa183
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 4, 2024
f4b8284
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Oct 4, 2024
12d1b43
Merge branch 'issues/612/application/min-stake-param' into issues/612…
bryanchriswhite Oct 4, 2024
30b48f4
test: simplify coin equality assertions
bryanchriswhite Oct 4, 2024
b3a3236
Merge branch 'issues/612/application/staking' into issues/612/applica…
bryanchriswhite Oct 4, 2024
1c309b8
Empty commit
bryanchriswhite Oct 4, 2024
e7ff959
Merge branch 'issues/612/param/min-stake-gateway' into issues/612/gat…
bryanchriswhite Oct 4, 2024
1257f6e
Merge branch 'main' into issues/612/gateway/logic
bryanchriswhite Oct 4, 2024
b972e3b
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 4, 2024
0f4a82d
chore: add review feedback TODOs
bryanchriswhite Oct 4, 2024
44257f3
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Oct 4, 2024
561a1aa
Merge branch 'issues/612/application/min-stake-param' into issues/612…
bryanchriswhite Oct 4, 2024
f176fe4
Merge branch 'issues/612/application/staking' into issues/612/applica…
bryanchriswhite Oct 4, 2024
ef4e0ad
chore: reconcile PreGeneratedAccountIterator#MustNext()
bryanchriswhite Oct 4, 2024
4d2c2d9
chore: review feedback improvements
bryanchriswhite Oct 4, 2024
5ba2a48
fix: typo
bryanchriswhite Oct 4, 2024
aef3773
chore: ensure gRPC status error returns from supplier stake handler
bryanchriswhite Oct 4, 2024
fff062b
chore: review improvements
bryanchriswhite Oct 4, 2024
3e4ef9e
fix: linter errors
bryanchriswhite Oct 4, 2024
8c7eadf
Empty commit
bryanchriswhite Oct 4, 2024
a28ff88
Empty commit
bryanchriswhite Oct 4, 2024
cd5e420
chore: review feedback improvements
bryanchriswhite Oct 4, 2024
cc95ebf
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 4, 2024
1c38372
fix: failing test
bryanchriswhite Oct 4, 2024
65158ad
Merge branch 'main' into issues/612/gateway/logic
bryanchriswhite Oct 4, 2024
70f8985
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 4, 2024
3774d66
feat: enforce supplier min stake when staking
bryanchriswhite Oct 4, 2024
4c46084
fix: unit tests
bryanchriswhite Oct 4, 2024
698991a
Empty commit
bryanchriswhite Oct 4, 2024
6c689e8
Merge branch 'issues/612/gateway/logic' into issues/612/app/msg-updat…
bryanchriswhite Oct 4, 2024
c2bf664
Merge branch 'main' into issues/612/app/msg-update-param
bryanchriswhite Oct 4, 2024
0d63e07
fix: linter error
bryanchriswhite Oct 4, 2024
7753572
Merge branch 'issues/612/app/msg-update-param' into issues/612/applic…
bryanchriswhite Oct 4, 2024
5556f4a
Merge remote-tracking branch 'pokt/main' into issues/612/application/…
bryanchriswhite Oct 4, 2024
1faf4ab
chore: regenerate protobufs
bryanchriswhite Oct 4, 2024
48ba5dd
Merge branch 'issues/612/application/min-stake-param' into issues/612…
bryanchriswhite Oct 4, 2024
d91dde7
Merge branch 'main' into issues/612/application/staking
bryanchriswhite Oct 4, 2024
032b849
test: add TestMsgServer_StakeSupplier_FailBelowMinStake
bryanchriswhite Oct 4, 2024
ce8b68c
chore: add gRPC status error
bryanchriswhite Oct 7, 2024
e06dca2
fix: failing unit tests
bryanchriswhite Oct 7, 2024
7bf55d6
Empty commit
bryanchriswhite Oct 7, 2024
a534825
chore: refresh shared module params impl. to match updated docs
bryanchriswhite Oct 2, 2024
9fa962c
fix: failing unit test
bryanchriswhite Oct 7, 2024
5e5d8a4
Merge branch 'issues/612/application/staking' into issues/612/applica…
bryanchriswhite Oct 7, 2024
e119e97
Merge branch 'issues/612/application/burning' into issues/612/supplie…
bryanchriswhite Oct 7, 2024
d99bac2
Merge branch 'issues/612/supplier/msg-update-param' into issues/612/s…
bryanchriswhite Oct 7, 2024
1d87fe3
Merge branch 'issues/612/supplier/min-stake' into issues/612/supplier…
bryanchriswhite Oct 7, 2024
7e9bd33
Empty commit
bryanchriswhite Oct 7, 2024
69c2755
Empty commit
bryanchriswhite Oct 9, 2024
1f7e201
Merge branch 'main' into issues/612/application/staking
bryanchriswhite Oct 9, 2024
0fa9ab8
Merge remote-tracking branch 'pokt/issues/612/application/staking' in…
bryanchriswhite Oct 10, 2024
d91671e
Merge remote-tracking branch 'pokt/main' into issues/612/application/…
bryanchriswhite Oct 10, 2024
c89ee93
chore: quick fixes
bryanchriswhite Oct 10, 2024
ed0d795
fix: linter error
bryanchriswhite Oct 10, 2024
0be55c6
Empty commit
bryanchriswhite Oct 10, 2024
14a5c79
chore: review feedback improvements
bryanchriswhite Oct 11, 2024
735ca2a
test: fix application min stake integration test
bryanchriswhite Oct 11, 2024
1c25798
chore: review feedback improvements
bryanchriswhite Oct 11, 2024
d2dfbd2
chore: regenerate protobufs
bryanchriswhite Oct 11, 2024
48df935
chore: review feedback improvements
bryanchriswhite Oct 11, 2024
b220177
Empty commit
bryanchriswhite Oct 11, 2024
530ce2a
Merge branch 'issues/612/application/burning' into issues/612/supplie…
bryanchriswhite Oct 11, 2024
788d506
Merge remote-tracking branch 'pokt/main' into issues/612/supplier/msg…
bryanchriswhite Oct 11, 2024
071149b
fix: flaky test
bryanchriswhite Oct 14, 2024
13b655a
Merge branch 'issues/612/supplier/msg-update-param' into issues/612/s…
bryanchriswhite Oct 14, 2024
f557714
Merge branch 'issues/612/supplier/min-stake' into issues/612/supplier…
bryanchriswhite Oct 14, 2024
c506c96
Merge branch 'issues/612/supplier/staking' into issues/612/shared/ref…
bryanchriswhite Oct 14, 2024
395126d
fix: linter error
bryanchriswhite Oct 14, 2024
ea028cb
Merge branch 'issues/612/supplier/msg-update-param' into issues/612/s…
bryanchriswhite Oct 14, 2024
8395029
Merge branch 'issues/612/supplier/min-stake' into issues/612/supplier…
bryanchriswhite Oct 14, 2024
f18e347
test: supplier up-staking from below min. stake
bryanchriswhite Oct 14, 2024
fcaef74
Merge branch 'issues/612/supplier/staking' into issues/612/shared/ref…
bryanchriswhite Oct 14, 2024
b166d0d
Merge remote-tracking branch 'pokt/HEAD' into issues/612/supplier/min…
bryanchriswhite Oct 14, 2024
413a084
Merge branch 'issues/612/supplier/min-stake' into issues/612/supplier…
bryanchriswhite Oct 14, 2024
67f28f6
Merge remote-tracking branch 'pokt/main' into issues/612/supplier/sta…
bryanchriswhite Oct 14, 2024
c7aa318
Merge branch 'issues/612/supplier/staking' into issues/612/shared/ref…
bryanchriswhite Oct 14, 2024
6e2b4db
Merge remote-tracking branch 'pokt/main' into issues/612/shared/refresh
bryanchriswhite Oct 14, 2024
d85daf7
Empty commit
bryanchriswhite Oct 14, 2024
3fa5533
Merge branch 'main' into issues/612/shared/refresh
bryanchriswhite Oct 14, 2024
9e06b8e
Merge branch 'main' into issues/612/shared/refresh
bryanchriswhite Oct 14, 2024
972b8df
Empty commit
bryanchriswhite Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 44 additions & 64 deletions x/shared/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,85 @@ package keeper

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

func (k msgServer) UpdateParam(ctx context.Context, msg *types.MsgUpdateParam) (*types.MsgUpdateParamResponse, error) {
logger := k.logger.With(
"method", "UpdateParam",
"param_name", msg.Name,
)

if err := msg.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if k.GetAuthority() != msg.Authority {
return nil, types.ErrSharedInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
return nil, status.Error(
codes.InvalidArgument,
types.ErrSharedInvalidSigner.Wrapf(
"invalid authority; expected %s, got %s",
k.GetAuthority(), msg.Authority,
).Error(),
)
}

params := k.GetParams(ctx)

switch msg.Name {
case types.ParamNumBlocksPerSession:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.NumBlocksPerSession = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.NumBlocksPerSession = uint64(msg.GetAsInt64())
case types.ParamGracePeriodEndOffsetBlocks:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.GracePeriodEndOffsetBlocks = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.GracePeriodEndOffsetBlocks = uint64(msg.GetAsInt64())
case types.ParamClaimWindowOpenOffsetBlocks:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.ClaimWindowOpenOffsetBlocks = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.ClaimWindowOpenOffsetBlocks = uint64(msg.GetAsInt64())
case types.ParamClaimWindowCloseOffsetBlocks:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.ClaimWindowCloseOffsetBlocks = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.ClaimWindowCloseOffsetBlocks = uint64(msg.GetAsInt64())
case types.ParamProofWindowOpenOffsetBlocks:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.ProofWindowOpenOffsetBlocks = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.ProofWindowOpenOffsetBlocks = uint64(msg.GetAsInt64())
case types.ParamProofWindowCloseOffsetBlocks:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.ProofWindowCloseOffsetBlocks = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.ProofWindowCloseOffsetBlocks = uint64(msg.GetAsInt64())
case types.ParamSupplierUnbondingPeriodSessions:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.SupplierUnbondingPeriodSessions = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.SupplierUnbondingPeriodSessions = uint64(msg.GetAsInt64())
case types.ParamApplicationUnbondingPeriodSessions:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}

params.ApplicationUnbondingPeriodSessions = uint64(value.AsInt64)
logger = logger.With("param_value", msg.GetAsInt64())
params.ApplicationUnbondingPeriodSessions = uint64(msg.GetAsInt64())
case types.ParamComputeUnitsToTokensMultiplier:
value, ok := msg.AsType.(*types.MsgUpdateParam_AsInt64)
if !ok {
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported value type for %s param: %T", msg.Name, msg.AsType)
}
computeUnitsToTokensMultiplier := uint64(value.AsInt64)

if err := types.ValidateComputeUnitsToTokensMultiplier(computeUnitsToTokensMultiplier); err != nil {
return nil, err
}

params.ComputeUnitsToTokensMultiplier = computeUnitsToTokensMultiplier
logger = logger.With("param_value", msg.GetAsInt64())
params.ComputeUnitsToTokensMultiplier = uint64(msg.GetAsInt64())
default:
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported param %q", msg.Name)
return nil, status.Error(
codes.InvalidArgument,
types.ErrSharedParamInvalid.Wrapf("unsupported param %q", msg.Name).Error(),
)
}

// Perform a global validation on all params, which includes the updated param.
// This is needed to ensure that the updated param is valid in the context of all other params.
if err := params.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if err := k.SetParams(ctx, params); err != nil {
return nil, err
err = fmt.Errorf("unable to set params: %w", err)
logger.Error(fmt.Sprintf("ERROR: %s", err))
return nil, status.Error(codes.Internal, err.Error())
}

updatedParams := k.GetParams(ctx)

return &types.MsgUpdateParamResponse{
Params: &updatedParams,
}, nil
Expand Down
52 changes: 35 additions & 17 deletions x/shared/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/x/shared/keeper"
"github.com/pokt-network/poktroll/x/shared/types"
Expand Down Expand Up @@ -50,7 +52,7 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) {
require.Equal(t, uint64(expectedNumBlocksPerSession), res.Params.NumBlocksPerSession)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "NumBlocksPerSession")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, string(sharedtypes.KeyNumBlocksPerSession))
}

func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) {
Expand Down Expand Up @@ -95,7 +97,7 @@ func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) {
require.Equal(t, uint64(expectedClaimWindowOpenOffestBlocks), res.Params.ClaimWindowOpenOffsetBlocks)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ClaimWindowOpenOffsetBlocks")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, string(sharedtypes.KeyClaimWindowOpenOffsetBlocks))
}

func TestMsgUpdateParam_UpdateClaimWindowCloseOffsetBlocks(t *testing.T) {
Expand Down Expand Up @@ -140,7 +142,7 @@ func TestMsgUpdateParam_UpdateClaimWindowCloseOffsetBlocks(t *testing.T) {
require.Equal(t, uint64(expectedClaimWindowCloseOffestBlocks), res.Params.ClaimWindowCloseOffsetBlocks)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ClaimWindowCloseOffsetBlocks")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, string(sharedtypes.KeyClaimWindowCloseOffsetBlocks))
}

func TestMsgUpdateParam_UpdateProofWindowOpenOffsetBlocks(t *testing.T) {
Expand Down Expand Up @@ -185,7 +187,7 @@ func TestMsgUpdateParam_UpdateProofWindowOpenOffsetBlocks(t *testing.T) {
require.Equal(t, uint64(expectedProofWindowOpenOffestBlocks), res.Params.ProofWindowOpenOffsetBlocks)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ProofWindowOpenOffsetBlocks")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, string(sharedtypes.KeyProofWindowOpenOffsetBlocks))
}

func TestMsgUpdateParam_UpdateProofWindowCloseOffsetBlocks(t *testing.T) {
Expand Down Expand Up @@ -230,7 +232,7 @@ func TestMsgUpdateParam_UpdateProofWindowCloseOffsetBlocks(t *testing.T) {
require.Equal(t, uint64(expectedProofWindowCloseOffestBlocks), res.Params.ProofWindowCloseOffsetBlocks)

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "ProofWindowCloseOffsetBlocks")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, string(sharedtypes.KeyProofWindowCloseOffsetBlocks))
}

func TestMsgUpdateParam_UpdateGracePeriodEndOffsetBlocks(t *testing.T) {
Expand Down Expand Up @@ -263,11 +265,11 @@ func TestMsgUpdateParam_UpdateGracePeriodEndOffsetBlocks(t *testing.T) {
require.Equal(t, uint64(expectedGracePeriodEndOffestBlocks), res.Params.GetGracePeriodEndOffsetBlocks())

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, "GracePeriodEndOffsetBlocks")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &sharedParams, res.Params, string(sharedtypes.KeyGracePeriodEndOffsetBlocks))
}

func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) {
var expectedSupplierUnbondingPerid int64 = 5
var expectedSupplierUnbondingPeriod int64 = 5

k, ctx := testkeeper.SharedKeeper(t)
msgSrv := keeper.NewMsgServerImpl(k)
Expand All @@ -276,21 +278,21 @@ func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) {
require.NoError(t, k.SetParams(ctx, testSharedParams))

// Ensure the default values are different from the new values we want to set
require.NotEqual(t, uint64(expectedSupplierUnbondingPerid), testSharedParams.GetSupplierUnbondingPeriodSessions())
require.NotEqual(t, uint64(expectedSupplierUnbondingPeriod), testSharedParams.GetSupplierUnbondingPeriodSessions())

// Update the supplier unbonding period param
updateParamMsg := &sharedtypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: sharedtypes.ParamSupplierUnbondingPeriodSessions,
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: expectedSupplierUnbondingPerid},
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: expectedSupplierUnbondingPeriod},
}
res, err := msgSrv.UpdateParam(ctx, updateParamMsg)
require.NoError(t, err)

require.Equal(t, uint64(expectedSupplierUnbondingPerid), res.Params.GetSupplierUnbondingPeriodSessions())
require.Equal(t, uint64(expectedSupplierUnbondingPeriod), res.Params.GetSupplierUnbondingPeriodSessions())

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "SupplierUnbondingPeriodSessions")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, string(sharedtypes.KeySupplierUnbondingPeriodSessions))

// Ensure that a supplier unbonding period that is less than the cumulative
// proof window close blocks is not allowed.
Expand All @@ -300,7 +302,13 @@ func TestMsgUpdateParam_UpdateSupplierUnbondingPeriodSessions(t *testing.T) {
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: 1},
}
_, err = msgSrv.UpdateParam(ctx, updateParamMsg)
require.ErrorIs(t, err, sharedtypes.ErrSharedParamInvalid)
require.EqualError(t, err, status.Error(
codes.InvalidArgument,
sharedtypes.ErrSharedParamInvalid.Wrapf(
"SupplierUnbondingPeriodSessions (%v session) (%v blocks) must be greater than the cumulative ProofWindowCloseOffsetBlocks (%v)",
1, 4, 10,
).Error(),
).Error())
}

func TestMsgUpdateParam_UpdateApplicationUnbondingPeriodSessions(t *testing.T) {
Expand All @@ -327,7 +335,7 @@ func TestMsgUpdateParam_UpdateApplicationUnbondingPeriodSessions(t *testing.T) {
require.Equal(t, uint64(expectedApplicationUnbondingPerid), res.Params.GetApplicationUnbondingPeriodSessions())

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "ApplicationUnbondingPeriodSessions")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, string(sharedtypes.KeyApplicationUnbondingPeriodSessions))

// Ensure that a application unbonding period that is less than the cumulative
// proof window close blocks is not allowed.
Expand All @@ -337,7 +345,13 @@ func TestMsgUpdateParam_UpdateApplicationUnbondingPeriodSessions(t *testing.T) {
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: 1},
}
_, err = msgSrv.UpdateParam(ctx, updateParamMsg)
require.ErrorIs(t, err, sharedtypes.ErrSharedParamInvalid)
require.EqualError(t, err, status.Error(
codes.InvalidArgument,
sharedtypes.ErrSharedParamInvalid.Wrapf(
"ApplicationUnbondingPeriodSessions (%v session) (%v blocks) must be greater than the cumulative ProofWindowCloseOffsetBlocks (%v)",
1, 4, 10,
).Error(),
).Error())
}

func TestMsgUpdateParam_ComputeUnitsToTokenMultiplier(t *testing.T) {
Expand All @@ -364,7 +378,7 @@ func TestMsgUpdateParam_ComputeUnitsToTokenMultiplier(t *testing.T) {
require.Equal(t, uint64(expectedComputeUnitsToTokenMultiplier), res.Params.GetComputeUnitsToTokensMultiplier())

// Ensure the other parameters are unchanged
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, "ComputeUnitsToTokensMultiplier")
testkeeper.AssertDefaultParamsEqualExceptFields(t, &testSharedParams, res.Params, string(sharedtypes.KeyComputeUnitsToTokensMultiplier))

// Ensure that compute units to token multiplier that is less than 1 is not allowed.
updateParamMsg = &sharedtypes.MsgUpdateParam{
Expand All @@ -373,7 +387,12 @@ func TestMsgUpdateParam_ComputeUnitsToTokenMultiplier(t *testing.T) {
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: 0},
}
_, err = msgSrv.UpdateParam(ctx, updateParamMsg)
require.ErrorIs(t, err, sharedtypes.ErrSharedParamInvalid)
require.EqualError(t, err, status.Error(
codes.InvalidArgument,
sharedtypes.ErrSharedParamInvalid.Wrapf(
"invalid ComputeUnitsToTokensMultiplier: (%d)", 0,
).Error(),
).Error())
}

// getMinActorUnbondingPeriodSessions returns the actors unbonding period
Expand All @@ -386,6 +405,5 @@ func getMinActorUnbondingPeriodSessions(
) uint64 {
deltaBlocks := newParamBlocksValue - oldParamBlocksValue
newProofWindowCloseBlocks := types.GetSessionEndToProofWindowCloseBlocks(params) + deltaBlocks

return (newProofWindowCloseBlocks / params.NumBlocksPerSession) + 1
}
62 changes: 49 additions & 13 deletions x/shared/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func NewMsgUpdateParam(authority string, name string, value any) (*MsgUpdatePara
}, nil
}

// ValidateBasic performs a basic validation of the MsgUpdateParam fields. It ensures
// the parameter name is supported and the parameter type matches the expected type for
// a given parameter name.
// ValidateBasic performs a basic validation of the MsgUpdateParam fields. It ensures:
// 1. The parameter name is supported.
// 2. The parameter type matches the expected type for a given parameter name.
// 3. The parameter value is valid (according to its respective validation function).
func (msg *MsgUpdateParam) ValidateBasic() error {
// Validate the address
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
Expand All @@ -48,16 +49,51 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
// Parameter name must be supported by this module.
switch msg.Name {
// TODO_IMPROVE: Add a Uint64 asType instead of using int64 for uint64 params.
case ParamNumBlocksPerSession,
ParamGracePeriodEndOffsetBlocks,
ParamClaimWindowOpenOffsetBlocks,
ParamClaimWindowCloseOffsetBlocks,
ParamProofWindowOpenOffsetBlocks,
ParamProofWindowCloseOffsetBlocks,
ParamSupplierUnbondingPeriodSessions,
ParamApplicationUnbondingPeriodSessions,
ParamComputeUnitsToTokensMultiplier:
return msg.paramTypeIsInt64()
case ParamNumBlocksPerSession:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateNumBlocksPerSession(uint64(msg.GetAsInt64()))
case ParamGracePeriodEndOffsetBlocks:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateGracePeriodEndOffsetBlocks(uint64(msg.GetAsInt64()))
case ParamClaimWindowOpenOffsetBlocks:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateClaimWindowOpenOffsetBlocks(uint64(msg.GetAsInt64()))
case ParamClaimWindowCloseOffsetBlocks:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateClaimWindowCloseOffsetBlocks(uint64(msg.GetAsInt64()))
case ParamProofWindowOpenOffsetBlocks:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateProofWindowOpenOffsetBlocks(uint64(msg.GetAsInt64()))
case ParamProofWindowCloseOffsetBlocks:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateProofWindowCloseOffsetBlocks(uint64(msg.GetAsInt64()))
case ParamSupplierUnbondingPeriodSessions:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateSupplierUnbondingPeriodSessions(uint64(msg.GetAsInt64()))
case ParamApplicationUnbondingPeriodSessions:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateApplicationUnbondingPeriodSessions(uint64(msg.GetAsInt64()))
case ParamComputeUnitsToTokensMultiplier:
if err := msg.paramTypeIsInt64(); err != nil {
return err
}
return ValidateComputeUnitsToTokensMultiplier(uint64(msg.GetAsInt64()))
default:
return ErrSharedParamNameInvalid.Wrapf("unsupported param %q", msg.Name)
}
Expand Down
Loading
Loading