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: restaking module keeper and msg server #31

Merged
merged 37 commits into from
Jul 4, 2024

Conversation

RiccardoM
Copy link
Contributor

@RiccardoM RiccardoM commented Jun 18, 2024

Description

This PR implements the write operations of the x/restaking module. In particular, it contains the Keeper and MsgServer methods to execute the various restaking-related messages.

All queries and read operations are not present inside this PR, neither are the module registration inside the App, nor clients implementations. All of this will be implemented with other PRs in the future. This guarantees that the files changed here are less and easier to review.


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)

@RiccardoM RiccardoM force-pushed the riccardom/restaking-module branch from df6ef4b to 60b17a6 Compare July 1, 2024 14:59
@RiccardoM RiccardoM requested a review from hallazzang July 1, 2024 20:18
@RiccardoM RiccardoM marked this pull request as ready for review July 1, 2024 20:18
@RiccardoM RiccardoM changed the title feat: restaking module feat: restaking module keeper and msg server Jul 1, 2024
@RiccardoM RiccardoM requested review from manu0466 and rustcandy July 1, 2024 20:41
Copy link
Contributor

@hallazzang hallazzang left a comment

Choose a reason for hiding this comment

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

Overall looks good. Just have some change requests.

proto/milkyway/restaking/v1/messages.proto Outdated Show resolved Hide resolved
x/restaking/keeper/alias_functions.go Outdated Show resolved Hide resolved
x/restaking/keeper/alias_functions.go Outdated Show resolved Hide resolved
x/restaking/keeper/pool_restaking.go Outdated Show resolved Hide resolved
x/restaking/types/events.go Outdated Show resolved Hide resolved
x/restaking/keeper/msg_server.go Show resolved Hide resolved
x/restaking/types/keys.go Show resolved Hide resolved
@hallazzang
Copy link
Contributor

hallazzang commented Jul 2, 2024

Also, can't we just use one Delegation struct and have different type field(pool, service, operator)?

Copy link

@rustcandy rustcandy left a comment

Choose a reason for hiding this comment

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

Minor suggestions :)

// GetAllPoolDelegations returns all the pool delegations
func (k *Keeper) GetAllPoolDelegations(ctx sdk.Context) []types.PoolDelegation {
var delegations []types.PoolDelegation
k.IterateAllPoolDelegations(ctx, func(delegation types.PoolDelegation) bool {

Choose a reason for hiding this comment

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

Looks like this could be implemented with the same way below(GetAllDelegatorPoolDelegations) instead of calling callback and always returning false.

Comment on lines 69 to 73
if err != nil {
return newShares, err
}

return newShares, nil

Choose a reason for hiding this comment

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

Suggested change
if err != nil {
return newShares, err
}
return newShares, nil
return newShares, err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just a personal preference, but I like best returning the error explicitly inside an if instead of using the last return statement.

This because if we want, we could also write

return newShares, hooks.AfterDelegationModified(ctx, receiver.GetID(), delegator)

And it would be the same. But this makes it harder to read the code in my opinion. Then we might have the question: how far should we go in choosing between "less code as possible" vs "more code to be more readable"?

In this fight I always choose "more code but easier to read", just to be consistent. This is why I always prefer things like

if err != nil {
  return nil, err
}

rather than

return newShares, hooks.AfterDelegationModified(ctx, receiver.GetID(), delegator)

Even though they are identical. Just some lines more won't be an issue performance-wise (also because the compiler will take care of optimizing them). It's just about making it easier to read for other developers and have a consistent code style in my opinion

@RiccardoM RiccardoM requested review from hallazzang and rustcandy July 2, 2024 17:18
Copy link
Contributor

@hallazzang hallazzang left a comment

Choose a reason for hiding this comment

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

LGTM

@RiccardoM RiccardoM merged commit 9427193 into main Jul 4, 2024
17 checks passed
@RiccardoM RiccardoM deleted the riccardom/restaking-module branch July 4, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants