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

BM-13: feat(epoching): add hooks, events and keeper functions #14

Merged
merged 8 commits into from
Jun 21, 2022

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Jun 15, 2022

Fixes BM-13 and BM-14

This PR adds hooks and events for the epoching module, including

  • 2 hooks AfterEpochBegins and AfterEpochEnds
  • 2 events BeginEpoch and EndEpoch
  • 3 keeper functions

@SebastianElvis SebastianElvis changed the title BM-13: feat(epoching): add hooks and events BM-13: feat(epoching): add hooks, events and keeper functions Jun 15, 2022
@SebastianElvis
Copy link
Member Author

UPDATE: added 3 keeper functions in this PR to close BM-14 also, given the light workload.

Comment on lines 30 to 31
BeginEpoch(ctx sdk.Context, epoch sdk.Uint) error // Must be called when an epoch begins
EndEpoch(ctx sdk.Context, epoch sdk.Uint) error // Must be called when an epoch ends
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor comment about the naming. For example, the statking module has hooks name like AfterValidatorCreated. Should we follow their convention? Maybe AfterEpochBegins?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. I double-checked Cosmos SDK code, it seems that they distinguish between BeforeXXX andEndXXX. In our scenario I think we only need AfterEpochBegins and AfterEpochEnds. Thanks!

Comment on lines 30 to 31
BeginEpoch(ctx sdk.Context, epoch sdk.Uint) error // Must be called when an epoch begins
EndEpoch(ctx sdk.Context, epoch sdk.Uint) error // Must be called when an epoch ends
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor comment about the naming. For example, the statking module has hooks name like AfterValidatorCreated. Should we follow their convention? Maybe AfterEpochBegins?

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Looks good (although I don't know much about hooks)!

My two remarks are basically that we already fixed in the proto messages that only certain messages can be delayed, so I reckon the code should reflect that restriction as well, and that I still don't understand why we should support querying delayed messages by epoch number.

Comment on lines 64 to 65
// GetEpochMsgs returns the set of messages queued of a given uncheckpointed epoch
func (k Keeper) GetEpochMsgs(ctx sdk.Context, epoch sdk.Uint) []sdk.Msg {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought in https://github.com/babylonchain/babylon/pull/10/files#r899915268 we agreed that this method will not have any epoch parameter, that it returns the messages that will be dequeued at the end of the current epoch. We also know that the return value will be more specific than sdk.Msg, it's the QueuedMessage type you defined.

Copy link
Member Author

@SebastianElvis SebastianElvis Jun 20, 2022

Choose a reason for hiding this comment

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

Yeah I was doing this for being consistent. Will remove the epoch field and use the QueuedMessage type.

}

// EnqueueMsg enqueues a message to the queue of the current epoch
func (k Keeper) EnqueueMsg(ctx sdk.Context, msg sdk.Msg) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't msg be of type QueuedMessage?

@SebastianElvis
Copy link
Member Author

Thanks for the comments Akosh and Gai! Now this PR reflects to the comments and #10. Feel free to have a look again.

Copy link
Contributor

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Nice work. LGTM!

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Good good 👏

@SebastianElvis SebastianElvis merged commit 901d96a into main Jun 21, 2022
@SebastianElvis SebastianElvis deleted the epoching-hooks-events branch June 21, 2022 00:04
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