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

feat(gov): app-wiring for x/gov #12369

Merged
merged 19 commits into from
Jul 4, 2022
Merged

feat(gov): app-wiring for x/gov #12369

merged 19 commits into from
Jul 4, 2022

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Jun 27, 2022

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions github-actions bot added C:x/distribution distribution module related C:x/gov labels Jun 27, 2022
x/gov/module.go Fixed Show fixed Hide fixed
Copy link
Member

@aaronc aaronc left a 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?

@kocubinski kocubinski force-pushed the kocubinski/gov-app-wiring branch from 166bcda to 5255833 Compare June 28, 2022 14:39
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
io "io"
reflect "reflect"

Check notice

Code scanning / CodeQL

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type RoutedHandler struct {
type HandlerRoute struct {

@julienrbrt julienrbrt changed the base branch from main to epic/app-wiring June 29, 2022 13:39
@julienrbrt julienrbrt changed the base branch from epic/app-wiring to main June 29, 2022 15:52
- post construction mutation is required to overcome circular dependencies
@kocubinski kocubinski changed the title feat(gov): app-wiring in gov WIP feat(gov): app-wiring for x/gov Jun 30, 2022
@@ -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)
Copy link
Member Author

@kocubinski kocubinski Jun 30, 2022

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())
Copy link
Member Author

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

Copy link
Member

@julienrbrt julienrbrt Jun 30, 2022

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{
Copy link
Member Author

@kocubinski kocubinski Jun 30, 2022

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.

x/params/module.go Outdated Show resolved Hide resolved
@kocubinski kocubinski marked this pull request as ready for review June 30, 2022 15:32
@kocubinski kocubinski requested a review from a team as a code owner June 30, 2022 15:32
simapp/app.go Outdated
@@ -422,5 +388,4 @@ func GetMaccPerms() map[string][]string {

// initParamsKeeper init params keeper and its subspaces
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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() {}
Copy link
Member

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

Copy link
Member Author

@kocubinski kocubinski Jun 30, 2022

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))

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@codecov
Copy link

codecov bot commented Jul 4, 2022

Codecov Report

Merging #12369 (e4bd03c) into main (74f265c) will increase coverage by 0.32%.
The diff coverage is 88.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
x/gov/types/expected_keepers.go 0.00% <0.00%> (ø)
x/gov/types/v1beta1/content.go 0.00% <0.00%> (ø)
x/params/types/table.go 97.72% <0.00%> (-2.28%) ⬇️
x/params/module.go 57.14% <72.72%> (ø)
depinject/container.go 90.49% <100.00%> (ø)
simapp/app.go 69.01% <100.00%> (-5.99%) ⬇️
x/distribution/module.go 56.66% <100.00%> (+0.48%) ⬆️
x/gov/abci.go 90.38% <100.00%> (ø)
x/gov/genesis.go 87.50% <100.00%> (ø)
x/gov/keeper/grpc_query.go 76.56% <100.00%> (ø)
... and 29 more

@julienrbrt julienrbrt merged commit 61dc023 into main Jul 4, 2022
@julienrbrt julienrbrt deleted the kocubinski/gov-app-wiring branch July 4, 2022 12:58
@julienrbrt julienrbrt mentioned this pull request Jul 4, 2022
1 task
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants