Skip to content

Commit

Permalink
[Relayminer] refactor: relayminer to use `claim_window_open_offset_bl…
Browse files Browse the repository at this point in the history
…ocks` shared param (#565)

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk authored Jun 3, 2024
1 parent 8d43941 commit 45314cd
Show file tree
Hide file tree
Showing 25 changed files with 373 additions and 66 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ params_update_shared_num_blocks_per_session: ## Update the shared module params
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_update_shared_claim_window_close_offset_blocks
params_update_shared_claim_window_close_offset_blocks: ## Update the shared module params
poktrolld tx authz exec ./tools/scripts/params/shared_claim_window_close_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
106 changes: 87 additions & 19 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 @@ -187,3 +187,4 @@ genesis:
params:
num_blocks_per_session: 4
claim_window_open_offset_blocks: 0
claim_window_close_offset_blocks: 4
2 changes: 2 additions & 0 deletions e2e/tests/parse_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (s *suite) newSharedMsgUpdateParams(params paramsMap) cosmostypes.Msg {
msgUpdateParams.Params.NumBlocksPerSession = uint64(paramValue.value.(int64))
case sharedtypes.ParamClaimWindowOpenOffsetBlocks:
msgUpdateParams.Params.ClaimWindowOpenOffsetBlocks = uint64(paramValue.value.(int64))
case sharedtypes.ParamClaimWindowCloseOffsetBlocks:
msgUpdateParams.Params.ClaimWindowCloseOffsetBlocks = uint64(paramValue.value.(int64))
default:
s.Fatalf("unexpected %q type param name %q", paramValue.typeStr, paramName)
}
Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/update_params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Feature: Params Namespace
| name | value | type |
| num_blocks_per_session | 8 | int64 |
| claim_window_open_offset_blocks | 8 | int64 |
| claim_window_close_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 @@ -63,6 +64,7 @@ Feature: Params Namespace
| 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 |
| shared | /poktroll.shared.MsgUpdateParam | claim_window_close_offset_blocks | 8 | int64 |

Scenario: An unauthorized user cannot update individual module params
Given the user has the pocketd binary installed
Expand Down
5 changes: 5 additions & 0 deletions e2e/tests/update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ func (s *suite) assertExpectedModuleParamsUpdated(moduleName string) {
params.ClaimWindowOpenOffsetBlocks = uint64(claimWindowOpenOffsetBlocksParam.value.(int64))
}

claimWindowCloseOffsetBlocksParam, ok := paramsMap[sharedtypes.ParamClaimWindowCloseOffsetBlocks]
if ok {
params.ClaimWindowCloseOffsetBlocks = uint64(claimWindowCloseOffsetBlocksParam.value.(int64))
}

assertUpdatedParams(s,
[]byte(res.Stdout),
&sharedtypes.QueryParamsResponse{
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,7 @@ type SessionQueryClient interface {
type SharedQueryClient interface {
// GetParams queries the chain for the current shared module parameters.
GetParams(ctx context.Context) (*sharedtypes.Params, error)
// GetClaimWindowOpenHeight returns the block height at which the claim window of
// the session that includes queryHeight opens.
GetClaimWindowOpenHeight(ctx context.Context, queryHeight int64) (int64, error)
}
17 changes: 17 additions & 0 deletions pkg/client/query/sharedquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/gogoproto/grpc"

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

Expand Down Expand Up @@ -53,3 +54,19 @@ func (sq *sharedQuerier) GetParams(ctx context.Context) (*sharedtypes.Params, er
}
return &res.Params, nil
}

// GetClaimWindowOpenHeight returns the block height at which the claim window of
// the session that includes queryHeight opens.
//
// TODO_TECHDEBT(#543): We don't really want to have to query the params for every method call.
// Once `ModuleParamsClient` is implemented, use its replay observable's `#Last()` method
// to get the most recently (asynchronously) observed (and cached) value.
// TODO_BLOCKER(#543): We also don't really want to use the current value of the params. Instead,
// we should be using the value that the params had for the session which includes queryHeight.
func (sq *sharedQuerier) GetClaimWindowOpenHeight(ctx context.Context, queryHeight int64) (int64, error) {
sharedParams, err := sq.GetParams(ctx)
if err != nil {
return 0, err
}
return shared.GetClaimWindowOpenHeight(sharedParams, queryHeight), nil
}
2 changes: 1 addition & 1 deletion pkg/relayer/protocol/block_heights.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetEarliestCreateClaimHeight(ctx context.Context, createClaimWindowStartBlo
rngSeed, _ := binary.Varint(createClaimWindowStartBlockHash)
randomNumber := rand.NewSource(rngSeed).Int63()

// TODO_BLOCKER: query the on-chain governance parameter once available.
// TODO_BLOCKER(#402): query the on-chain governance parameter once available.
// randCreateClaimHeightOffset := randomNumber % (claimproofparams.GovCreateClaimIntervalBlocks - claimproofparams.GovCreateClaimWindowBlocks - 1)
_ = randomNumber
randCreateClaimHeightOffset := int64(0)
Expand Down
Loading

0 comments on commit 45314cd

Please sign in to comment.