-
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
feat(gov): app-wiring for x/gov #12369
Conversation
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.
That’s the right idea. ManyPerContainer is probably more appropriate. We should think of a better name than RouteHandlerWrapper. Can we define the interface method directly on the Handler type?
166bcda
to
5255833
Compare
x/gov/types/v1beta1/content.go
Outdated
@@ -18,3 +18,11 @@ type Content interface { | |||
// Handler defines a function that handles a proposal after it has passed the | |||
// governance process. | |||
type Handler func(ctx sdk.Context, content Content) error | |||
|
|||
type RoutedHandler struct { |
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.
type RoutedHandler struct { | |
type HandlerRoute struct { |
- post construction mutation is required to overcome circular dependencies
@@ -95,8 +95,6 @@ func (c *container) call(provider *ProviderDescriptor, moduleKey *moduleKey) ([] | |||
} | |||
|
|||
func (c *container) getResolver(typ reflect.Type, key *moduleKey) (resolver, error) { | |||
c.logf("Resolving %v", typ) |
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 accidentally merged this debug code at some point, it makes error messages needlessly verbose and long. Sorry about that.
@@ -417,7 +415,7 @@ func (c *container) resolve(in ProviderInput, moduleKey *moduleKey, caller Locat | |||
|
|||
markGraphNodeAsFailed(typeGraphNode) | |||
return reflect.Value{}, errors.Errorf("can't resolve type %v for %s:\n%s", | |||
in.Type, caller, c.formatResolveStack()) | |||
fullyQualifiedTypeName(in.Type), caller, c.formatResolveStack()) |
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.
A much improved error message will result, e.g.
Failed to locate provider for github.com/cosmos/cosmos-sdk/x/gov/keeper/*keeper.Keeper
vs
Failed to locate provider *keeper.Keeper
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!
legacyRouter: legacyRouter, | ||
router: router, | ||
config: config, | ||
return &Keeper{ |
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.
The gov keeper constructor must return a pointer to Keeper
since we're setting hooks and routes in a post-construction step.
simapp/app.go
Outdated
@@ -422,5 +388,4 @@ func GetMaccPerms() map[string][]string { | |||
|
|||
// initParamsKeeper init params keeper and its subspaces |
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.
Can this be removed?
x/gov/module.go
Outdated
return runtime.WrapAppModuleBasic(AppModuleBasic{}) | ||
} | ||
|
||
func provideModule( |
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.
For consistency I'd think we should use a struct named govInputs
and govOutputs
.
@@ -55,34 +55,27 @@ type Keeper struct { | |||
func NewKeeper( |
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 think this requires a changelog
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.
100% this is api breaking
simapp/app.go
Outdated
@@ -236,41 +232,11 @@ func NewSimApp( | |||
|
|||
initParamsKeeper(app.ParamsKeeper) |
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 think this can be removed
type GovHooksWrapper struct{ GovHooks } | ||
|
||
// IsOnePerModuleType implements the depinject.OnePerModuleType interface. | ||
func (GovHooksWrapper) IsOnePerModuleType() {} |
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.
out of scope but what is IsOnePerModule
I don't find this intuitive, could be missing something
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.
Implementing depinject.OnePerModuleType is an instruction for depinject
, the IoC container will create one instance of GovHooksWrapper
per module and collect them into a map[string]GovHooksWrapper
as input to a provider further down the graph.
I kind of agree how this is not intuitive and could seem like spooky action at a distance. An alternative is to configure this behavior in the composition root.
depinject.ProvideOncePerModule(new(govkeeper.GovHooksWrapper))
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.
lgtm!
Codecov Report
@@ Coverage Diff @@
## main #12369 +/- ##
==========================================
+ Coverage 65.71% 66.04% +0.32%
==========================================
Files 680 692 +12
Lines 71733 72603 +870
==========================================
+ Hits 47142 47948 +806
- Misses 21943 21986 +43
- Partials 2648 2669 +21
|
Description
Ref: #12274
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change