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

chore: loosen assertions in SetOrderBeginBlockers() and SetOrderEndBlockers() #14415

Merged
merged 12 commits into from
Dec 29, 2022

Conversation

0Tech
Copy link
Contributor

@0Tech 0Tech commented Dec 26, 2022

Description

Thanks to #12603, we can omit the methods BeginBlock() and EndBlock() from a module. This patch goes one step further, allowing one not to add the module name into SetOrderBeginBlockers() or SetOrderEndBlockers() if the module does not have the corresponding method.

Before implementing the method, we cannot know its order in the modules, so I think it would be better not to add a module into the order list before implementing it.


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)

Copy link
Contributor Author

@0Tech 0Tech left a comment

Choose a reason for hiding this comment

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

I provide the supplementary comments.

simapp/app.go Outdated
Comment on lines 419 to 426
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName,
authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
authz.ModuleName,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the main reason of the PR is to make the list clean, I removed module names which does not have BeginBlock().
But, it's not mandatory.

func(moduleName string) bool {
module := m.Modules[moduleName]
_, hasBeginBlock := module.(BeginBlockAppModule)
return !hasBeginBlock
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assertion passes if the module does not have BeginBlock().

{"less modules", false, []string{"a"}, nil},
{"same modules", true, []string{"a", "b"}, nil},
{"more modules", true, []string{"a", "b", "c"}, nil},
{"pass module b", true, []string{"a"}, func(moduleName string) bool { return moduleName == "b" }},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The relevant unit test case.

@0Tech 0Tech marked this pull request as ready for review December 26, 2022 09:50
@0Tech 0Tech requested a review from a team as a code owner December 26, 2022 09:50
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

This is nicer but the reason we added it before was that a developer forgot to add the begin blocker and it caused issue. I think we should keep that functionality but instead, if possible, we should check all the modules if they have the interface(s) somewhere else, if so then error out telling the user they forgot to add a module this prevents the problem we faced earlier but without forcing users to list all the modules

types/module/module.go Fixed Show fixed Hide fixed
@0Tech
Copy link
Contributor Author

0Tech commented Dec 27, 2022

a developer forgot to add the begin blocker

You mean, the developer forgot to add the module name into the argument of SetOrderBeginBlockers(), right?

This is nicer but the reason we added it before was that a developer forgot to add the begin blocker and it caused issue. I think we should keep that functionality but instead, if possible, we should check all the modules if they have the interface(s) somewhere else, if so then error out telling the user they forgot to add a module this prevents the problem we faced earlier but without forcing users to list all the modules

I thought following procedures are necessary:

  • register the modules which we are going to use
  • specify the order of BeginBlock() and EndBlock()

Hence, while sequencing them, we can also check whether the modules which have BeginBlock() (or EndBlock()) are not specified in the list. This is the intention of this PR.

If a module has BeginBlock() and one forgets to add the module into SetOrderBeginBlockers(), it will still panic.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! It seems like a nice improvement!

Have you checked it the docs (docs/) are up to date?

I think we should add a changelog under improvements too.

types/module/module.go Show resolved Hide resolved
Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

@julienrbrt julienrbrt enabled auto-merge (squash) December 29, 2022 06:27
@julienrbrt julienrbrt merged commit e18a093 into cosmos:main Dec 29, 2022
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
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.

4 participants