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

[Relay Mining] Use per-service difficulty in the relayer #745

Merged
merged 40 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a604ee5
Check the number of claimed compute units against the service
adshmh Aug 13, 2024
faf83af
RelayMiner uses service ComputeUnitsPerRelay when adding relays to SMT
adshmh Aug 19, 2024
3debe2c
RelayMiner uses the tokenomic modules difficulty target for a service…
adshmh Aug 19, 2024
9c55ea7
Merge remote-tracking branch 'origin/main' into feat-relay-mining-dif…
adshmh Aug 19, 2024
7240a68
Change to use supplier OperatorAddress field name
adshmh Aug 19, 2024
f04df4e
Update pkg/relayer/miner/gen/gen_fixtures.go
adshmh Aug 22, 2024
66a371b
Update pkg/relayer/miner/gen/gen_fixtures.go
adshmh Aug 22, 2024
8376f09
Update pkg/relayer/miner/miner.go
adshmh Aug 22, 2024
ec6d613
Update pkg/relayer/miner/gen/template.go
adshmh Aug 22, 2024
7ed02d7
Apply suggestions from code review
adshmh Aug 22, 2024
1460021
Apply suggestions from code review
adshmh Aug 22, 2024
ad4b828
Apply suggestions from code review
adshmh Aug 22, 2024
0c8e38d
Update testutil/testclient/testqueryclients/servicequerier.go
adshmh Aug 22, 2024
20fe4e4
Update x/proof/keeper/msg_server_create_claim.go
adshmh Aug 22, 2024
ea07f50
Update x/proof/keeper/msg_server_create_claim_test.go
adshmh Aug 22, 2024
3edb218
Update x/proof/keeper/service.go
adshmh Aug 22, 2024
3a94474
address review comments on relay fixture generation
adshmh Aug 26, 2024
dbfe604
address review comments
adshmh Aug 26, 2024
8de0752
address review comment on sentinel errors
adshmh Aug 26, 2024
6e195a9
address review comment on GetServiceRelayDifficultyTargetHash
adshmh Aug 26, 2024
7bdcf15
Apply suggestions from code review
adshmh Aug 27, 2024
d0b66fa
address review comment: re-generate test fixtures
adshmh Aug 28, 2024
b5bfcff
Add a compile check target for miner fixtures generator
adshmh Aug 28, 2024
78f7229
Merge remote-tracking branch 'origin/feat-relay-mining-difficulty-per…
adshmh Aug 28, 2024
c220a82
Fix linter warning
adshmh Aug 28, 2024
3e56c16
Update pkg/relayer/session/session.go
adshmh Aug 29, 2024
d0e3984
Update pkg/deps/config/suppliers.go
adshmh Aug 29, 2024
f6b931b
Update pkg/relayer/session/session_test.go
adshmh Aug 29, 2024
5cda533
Update x/proof/keeper/msg_server_create_claim.go
adshmh Aug 29, 2024
5fc003b
Update x/proof/keeper/msg_server_create_claim_test.go
adshmh Sep 3, 2024
35f43a9
Update x/proof/keeper/msg_server_create_claim_test.go
adshmh Sep 3, 2024
2eea703
Update x/proof/keeper/msg_server_create_claim_test.go
adshmh Sep 3, 2024
5c76ec4
Update x/proof/keeper/msg_server_create_claim.go
adshmh Sep 3, 2024
6cdb0c6
address review comment on testqueryclients
adshmh Sep 3, 2024
81f51c5
Merge remote-tracking branch 'origin/main' into feat-relay-mining-dif…
adshmh Sep 3, 2024
e8af163
Empty commit
adshmh Sep 3, 2024
ec98f2d
fix linter warning
adshmh Sep 3, 2024
28d0c09
fix linter warning
adshmh Sep 3, 2024
2efeaa9
Merge branch 'main' into feat-relay-mining-difficulty-per-service
Olshansk Sep 4, 2024
9ccb738
Use the default relay difficulty if none is found for the service
adshmh Sep 4, 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
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ test_verbose: check_go_version ## Run all go tests verbosely
# It is not compatible with `-race`, which is why it's omitted here.
# See ref for more details: https://github.com/golang/go/issues/54482#issuecomment-1251124908
.PHONY: test_all
test_all: warn_flaky_tests check_go_version ## Run all go tests showing detailed output only on failures
test_all: warn_flaky_tests check_go_version test_gen_fixtures ## Run all go tests showing detailed output only on failures
go test -count=1 -buildmode=pie -tags test ./...

.PHONY: test_all_with_integration
Expand All @@ -451,6 +451,14 @@ test_integration: check_go_version ## Run only the in-memory integration "unit"
itest: check_go_version ## Run tests iteratively (see usage for more)
./tools/scripts/itest.sh $(filter-out $@,$(MAKECMDGOALS))

