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

ADR 17 Implementation: Historical Module #5380

Merged
merged 31 commits into from
Dec 18, 2019
Merged

ADR 17 Implementation: Historical Module #5380

merged 31 commits into from
Dec 18, 2019

Conversation

AdityaSripal
Copy link
Member

@AdityaSripal AdityaSripal commented Dec 10, 2019

Implements historical module inside x/staking

Address #4647 via design in #5340


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Dec 10, 2019

Codecov Report

Merging #5380 into master will decrease coverage by 0.13%.
The diff coverage is 45.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5380      +/-   ##
=========================================
- Coverage   54.73%   54.6%   -0.14%     
=========================================
  Files         312     315       +3     
  Lines       18789   18919     +130     
=========================================
+ Hits        10285   10330      +45     
- Misses       7726    7808      +82     
- Partials      778     781       +3
Impacted Files Coverage Δ
x/staking/handler.go 84.3% <ø> (-2.34%) ⬇️
x/staking/keeper/val_state_change.go 67.92% <0%> (-15.8%) ⬇️
x/staking/types/keys.go 30.9% <0%> (-0.58%) ⬇️
x/staking/types/querier.go 0% <0%> (ø) ⬆️
x/staking/module.go 0% <0%> (ø) ⬆️
x/staking/client/cli/query.go 0% <0%> (ø) ⬆️
x/staking/keeper/params.go 100% <100%> (ø) ⬆️
x/staking/types/validator.go 63.77% <100%> (+1.42%) ⬆️
x/staking/types/params.go 15.66% <33.33%> (-0.34%) ⬇️
x/staking/abci.go 50% <50%> (ø)
... and 8 more

@fedekunze fedekunze added this to the IBC Implementation milestone Dec 10, 2019
@alexanderbez alexanderbez mentioned this pull request Dec 10, 2019
30 tasks
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

LGTM except that we won't handle the case of decreasing HistoricalEntries correctly

x/staking/abci.go Outdated Show resolved Hide resolved
x/staking/abci.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Performed an initial review. Great job @AdityaSripal. In addition to the review, let's be sure to

  1. Add any necessary type/var/const to alias.go -- I noticed this file wasn't modified and typically should on such a feature.
  2. Update the spec -- can be a simple section about what historical info is and how its persisted.

@@ -147,6 +147,9 @@ that allows for arbitrary vesting periods.
* `ValidateSigCountDecorator`: Validate the number of signatures in tx based on app-parameters.
* `IncrementSequenceDecorator`: Increments the account sequence for each signer to prevent replay attacks.
* (cli) [\#5223](https://github.com/cosmos/cosmos-sdk/issues/5223) Cosmos Ledger App v2.0.0 is now supported. The changes are backwards compatible and App v1.5.x is still supported.
* (x/staking) [\#5380](https://github.com/cosmos/cosmos-sdk/pull/5380) Introduced ability to store historical info entries in staking keeper, allows applications to introspect specified number of past headers and validator sets
Copy link
Contributor

Choose a reason for hiding this comment

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

A single changelog entry should be made with bullet points if need be.

// BeginBlocker will persist the current header and validator set as a historical entry
// and prune the oldest entry based on the HistoricalEntries parameter
func BeginBlocker(ctx sdk.Context, k Keeper) {
entryNum := k.HistoricalEntries(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Best to move this entire block into a method on the keeper.

  1. This keeps the BeginBlocker abstraction clean.
  2. Improves testability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Open to doing this here, but what i have follows the pattern of BeginBlockers in x/slashing, x/supply, and x/upgrade

Copy link
Contributor

Choose a reason for hiding this comment

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

They should be updated as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

What about the EndBlocker? Since that isn't a method on the keeper either?

x/staking/abci.go Outdated Show resolved Hide resolved
x/staking/abci.go Outdated Show resolved Hide resolved
x/staking/abci.go Outdated Show resolved Hide resolved
x/staking/abci.go Outdated Show resolved Hide resolved
x/staking/keeper/historical_info.go Outdated Show resolved Hide resolved
x/staking/types/historical_info.go Show resolved Hide resolved
x/staking/types/historical_info.go Outdated Show resolved Hide resolved
x/staking/types/keys.go Outdated Show resolved Hide resolved
@fedekunze
Copy link
Collaborator

@AdityaSripal mind resolving the conflicts?

}

// ValidateBasic will ensure HistoricalInfo is not nil and sorted
func ValidateBasic(hi HistoricalInfo) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't check if the header is empty

Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed too that this function is not used at all in this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, doesn't need to be used in the code since the historicalinfo created is correct-by-construction.

I use the method in the tests to check if NewHistoricalInfo works correctly, and to keep the method available for users of the staking module who might find it useful

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

ACK -- great job @AdityaSripal. I think BeginBlocker should have the logic moved to a method. I'll be happy to merge after that.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

ACK 🎉

@alexanderbez alexanderbez merged commit fca4cbe into master Dec 18, 2019
@alexanderbez alexanderbez deleted the aditya/history branch December 18, 2019 13:20
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.

5 participants