-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Relay Mining] Use per-service difficulty in the relayer (#745)
<!-- README: DELETE THIS COMMENT BLOCK after: 5. Specify _Epic_ and _Iteration_ under _Project_ --> ## Summary - Relayer is updated to query the tokenmoics module to get the relay difficulty target hash specific to the service corresponding to the relay. This is used to determine if a relay is volume applicable. - Relayer is updated to query the service module to get the compute units per relay specific to the service corresponding to the relay. This is used as the weight of the relay when updating the Relayer's SMT for the session corresponding to the relay. - Claims are validated at the time of submission to ensure the total claimed compute units is equal to the number of relays multiplied by the compute units per relay for the corresponding service. - All #705 references in the code have been addressed. - Relay test fixture generator has been updated to use the difficulty threshold hash to be consistent with how the relayer now operates. ## Issue - Relayer should use a service-specific difficulty target hash. - Relayer should use the service-specific ComputeUnitsPerRelay when adding a relay to the SMT for claiming. - #705 ## UPNEXT - Remove the relay_difficulty_target_hash parameter - Addressing any remaining instances of `TODO_FOLLOWUP(@Olshansk, #690)` These have been skipped to: 1) align on the PR before making further changes and 2) restrict the PR size and scope, as these were not strictly required for the above enhancements to function. Depending on the review results, I can add commits to address the above in this PR as well. ## Type of change Select one or more: - [x] New feature, functionality or library - [ ] Bug fix - [x] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing **Documentation changes** (only if making doc changes) - [ ] `make docusaurus_start`; only needed if you make doc changes **Local Testing** (only if making code changes) - [x] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - See [quickstart guide](https://dev.poktroll.com/developer_guide/quickstart) for instructions **PR Testing** (only if making code changes) - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. - **THIS IS VERY EXPENSIVE**, so only do it after all the reviews are complete. - Optionally run `make trigger_ci` if you want to re-trigger tests without any code changes - If tests fail, try re-running failed tests only using the GitHub UI as shown [here](https://github.com/pokt-network/poktroll/assets/1892194/607984e9-0615-4569-9452-4c730190c1d2) ## 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 - [x] I create and reference any new tickets, if applicable - [x] I have left TODOs throughout the codebase, if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added new interfaces for querying tokenomics data, enhancing the app's ability to handle tokenomics-related queries. - Introduced a structured approach to query service information and tokenomics data, improving the overall querying functionality. - Implemented functionality to retrieve compute units per relay for services, optimizing session management. - **Bug Fixes** - Improved error handling for service retrieval and compute units mismatch scenarios. - **Tests** - Enhanced test coverage for tokenomics and service querying functionalities, ensuring robust testing of new features. - **Chores** - Updated test utilities and dependencies to support new service management capabilities. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Bryan White <[email protected]> Co-authored-by: Daniel Olshansky <[email protected]>
- Loading branch information
1 parent
ff05ce6
commit 1556a8f
Showing
29 changed files
with
731 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/depinject" | ||
"github.com/cosmos/gogoproto/grpc" | ||
|
||
"github.com/pokt-network/poktroll/pkg/client" | ||
servicetypes "github.com/pokt-network/poktroll/x/service/types" | ||
sharedtypes "github.com/pokt-network/poktroll/x/shared/types" | ||
) | ||
|
||
var _ client.ServiceQueryClient = (*serviceQuerier)(nil) | ||
|
||
// serviceQuerier is a wrapper around the servicetypes.QueryClient that enables the | ||
// querying of on-chain service information through a single exposed method | ||
// which returns a sharedtypes.Service struct | ||
type serviceQuerier struct { | ||
clientConn grpc.ClientConn | ||
serviceQuerier servicetypes.QueryClient | ||
} | ||
|
||
// NewServiceQuerier returns a new instance of a client.ServiceQueryClient by | ||
// injecting the dependecies provided by the depinject.Config. | ||
// | ||
// Required dependencies: | ||
// - clientCtx (grpc.ClientConn) | ||
func NewServiceQuerier(deps depinject.Config) (client.ServiceQueryClient, error) { | ||
servq := &serviceQuerier{} | ||
|
||
if err := depinject.Inject( | ||
deps, | ||
&servq.clientConn, | ||
); err != nil { | ||
return nil, err | ||
} | ||
|
||
servq.serviceQuerier = servicetypes.NewQueryClient(servq.clientConn) | ||
|
||
return servq, nil | ||
} | ||
|
||
// GetService returns a sharedtypes.Service struct for a given serviceId. | ||
// It implements the ServiceQueryClient#GetService function. | ||
func (servq *serviceQuerier) GetService( | ||
ctx context.Context, | ||
serviceId string, | ||
) (sharedtypes.Service, error) { | ||
req := &servicetypes.QueryGetServiceRequest{ | ||
Id: serviceId, | ||
} | ||
|
||
res, err := servq.serviceQuerier.Service(ctx, req) | ||
if err != nil { | ||
return sharedtypes.Service{}, ErrQueryRetrieveService.Wrapf( | ||
"serviceId: %s; error: [%v]", | ||
serviceId, err, | ||
) | ||
} | ||
return res.Service, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/depinject" | ||
"github.com/cosmos/gogoproto/grpc" | ||
|
||
"github.com/pokt-network/poktroll/pkg/client" | ||
tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" | ||
) | ||
|
||
// tokenomicsQuerier is a wrapper around the tokenomicstypes.QueryClient that enables the | ||
// querying of on-chain tokenomics module data. | ||
type tokenomicsQuerier struct { | ||
clientConn grpc.ClientConn | ||
tokenomicsQuerier tokenomicstypes.QueryClient | ||
} | ||
|
||
// NewTokenomicsQuerier returns a new instance of a client.TokenomicsQueryClient by | ||
// injecting the dependecies provided by the depinject.Config. | ||
// | ||
// Required dependencies: | ||
// - grpc.ClientConn | ||
func NewTokenomicsQuerier(deps depinject.Config) (client.TokenomicsQueryClient, error) { | ||
querier := &tokenomicsQuerier{} | ||
|
||
if err := depinject.Inject( | ||
deps, | ||
&querier.clientConn, | ||
); err != nil { | ||
return nil, err | ||
} | ||
|
||
querier.tokenomicsQuerier = tokenomicstypes.NewQueryClient(querier.clientConn) | ||
|
||
return querier, nil | ||
} | ||
|
||
// GetServiceRelayDifficultyTargetHash queries the onchain data for | ||
// the relay mining difficulty associated with the given service. | ||
func (tq *tokenomicsQuerier) GetServiceRelayDifficultyTargetHash( | ||
ctx context.Context, | ||
serviceId string, | ||
) (client.TokenomicsRelayMiningDifficulty, error) { | ||
req := &tokenomicstypes.QueryGetRelayMiningDifficultyRequest{ | ||
ServiceId: serviceId, | ||
} | ||
|
||
res, err := tq.tokenomicsQuerier.RelayMiningDifficulty(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &res.RelayMiningDifficulty, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.