# Verify there are no compile errors in pkg/relayer/miner/gen directory.
adshmh marked this conversation as resolved.
Show resolved Hide resolved
# This is done by overriding the build tags through passing a `*.go` argument to `go test`.
# .go files in that directory contain a `go:build ignore` directive to avoid introducing
# unintentional churn in the randomly generated fixtures.
.PHONY: test_gen_fixtures
test_gen_fixtures: check_go_version ## Run all go tests verbosely
go test -count=1 -v -race ./pkg/relayer/miner/gen/*.go
adshmh marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: go_mockgen
go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
find . -name "*_mock.go" | xargs --no-run-if-empty rm
Expand Down
20 changes: 19 additions & 1 deletion pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//go:generate mockgen -destination=../../testutil/mockclient/session_query_client_mock.go -package=mockclient . SessionQueryClient
//go:generate mockgen -destination=../../testutil/mockclient/shared_query_client_mock.go -package=mockclient . SharedQueryClient
//go:generate mockgen -destination=../../testutil/mockclient/proof_query_client_mock.go -package=mockclient . ProofQueryClient
//go:generate mockgen -destination=../../testutil/mockclient/tokenomics_query_client_mock.go -package=mockclient . TokenomicsQueryClient
//go:generate mockgen -destination=../../testutil/mockclient/service_query_client_mock.go -package=mockclient . ServiceQueryClient
//go:generate mockgen -destination=../../testutil/mockclient/cosmos_tx_builder_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client TxBuilder
//go:generate mockgen -destination=../../testutil/mockclient/cosmos_keyring_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/crypto/keyring Keyring
//go:generate mockgen -destination=../../testutil/mockclient/cosmos_client_mock.go -package=mockclient github.com/cosmos/cosmos-sdk/client AccountRetriever
Expand Down Expand Up @@ -335,7 +337,6 @@ type BlockQueryClient interface {
// protobuf message. Since the generated go types don't include interface types, this
// is necessary to prevent dependency cycles.
type ProofParams interface {
GetRelayDifficultyTargetHash() []byte
GetProofRequestProbability() float32
GetProofRequirementThreshold() uint64
GetProofMissingPenalty() *cosmostypes.Coin
Expand All @@ -347,3 +348,20 @@ type ProofQueryClient interface {
// GetParams queries the chain for the current shared module parameters.
GetParams(ctx context.Context) (ProofParams, error)
}

// TokenomicsRelayMiningDifficulty is a go interface type which corresponding to the poktroll.tokenomics.RelayMiningDifficulty
// protobuf message. This is necessary to prevent dependency cycles.
type TokenomicsRelayMiningDifficulty interface {
GetTargetHash() []byte
}

type TokenomicsQueryClient interface {
GetServiceRelayDifficultyTargetHash(ctx context.Context, serviceId string) (TokenomicsRelayMiningDifficulty, error)
}

// ServiceQueryClient defines an interface that enables the querying of the
// on-chain service information
type ServiceQueryClient interface {
// GetService queries the chain for the details of the service provided
GetService(ctx context.Context, serviceId string) (sharedtypes.Service, error)
}
1 change: 1 addition & 0 deletions pkg/client/query/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ var (
ErrQueryRetrieveSession = sdkerrors.Register(codespace, 3, "error while trying to retrieve a session")
ErrQueryPubKeyNotFound = sdkerrors.Register(codespace, 4, "account pub key not found")
ErrQuerySessionParams = sdkerrors.Register(codespace, 5, "unable to query session params")
ErrQueryRetrieveService = sdkerrors.Register(codespace, 6, "error while trying to retrieve a service")
)
62 changes: 62 additions & 0 deletions pkg/client/query/servicequerier.go
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
}
55 changes: 55 additions & 0 deletions pkg/client/query/tokenomicsquerier.go
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
}
33 changes: 33 additions & 0 deletions pkg/deps/config/suppliers.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,39 @@ func NewSupplyProofQueryClientFn() SupplierFn {
}
}

// NewSupplyTokenomicsQueryClientFn returns a function which constructs a
// TokenomicsQueryClient instance and returns a new depinject.Config which
// is supplied with the given deps and the new TokenomicsQueryClient.
func NewSupplyTokenomicsQueryClientFn() SupplierFn {
return func(
_ context.Context,
deps depinject.Config,
_ *cobra.Command,
) (depinject.Config, error) {
tokenomicsQuerier, err := query.NewTokenomicsQuerier(deps)
if err != nil {
return nil, err
}

return depinject.Configs(deps, depinject.Supply(tokenomicsQuerier)), nil
}
}

adshmh marked this conversation as resolved.
Show resolved Hide resolved
func NewSupplyServiceQueryClientFn() SupplierFn {
return func(
_ context.Context,
deps depinject.Config,
_ *cobra.Command,
) (depinject.Config, error) {
serviceQuerier, err := query.NewServiceQuerier(deps)
if err != nil {
return nil, err
}

return depinject.Configs(deps, depinject.Supply(serviceQuerier)), nil
}
}

// newSupplyTxClientFn returns a new depinject.Config which is supplied with
// the given deps and the new TxClient.
func newSupplyTxClientsFn(ctx context.Context, deps depinject.Config, signingKeyName string) (depinject.Config, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/relayer/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ func setupRelayerDependencies(
config.NewSupplyTxClientContextFn(queryNodeGRPCUrl, txNodeRPCUrl), // leaf
config.NewSupplyDelegationClientFn(), // leaf
config.NewSupplySharedQueryClientFn(), // leaf
config.NewSupplyProofQueryClientFn(),
config.NewSupplyTokenomicsQueryClientFn(),
supplyMiner,
config.NewSupplyAccountQuerierFn(),
config.NewSupplyApplicationQuerierFn(),
config.NewSupplySupplierQuerierFn(),
config.NewSupplySessionQuerierFn(),
config.NewSupplyServiceQueryClientFn(),
config.NewSupplyRingCacheFn(),
supplyTxFactory,
supplyTxContext,
Expand Down
Loading
Loading