-
Notifications
You must be signed in to change notification settings - Fork 420
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
Streamline Stargate/gRPC querier interfaces #2093
Open
webmaster128
wants to merge
5
commits into
main
Choose a base branch
from
streamline-RejectStargateQuerier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4daa132
Change RejectStargateQuerier from factory function to free function
webmaster128 5a14616
Clarify error message to help contract developers
webmaster128 d256a5f
Streamline and improve documentation for RejectGrpcQuerier
webmaster128 7f313dc
Pull out function signatures
webmaster128 4d27351
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,13 +84,18 @@ | |
|
||
type CustomQuerier func(ctx sdk.Context, request json.RawMessage) ([]byte, error) | ||
|
||
type ( | ||
stargateQuerierFn func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) | ||
grpcQuerierFn func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) | ||
) | ||
|
||
type QueryPlugins struct { | ||
Bank func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error) | ||
Custom CustomQuerier | ||
IBC func(ctx sdk.Context, caller sdk.AccAddress, request *wasmvmtypes.IBCQuery) ([]byte, error) | ||
Staking func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) | ||
Stargate func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) | ||
Grpc func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) | ||
Stargate stargateQuerierFn | ||
Grpc grpcQuerierFn | ||
Wasm func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error) | ||
Distribution func(ctx sdk.Context, request *wasmvmtypes.DistributionQuery) ([]byte, error) | ||
} | ||
|
@@ -121,7 +126,7 @@ | |
Custom: NoCustomQuerier, | ||
IBC: IBCQuerier(wasm, channelKeeper), | ||
Staking: StakingQuerier(staking, distKeeper), | ||
Stargate: RejectStargateQuerier(), | ||
Stargate: RejectStargateQuerier, | ||
Grpc: RejectGrpcQuerier, | ||
Wasm: WasmQuerier(wasm), | ||
Distribution: DistributionQuerier(distKeeper), | ||
|
@@ -332,10 +337,15 @@ | |
} | ||
} | ||
|
||
// RejectGrpcQuerier is a querier that rejects all gRPC queries. | ||
// | ||
// Use AcceptListGrpcQuerier instead to create a list of accepted query types. | ||
func RejectGrpcQuerier(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) { | ||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "gRPC queries are disabled"} | ||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "gRPC queries are disabled on this chain"} | ||
} | ||
|
||
var _ grpcQuerierFn = RejectGrpcQuerier // just a type check | ||
|
||
// AcceptListGrpcQuerier supports a preconfigured set of gRPC queries only. | ||
// All arguments must be non nil. | ||
// | ||
|
@@ -344,7 +354,7 @@ | |
// | ||
// These queries can be set via WithQueryPlugins option in the wasm keeper constructor: | ||
// WithQueryPlugins(&QueryPlugins{Grpc: AcceptListGrpcQuerier(acceptList, queryRouter, codec)}) | ||
func AcceptListGrpcQuerier(acceptList AcceptedQueries, queryRouter GRPCQueryRouter, codec codec.Codec) func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) { | ||
func AcceptListGrpcQuerier(acceptList AcceptedQueries, queryRouter GRPCQueryRouter, codec codec.Codec) grpcQuerierFn { | ||
return func(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (proto.Message, error) { | ||
protoResponseFn, accepted := acceptList[request.Path] | ||
if !accepted { | ||
|
@@ -375,13 +385,15 @@ | |
} | ||
} | ||
|
||
// RejectStargateQuerier rejects all stargate queries | ||
func RejectStargateQuerier() func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { | ||
return func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { | ||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "Stargate queries are disabled"} | ||
} | ||
// RejectStargateQuerier is a querier that rejects all stargate queries. | ||
// | ||
// Use AcceptListStargateQuerier instead to create a list of accepted query types. | ||
func RejectStargateQuerier(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { | ||
return nil, wasmvmtypes.UnsupportedRequest{Kind: "Stargate queries are disabled on this chain"} | ||
} | ||
|
||
var _ stargateQuerierFn = RejectStargateQuerier // just a type check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
|
||
// AcceptedQueries defines accepted Stargate or gRPC queries as a map where the key is the query path | ||
// and the value is a function returning a proto.Message. | ||
// | ||
|
@@ -400,7 +412,7 @@ | |
// | ||
// These queries can be set via WithQueryPlugins option in the wasm keeper constructor: | ||
// WithQueryPlugins(&QueryPlugins{Stargate: AcceptListStargateQuerier(acceptList, queryRouter, codec)}) | ||
func AcceptListStargateQuerier(acceptList AcceptedQueries, queryRouter GRPCQueryRouter, codec codec.Codec) func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { | ||
func AcceptListStargateQuerier(acceptList AcceptedQueries, queryRouter GRPCQueryRouter, codec codec.Codec) stargateQuerierFn { | ||
return func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { | ||
protoResponseFn, accepted := acceptList[request.Path] | ||
if !accepted { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is breaking since it changes the signature of a public function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's breaking. I would assume that most people don't use the RejectStargateQuerier directly, since it's the default anyways, but not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github only finds copies, no usage: https://github.com/search?q=RejectStargateQuerier&type=code
So probably a good change to include in 0.55