Skip to content

Commit

Permalink
[Claim/proof] feat: add claim_window_open_offset_blocks shared modu…
Browse files Browse the repository at this point in the history
…le param (#561)

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk authored Jun 3, 2024
1 parent 488c0d2 commit 8d43941
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 53 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ params_update_shared_all: ## Update the session module params
params_update_shared_num_blocks_per_session: ## Update the shared module params
poktrolld tx authz exec ./tools/scripts/params/shared_num_blocks_per_session.json $(PARAM_FLAGS)

.PHONY: params_update_shared_claim_window_open_offset_blocks
params_update_shared_claim_window_open_offset_blocks: ## Update the shared module params
poktrolld tx authz exec ./tools/scripts/params/shared_claim_window_open_offset_blocks.json $(PARAM_FLAGS)

.PHONY: params_query_all
params_query_all: check_jq ## Query the params from all available modules
@for module in $(MODULES); do \
Expand Down
108 changes: 85 additions & 23 deletions api/poktroll/shared/params.pulsar.go

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

1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,4 @@ genesis:
shared:
params:
num_blocks_per_session: 4
claim_window_open_offset_blocks: 0
2 changes: 2 additions & 0 deletions e2e/tests/parse_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (s *suite) newSharedMsgUpdateParams(params paramsMap) cosmostypes.Msg {
switch paramName {
case sharedtypes.ParamNumBlocksPerSession:
msgUpdateParams.Params.NumBlocksPerSession = uint64(paramValue.value.(int64))
case sharedtypes.ParamClaimWindowOpenOffsetBlocks:
msgUpdateParams.Params.ClaimWindowOpenOffsetBlocks = uint64(paramValue.value.(int64))
default:
s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName)
}
Expand Down
6 changes: 4 additions & 2 deletions e2e/tests/update_params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Feature: Params Namespace
And all "shared" module params are set to their default values
And an authz grant from the "gov" "module" account to the "pnf" "user" account for the "/poktroll.shared.MsgUpdateParams" message exists
When the "pnf" account sends an authz exec message to update all "shared" module params
| name | value | type |
| num_blocks_per_session | 10 | int64 |
| name | value | type |
| num_blocks_per_session | 8 | int64 |
| claim_window_open_offset_blocks | 8 | int64 |
Then all "shared" module params should be updated

# NB: If you are reading this and any module has parameters that
Expand All @@ -61,6 +62,7 @@ Feature: Params Namespace
| tokenomics | /poktroll.tokenomics.MsgUpdateParam | compute_units_to_tokens_multiplier | 68 | int64 |
| proof | /poktroll.proof.MsgUpdateParam | min_relay_difficulty_bits | 12 | int64 |
| shared | /poktroll.shared.MsgUpdateParam | num_blocks_per_session | 8 | int64 |
| shared | /poktroll.shared.MsgUpdateParam | claim_window_open_offset_blocks | 8 | int64 |

Scenario: An unauthorized user cannot update individual module params
Given the user has the pocketd binary installed
Expand Down
18 changes: 14 additions & 4 deletions e2e/tests/update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,23 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) {
},
)
case sharedtypes.ModuleName:
numBlocksPerSession := uint64(s.expectedModuleParams[moduleName][sharedtypes.ParamNumBlocksPerSession].value.(int64))
params := sharedtypes.DefaultParams()
paramsMap := s.expectedModuleParams[moduleName]

numBlocksPerSessionParam, ok := paramsMap[sharedtypes.ParamNumBlocksPerSession]
if ok {
params.NumBlocksPerSession = uint64(numBlocksPerSessionParam.value.(int64))
}

claimWindowOpenOffsetBlocksParam, ok := paramsMap[sharedtypes.ParamClaimWindowOpenOffsetBlocks]
if ok {
params.ClaimWindowOpenOffsetBlocks = uint64(claimWindowOpenOffsetBlocksParam.value.(int64))
}

