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: migrate x/staking to app wiring #12102

Merged
merged 26 commits into from
Jun 3, 2022

Conversation

JeancarloBarrios
Copy link
Contributor

@JeancarloBarrios JeancarloBarrios commented May 31, 2022

Description

Migrate x/staking to the new app wiring (dependency injection).

Tracking progress at #12036


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)

x/staking/module.go Outdated Show resolved Hide resolved
x/bank/module.go Outdated Show resolved Hide resolved
@blushi blushi mentioned this pull request Jun 2, 2022
19 tasks
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
Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

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

is this R4R?

proto/cosmos/staking/module/v1/module.proto Outdated Show resolved Hide resolved
x/staking/module.go Outdated Show resolved Hide resolved
Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
@JeancarloBarrios
Copy link
Contributor Author

R4R

I still have this test regarding the distribution module for delegation I'm getting the error no delegation distribution info

@@ -63,14 +63,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// Set the validator hooks
func (k *Keeper) SetHooks(sh types.StakingHooks) *Keeper {
Copy link
Member

@kocubinski kocubinski Jun 2, 2022

Choose a reason for hiding this comment

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

This pattern makes little sense to me given the name SetHooks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add an API-breaking changelog entry, iirc Osmosis is using SetHooks pretty heavily

@@ -47,7 +47,7 @@ func NewKeeper(
panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName))
}

return Keeper{
Copy link
Member

@kocubinski kocubinski Jun 2, 2022

Choose a reason for hiding this comment

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

Fundamentally this change is required so that when InitGenesis iterates over the ModuleManager the StakingKeeper which is retrieved (by reference) is the same area of memory which the post construction SetHooks mutation modifies.

This is the reason for now passing the Keeper around everywhere by reference.

Not a huge fan of this, but it seems it will be up for refactor when we get to x/distribution and x/slashing, or possibly sooner. Those modules can provide their StakingHooks for this module to order as BaseAppOptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@JeancarloBarrios
Copy link
Contributor Author

@aaronc, @kocubinski found a memory bug regarding the staking keeper. Given that the new mechanism was initialized before the hooks are added to it, it will initialize with hooks on nil. @kocubinski solution is in the comment above. I was wondering if you could give it a look and give us your opinion about it.

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.

LGTM

@github-actions github-actions bot added C:Simulations C:x/distribution distribution module related labels Jun 2, 2022
…_use_app_wiring' into JeancarloBarrios/migrate_staking_use_app_wiring
@JeancarloBarrios JeancarloBarrios marked this pull request as ready for review June 2, 2022 23:45
@JeancarloBarrios JeancarloBarrios requested a review from a team as a code owner June 2, 2022 23:45
@codecov
Copy link

codecov bot commented Jun 2, 2022

Codecov Report

Merging #12102 (d8903e2) into main (fe5c22e) will increase coverage by 0.00%.
The diff coverage is 94.28%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12102   +/-   ##
=======================================
  Coverage   66.00%   66.00%           
=======================================
  Files         671      671           
  Lines       71006    71011    +5     
=======================================
+ Hits        46866    46872    +6     
+ Misses      21478    21477    -1     
  Partials     2662     2662           
Impacted Files Coverage Δ
simapp/export.go 11.76% <0.00%> (ø)
x/distribution/module.go 62.85% <ø> (ø)
x/staking/genesis.go 46.15% <0.00%> (ø)
x/staking/keeper/grpc_query.go 58.95% <ø> (ø)
x/staking/keeper/invariants.go 62.40% <83.33%> (ø)
x/staking/module.go 70.58% <93.75%> (+5.79%) ⬆️
simapp/app.go 78.23% <100.00%> (-0.51%) ⬇️
x/bank/module.go 63.91% <100.00%> (ø)
x/distribution/simulation/operations.go 80.21% <100.00%> (ø)
x/slashing/module.go 61.42% <100.00%> (ø)
... and 8 more

@blushi blushi added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 3, 2022
@mergify mergify bot merged commit 90d6745 into main Jun 3, 2022
@mergify mergify bot deleted the JeancarloBarrios/migrate_staking_use_app_wiring branch June 3, 2022 08:10
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

🎉

@JeancarloBarrios could you create a quick follow-up to add changelog entries?

@@ -63,14 +63,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// Set the validator hooks
func (k *Keeper) SetHooks(sh types.StakingHooks) *Keeper {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add an API-breaking changelog entry, iirc Osmosis is using SetHooks pretty heavily

@@ -47,7 +47,7 @@ func NewKeeper(
panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName))
}

return Keeper{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
## Description
Migrate x/staking to the new app wiring (dependency injection).

Tracking progress at cosmos#12036

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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...

- [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Simulations C:x/bank C:x/distribution distribution module related C:x/slashing C:x/staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants