-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Environment in context #19640
Comments
I'm in favor of solution (1) here, I think it's an appropriate use of
This is request (and module) scope data required for state machine execution that transits APIs. I prefer scoping to module since it will force us to be more careful with this pattern and it should be an exception to normal flow not the rule. |
Unfortunately, this wasn't possible, as we had to make the module defining an authz grant or a feegrant import x/authz or x/feegrant for the context key. As we want to avoid unnecessary deps, we have made a singel |
With the migration of cosmos sdk modules to be compatible with server/v2, modules must not use
sdk.UnwrapSDKContext
.The environment provides everything a module needs.
The goal is to keep cosmos sdk modules compatible with baseapp and server/v2, with the minimum api break possible.
However, there are a few places where the SDK context is still required, and it cannot be easily refactored by taking an environment due to the api/interface breakage this would bring.
x/feegrant
feegrant.FeeAllowanceI
Accept method takes only asdk.Context
:cosmos-sdk/x/feegrant/basic_fee.go
Lines 25 to 26 in 3e63309
x/authz
Like feegrant, authz Accept method takes only a
sdk.Context
:cosmos-sdk/x/authz/keeper/keeper.go
Line 126 in 3e63309
x/gov legacy proposals
x/gov v1beta1 proposals handler takes only a
sdk.Context
:cosmos-sdk/x/gov/types/v1beta1/content.go
Line 20 in 3e63309
Ante Handlers
Lastly, some ante handlers, such as
TxFeeChecker
, need access to services provided by the environment:cosmos-sdk/x/auth/ante/fee.go
Lines 14 to 16 in 3e63309
Solutions
A few solutions have been discussed, but consensus haven't been reached.
One solution is to have those modules set their environment in context before passing it to those methods.
We could make the caller aware that it is a module-specific context by having a module-scope context key:
FeeGrantEnvContextKey
,AuthzEnvConextKey
,GovEnvContextKey
.Drawback: The module developer needs then to be aware of which module calls the method and unwrap the right context.
The module implementing those methods has no access to their environment.
A second proposal is to store a subset of
appmodule.Environment
containing non module-scoped servicesDrawback: It adds a new notion differing from the environment, and may not be compatible with gov v1beta1 proposal handler usage (needs to be checked on sourcegraph.com).
The third proposal is to add environment in the interfaces
Drawback: It breaks everyone, and still has the same drawbacks as 1.
We are as well thinking of deprecating gov v1beta1 proposals totally or only for server/v2 if none of the solution above is a right fit.
The text was updated successfully, but these errors were encountered: