diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 2eb7e2592..614b8a460 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -336,6 +336,8 @@ 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 { + cosmostypes.Msg + GetProofRequestProbability() float64 GetProofRequirementThreshold() *cosmostypes.Coin GetProofMissingPenalty() *cosmostypes.Coin @@ -345,8 +347,7 @@ type ProofParams interface { // ProofQueryClient defines an interface that enables the querying of the // on-chain proof module params. type ProofQueryClient interface { - // GetParams queries the chain for the current shared module parameters. - GetParams(ctx context.Context) (ProofParams, error) + ParamsQuerier[ProofParams] } // ServiceQueryClient defines an interface that enables the querying of the diff --git a/pkg/client/query/proofquerier.go b/pkg/client/query/proofquerier.go index 30c2984cd..dd4a2218e 100644 --- a/pkg/client/query/proofquerier.go +++ b/pkg/client/query/proofquerier.go @@ -1,8 +1,6 @@ package query import ( - "context" - "cosmossdk.io/depinject" "github.com/cosmos/gogoproto/grpc" @@ -10,9 +8,17 @@ import ( prooftypes "github.com/pokt-network/poktroll/x/proof/types" ) +// TODO_IN_THIS_COMMIT: comment explaining why we can't use client.ProofQueryClient; +// tl;dr, it defines ian interface for ProofParams to avoid a dependency cycle +// (i.e. instead of importing prooftypes). +var _ client.ProofQueryClient = (*proofQuerier)(nil) + // proofQuerier is a wrapper around the prooftypes.QueryClient that enables the // querying of on-chain proof module params. type proofQuerier struct { + //client.ParamsQuerier[*prooftypes.Params] + client.ParamsQuerier[client.ProofParams] + clientConn grpc.ClientConn proofQuerier prooftypes.QueryClient } @@ -22,10 +28,33 @@ type proofQuerier struct { // // Required dependencies: // - grpc.ClientConn -func NewProofQuerier(deps depinject.Config) (client.ProofQueryClient, error) { - querier := &proofQuerier{} +func NewProofQuerier( + deps depinject.Config, + paramsQuerierOpts ...ParamsQuerierOptionFn, + // TODO_IN_THIS_COMMIT: comment explaining why we can't use client.ProofQueryClient; + // tl;dr, it defines ian interface for ProofParams to avoid a dependency cycle + // (i.e. instead of importing prooftypes). + // ) (paramsQuerierIface[*prooftypes.Params], error) { +) (paramsQuerierIface[client.ProofParams], error) { + paramsQuerierCfg := DefaultParamsQuerierConfig() + for _, opt := range paramsQuerierOpts { + opt(paramsQuerierCfg) + } + + paramsQuerier, err := NewCachedParamsQuerier[client.ProofParams, prooftypes.ProofQueryClient]( + deps, prooftypes.NewProofQueryClient, + WithModuleInfo[*prooftypes.Params](prooftypes.ModuleName, prooftypes.ErrProofParamInvalid), + WithParamsCacheOptions(paramsQuerierCfg.CacheOpts...), + ) + if err != nil { + return nil, err + } - if err := depinject.Inject( + querier := &proofQuerier{ + ParamsQuerier: paramsQuerier, + } + + if err = depinject.Inject( deps, &querier.clientConn, ); err != nil { @@ -36,15 +65,3 @@ func NewProofQuerier(deps depinject.Config) (client.ProofQueryClient, error) { return querier, nil } - -// GetParams queries the chain for the current proof module parameters. -func (pq *proofQuerier) GetParams( - ctx context.Context, -) (client.ProofParams, error) { - req := &prooftypes.QueryParamsRequest{} - res, err := pq.proofQuerier.Params(ctx, req) - if err != nil { - return nil, err - } - return &res.Params, nil -} diff --git a/x/proof/types/expected_keepers.go b/x/proof/types/expected_keepers.go index 9d1fd765e..22bfc9522 100644 --- a/x/proof/types/expected_keepers.go +++ b/x/proof/types/expected_keepers.go @@ -49,6 +49,7 @@ type ApplicationKeeper interface { GetApplication(ctx context.Context, address string) (app apptypes.Application, found bool) GetAllApplications(ctx context.Context) []apptypes.Application SetApplication(context.Context, apptypes.Application) + GetParams(ctx context.Context) apptypes.Params } // SharedKeeper defines the expected interface needed to retrieve shared information. diff --git a/x/proof/types/query_client.go b/x/proof/types/query_client.go new file mode 100644 index 000000000..de5e5e3b4 --- /dev/null +++ b/x/proof/types/query_client.go @@ -0,0 +1,33 @@ +package types + +import ( + "context" + + gogogrpc "github.com/cosmos/gogoproto/grpc" + + "github.com/pokt-network/poktroll/pkg/client" +) + +// TODO_IN_THIS_COMMIT: godoc... +type ProofQueryClient interface { + QueryClient + + GetParams(context.Context) (client.ProofParams, error) +} + +// TODO_IN_THIS_COMMIT: godoc... +func NewProofQueryClient(conn gogogrpc.ClientConn) ProofQueryClient { + return NewQueryClient(conn).(ProofQueryClient) +} + +// TODO_IN_THIS_COMMIT: investigate generalization... +// TODO_IN_THIS_COMMIT: godoc... +func (c *queryClient) GetParams(ctx context.Context) (client.ProofParams, error) { + res, err := c.Params(ctx, &QueryParamsRequest{}) + if err != nil { + return nil, err + } + + params := res.GetParams() + return ¶ms, nil +}