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

perf: Don't deserialize params for every validator in slashing #18959

Merged
merged 5 commits into from
Jan 6, 2024

Conversation

ValarDragon
Copy link
Contributor

@ValarDragon ValarDragon commented Jan 5, 2024

Description

Pretty light performance improvement. Its a been a consistent small point that validators missed block tracking appears in CPU profiles. (DB key format / data layout is the bigger issue to fixing)

This at least removes the param deserialization of it. I don't have a "fair" benchmark to compare with on-hand over a large period, but on an IAVL v0 benchmark during 100 blocks with high CPU load, it appears params deserialziation is taking .8% of the CPU time for block execution.

Go tests are broken on my laptop rn for the SDK, hopefully this works without too many back + forths 🙏
I won't be able to fix too many follow-ups in a hot loop because of this, so happy to close if its not worth the overhead. (Or have someone else take over!)

This should be fully state compatible.


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
  • confirmed ! in 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
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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 all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@ValarDragon ValarDragon requested a review from a team as a code owner January 5, 2024 23:00
Copy link
Contributor

coderabbitai bot commented Jan 5, 2024

Walkthrough

The changes involve updates to the slashing module, specifically refining how the BeginBlocker function processes validator activities and the calculation of the minimum number of blocks validators must sign. The logic for slashing and unbonding due to missed blocks has been adjusted, and a new method for calculating the MinSignedPerWindow parameter has been implemented to ensure it's derived from existing struct fields and rounded to the nearest integer.

Changes

Files Summary
x/slashing/abci.go Updated BeginBlocker function to retrieve parameters and handle validator signatures with additional parameters, potentially affecting the logic related to slashing and unbonding validators based on missed blocks, introducing a slight speedup to the Slashing Beginblock logic.
x/slashing/keeper/infractions.go, x/slashing/keeper/params.go, x/slashing/types/params.go Modified HandleValidatorSignature function in infractions.go to call a new HandleValidatorSignatureWithParams function with additional parameters. The new function takes a types.Params object as an argument and uses its fields for computation. Additionally, in keeper/params.go, the MinSignedPerWindow function has been modified to now call another function MinSignedPerWindowInt on the receiver params instead of directly using the params struct fields SignedBlocksWindow and MinSignedPerWindow. Also, the MinSignedPerWindow method has been added to the Params type, which calculates a value based on the SignedBlocksWindow and MinSignedPerWindow fields and returns the result rounded to the nearest integer.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit's AI:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

This comment has been minimized.

x/slashing/keeper/params.go Outdated Show resolved Hide resolved
ValarDragon and others added 4 commits January 5, 2024 17:09
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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!

@@ -191,6 +191,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [#18372](https://github.com/cosmos/cosmos-sdk/pull/18372) Removed global configuration for coin type and purpose. Setters and getters should be removed and access directly to defined types.
* (types) [#18695](https://github.com/cosmos/cosmos-sdk/pull/18695) Removed global configuration for txEncoder.
* (server) [#18909](https://github.com/cosmos/cosmos-sdk/pull/18909) Remove configuration endpoint on grpc reflection endpoint in favour of auth module bech32prefix endpoint already exposed.
* (slashing) [#18959](https://github.com/cosmos/cosmos-sdk/pull/18959) Slight speedup to Slashing Beginblock logic
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, changelog of modules should be under their own changelog.
Here x/slashing/changelog.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thank you will move that

@@ -146,3 +146,13 @@ func validateSlashFractionDowntime(i interface{}) error {

return nil
}

// return min signed per window as an integer (vs the decimal in the param)
Copy link
Member

Choose a reason for hiding this comment

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

Nit go doc naming.

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.

utACK

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.

Thanks for the pr

@tac0turtle tac0turtle added this pull request to the merge queue Jan 6, 2024
Merged via the queue into main with commit 0b01347 Jan 6, 2024
59 of 60 checks passed
@tac0turtle tac0turtle deleted the dev/dont_get_params_per_val branch January 6, 2024 07:51
@tac0turtle tac0turtle mentioned this pull request Jan 6, 2024
12 tasks
ValarDragon added a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 22, 2024
ValarDragon added a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
mergify bot pushed a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)
mergify bot pushed a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)
mergify bot pushed a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)
ValarDragon added a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)

Co-authored-by: Dev Ojha <[email protected]>
ValarDragon added a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)

Co-authored-by: Dev Ojha <[email protected]>
ValarDragon added a commit to osmosis-labs/cosmos-sdk that referenced this pull request Feb 23, 2024
(cherry picked from commit c4a2b32)

Co-authored-by: Dev Ojha <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request May 3, 2024
12 tasks
czarcas7ic pushed a commit to osmosis-labs/cosmos-sdk that referenced this pull request May 9, 2024
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.

4 participants