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!: Staking module validator set epoching #9043

Closed
wants to merge 126 commits into from

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Apr 1, 2021

Description

closes #8455

Remaining tasks TODO:

  • Fix staking CLI test
  • Improve docs/spec
  • Implement querying for things that are in the queue (e.g. if I check my account, it should search the queue), see step 2 of ADR
  • Implementing variable epoch pipeline legnth
  • Allow epochs to be time-based instead of height-based

super seeds #8829


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • 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
  • Review Codecov Report in the comment section below once CI passes

… EpochDelegate, add panic for unrecognized message
@github-actions github-actions bot added the T:Docs Changes and features related to documentation. label Apr 28, 2021
@tac0turtle
Copy link
Member Author

will work on updating this tomorrow.

@tac0turtle
Copy link
Member Author

Note: Add an event when the epoch number is incremented.

Copy link
Contributor

@JimLarson JimLarson left a comment

Choose a reason for hiding this comment

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

Here's an initial review. I'm still coming up to speed on the background here, so take everything with a grain of salt. I'm probably not aware of all the high-level invariants, so be aware of the depth of my review. One issue with the review is the clutter from all the coverage warnings makes certain sections painful to read. It might be worthwhile to add some trivial tests just so not to obscure important gaps in coverage or other warnings.

proto/cosmos/staking/v1beta1/staking.proto Show resolved Hide resolved
app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)

// NOTE: slashing module endblocker should run before staking module since MsgUnjail epoch action should run before making
// validator set update on staking module
Copy link
Contributor

Choose a reason for hiding this comment

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

Cross-reference to ExecuteEpoch() below, for consistency.


// ActionStoreKey returns action store key from ID
func ActionStoreKey(epochNumber int64, actionID uint64) []byte {
return []byte(fmt.Sprintf("%s_%d_%d", EpochActionQueuePrefix, epochNumber, actionID))
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider zero-padding the numbers so that contiguous numbers are stored contiguously, vs the order 1, 10, 100, 11, 12, .., 2, 20, 21, .... Helps with locality and pre-fectching during traversals.

store.Set(NextEpochActionID, sdk.Uint64ToBigEndian(actionID))
}

// GetNewActionID returns ID to be used for next epoch
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider incrementing the stored NextEpochActionID here and dispensing with SetNewActionID() above, otherwise this doesn't actually guarantee that it's a new action ID. Note that the staking keeper's GetNewActionID() misses the increment and will keep returning the same ID - incrementing here will prevent this error.


actionID := k.GetNewActionID(ctx)
store.Set(ActionStoreKey(epochNumber, actionID), bz)
k.SetNewActionID(ctx, actionID+1)
Copy link
Contributor

Choose a reason for hiding this comment

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

See above suggestion to put the increment in GetNewActionID(), here and below.

err := k.executeQueuedCreateValidatorMsg(cacheCtx, msg)
if err == nil {
writeCache()
} else if err = k.revertCreateValidatorMsg(ctx, msg); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Is it okay to not writeCache() in the successful revert case?
  2. Consider logging or telemetry for execution failure of the create validator message.

Same applies for other types below.

@@ -539,3 +587,304 @@ func queryAllRedelegations(store sdk.KVStore, k Querier, req *types.QueryRedeleg

return redels, res, err
}

func (k Querier) QueuedMsgCreateValidators(c context.Context, req *types.QueryQueuedMsgCreateValidatorsRequest) (*types.QueryQueuedMsgCreateValidatorsResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh, I'd be tempted to use reflection to consolidate similar cases rather than writing repeated boilerplate. On the other hand, reflection makes it easy to mess up, and the straightforward code is easier to analyze. Maybe I'm just reacting to all the code coverage warnings.


testCases := []struct {
msg string
malleate func()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining the need to wrap what looks like a simple struct literal in a func.

x/staking/keeper/msg_server.go Show resolved Hide resolved
x/staking/keeper/msg_server.go Outdated Show resolved Hide resolved
@amaury1093
Copy link
Contributor

@marbar3778 Could you fix the conflicts? I think we can merge this for 0.44

@tac0turtle
Copy link
Member Author

@marbar3778 Could you fix the conflicts? I think we can merge this for 0.44

yup, will handle this and fix the issues in sims

@orijbot
Copy link

orijbot commented Aug 13, 2021

@tac0turtle tac0turtle changed the title Staking module validator set epoching feat!: Staking module validator set epoching Aug 17, 2021
@tac0turtle tac0turtle mentioned this pull request Sep 13, 2021
19 tasks
@tac0turtle tac0turtle mentioned this pull request Sep 16, 2021
19 tasks
@tac0turtle
Copy link
Member Author

closing this as I am pulling out chunks from it

@tac0turtle tac0turtle closed this Sep 16, 2021
@julienrbrt julienrbrt deleted the staking_module_validator_set_epoching branch October 10, 2022 13:39
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.

staking: introduce epochs
7 participants