assertUpdatedParams(s,
[]byte(res.Stdout),
&sharedtypes.QueryParamsResponse{
Params: sharedtypes.Params{
NumBlocksPerSession: numBlocksPerSession,
},
Params: params,
},
)
case apptypes.ModuleName:
Expand Down
4 changes: 4 additions & 0 deletions proto/poktroll/shared/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ message Params {
option (amino.name) = "poktroll/x/shared/Params";
option (gogoproto.equal) = true;

// num_blocks_per_session is the number of blocks between the session start & end heights.
uint64 num_blocks_per_session = 1 [(gogoproto.jsontag) = "num_blocks_per_session"];
// claim_window_open_offset_blocks is the number of blocks after the session grace
// period height, at which the claim window opens.
uint64 claim_window_open_offset_blocks = 2 [(gogoproto.jsontag) = "claim_window_open_offset_blocks"];
}
3 changes: 2 additions & 1 deletion tools/scripts/params/shared_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@type": "/poktroll.shared.MsgUpdateParams",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"params": {
"num_blocks_per_session": "4"
"num_blocks_per_session": "4",
"claim_window_open_offset_blocks": "0",
}
}
]
Expand Down
12 changes: 12 additions & 0 deletions tools/scripts/params/shared_claim_window_open_offset_blocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"body": {
"messages": [
{
"@type": "/poktroll.shared.MsgUpdateParam",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"name": "claim_window_open_offset_blocks",
"as_int64": "0"
}
]
}
}
12 changes: 12 additions & 0 deletions x/shared/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ func (k msgServer) UpdateParam(ctx context.Context, msg *types.MsgUpdateParam) (
}

params.NumBlocksPerSession = numBlocksPerSession
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)
}
claimWindowOpenOffsetBlocks := uint64(value.AsInt64)

if err := types.ValidateClaimWindowOpenOffsetBlocks(claimWindowOpenOffsetBlocks); err != nil {
return nil, err
}

params.ClaimWindowOpenOffsetBlocks = claimWindowOpenOffsetBlocks
default:
return nil, types.ErrSharedParamInvalid.Wrapf("unsupported param %q", msg.Name)
}
Expand Down
34 changes: 31 additions & 3 deletions x/shared/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) {
// Ensure the default values are different from the new values we want to set
require.NotEqual(t, uint64(expectedNumBlocksPerSession), defaultParams.NumBlocksPerSession)

// Update the min relay difficulty bits
// Update the number of blocks per session
updateParamMsg := &sharedtypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: sharedtypes.ParamNumBlocksPerSession,
Expand All @@ -37,6 +37,34 @@ func TestMsgUpdateParam_UpdateNumBlocksPerSession(t *testing.T) {

require.Equal(t, uint64(expectedNumBlocksPerSession), res.Params.NumBlocksPerSession)

// TODO_BLOCKER: once we have more than one param per module, add assertions
// here which ensure that other params were not changed!
// Ensure the other parameters are unchanged
require.Equal(t, defaultParams.ClaimWindowOpenOffsetBlocks, res.Params.ClaimWindowOpenOffsetBlocks)
}

func TestMsgUpdateParam_UpdateClaimWindowOpenOffsetBlocks(t *testing.T) {
var expectedClaimWindowOpenOffestBlocks int64 = 4

k, ctx := keepertest.SharedKeeper(t)
msgSrv := keeper.NewMsgServerImpl(k)

// Set the parameters to their default values
defaultParams := sharedtypes.DefaultParams()
require.NoError(t, k.SetParams(ctx, defaultParams))

// Ensure the default values are different from the new values we want to set
require.NotEqual(t, uint64(expectedClaimWindowOpenOffestBlocks), defaultParams.ClaimWindowOpenOffsetBlocks)

// Update the claim window open offset blocks
updateParamMsg := &sharedtypes.MsgUpdateParam{
Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Name: sharedtypes.ParamClaimWindowOpenOffsetBlocks,
AsType: &sharedtypes.MsgUpdateParam_AsInt64{AsInt64: expectedClaimWindowOpenOffestBlocks},
}
res, err := msgSrv.UpdateParam(ctx, updateParamMsg)
require.NoError(t, err)

require.Equal(t, uint64(expectedClaimWindowOpenOffestBlocks), res.Params.ClaimWindowOpenOffsetBlocks)

// Ensure the other parameters are unchanged
require.Equal(t, defaultParams.NumBlocksPerSession, res.Params.NumBlocksPerSession)
}
5 changes: 3 additions & 2 deletions x/shared/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ func (msg *MsgUpdateParam) ValidateBasic() error {

// Parameter name must be supported by this module.
switch msg.Name {
case ParamNumBlocksPerSession:
case ParamNumBlocksPerSession,
ParamClaimWindowOpenOffsetBlocks:
return msg.paramTypeIsInt64()
default:
return ErrSharedParamNameInvalid.Wrapf("unsupported name param %q", msg.Name)
return ErrSharedParamNameInvalid.Wrapf("unsupported param %q", msg.Name)
}
}

Expand Down
Loading

0 comments on commit 8d43941

Please sign in to comment.