node icon indicating copy to clipboard operation
node copied to clipboard

refactor(zetacore): delete ballots after maturity

Open kingpinXD opened this issue 1 year ago โ€ข 2 comments

Description

Closes https://github.com/zeta-chain/node/issues/942

How Has This Been Tested?

  • [ ] Tested CCTX in localnet
  • [ ] Tested in development environment
  • [ ] Go unit tests
  • [ ] Go integration tests
  • [ ] Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Added functionality to delete matured ballots, enhancing ballot lifecycle management.
    • Introduced a new VoterList message type to track individual voter details.
    • Added event handling for deleted ballots to improve system responsiveness.
  • Bug Fixes

    • Enhanced logic for managing observer rewards and matured ballots.
  • Tests

    • Expanded test coverage for ballot deletion and voter list generation, ensuring robustness in functionality.
  • Documentation

    • Updated changelog to reflect the latest changes and features.

kingpinXD avatar Sep 11 '24 16:09 kingpinXD

[!IMPORTANT]

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough
๐Ÿ“ Walkthrough

Walkthrough

The changes introduced in this pull request focus on enhancing ballot management within the system, specifically addressing the deletion of matured ballots. This includes the addition of new message types, modifications to existing functions for handling ballots, and the introduction of event emissions upon ballot deletion. The updates aim to streamline the lifecycle management of ballots, ensuring that matured ballots are efficiently removed from the state to optimize resource use.

Changes

Files Change Summary
changelog.md Added entry for deleting ballots after they mature.
proto/zetachain/zetacore/observer/ballot.proto Introduced VoterList message with fields for voter address and vote type.
proto/zetachain/zetacore/observer/events.proto Added EventBallotDeleted message and imported ballot.proto.
proto/zetachain/zetacore/observer/query.proto Modified QueryBallotByIdentifierResponse to enforce non-nullable voters field.
testutil/keeper/mocks/emissions/observer.go Introduced ClearMaturedBallots mock function for testing.
x/emissions/abci.go Modified DistributeObserverRewards to handle and clear matured ballots.
x/emissions/abci_test.go Adjusted test logic for reward distribution and ballot maturity checks.
x/emissions/types/expected_keepers.go Added ClearMaturedBallots method to ObserverKeeper interface.
x/observer/keeper/ballot.go Added methods for deleting individual ballots and lists, and clearing matured ballots.
x/observer/keeper/ballot_test.go Added tests for deleting ballots, clearing matured ballots, and ensuring correct behavior.
x/observer/keeper/events.go Introduced EmitEventBallotDeleted for emitting deletion events.
x/observer/keeper/events_test.go Created tests for EmitEventBallotDeleted functionality.
x/observer/keeper/grpc_query_ballot.go Simplified voter list construction using GenerateVoterList method.
x/observer/keeper/grpc_query_ballot_test.go Changed Voters field type in response struct from pointer to value slice.
x/observer/types/ballot.go Added GenerateVoterList method to Ballot struct for generating voter lists.
x/observer/types/ballot_test.go Added tests for GenerateVoterList method to validate voter list generation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Keeper
    participant EventManager

    User->>Keeper: Request to delete matured ballots
    Keeper->>Keeper: Identify matured ballots
    Keeper->>Keeper: Delete matured ballots
    Keeper->>EventManager: Emit EventBallotDeleted
    EventManager-->>Keeper: Confirmation of event emission

Assessment against linked issues

Objective Addressed Explanation
Delete matured ballots (##942) โœ…
Add an event when the ballot gets deleted (##942) โœ…

Possibly related PRs

  • #2863 - Directly relates to the deletion of matured ballots, which is a core focus of this PR.
  • #2861 - Enhances event handling, which may indirectly affect ballot management processes.

Suggested labels

breaking:cli, chain:solana


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Sep 11 '24 16:09 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 95.65217% with 6 lines in your changes missing coverage. Please review.

Project coverage is 62.53%. Comparing base (7eea20e) to head (950141f). Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
x/observer/keeper/grpc_query_ballot.go 73.91% 4 Missing and 2 partials :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2863      +/-   ##
===========================================
+ Coverage    62.43%   62.53%   +0.10%     
===========================================
  Files          449      450       +1     
  Lines        31706    31811     +105     
===========================================
+ Hits         19795    19894      +99     
- Misses       11024    11028       +4     
- Partials       887      889       +2     
Files with missing lines Coverage ฮ”
x/emissions/abci.go 94.26% <100.00%> (+1.08%) :arrow_up:
x/observer/keeper/ballot.go 100.00% <100.00%> (รธ)
x/observer/migrations/v9/migrate.go 100.00% <100.00%> (รธ)
x/observer/keeper/grpc_query_ballot.go 90.32% <73.91%> (-9.68%) :arrow_down:

codecov[bot] avatar Sep 11 '24 16:09 codecov[bot]

Small note: let's keep this one aside for now to not introduce migration scripts as we already heavy operations with gateway and Solana

lumtis avatar Nov 06 '24 08:11 lumtis

Hi @lumtis Should we revisit this for the next release?

We can consider breaking the pr down, into

  • Change in logic
  • Migration script And only add the former if in case a long-running migration script is not desired

kingpinXD avatar Dec 10 '24 10:12 kingpinXD

Hi @lumtis Should we revisit this for the next release?

We can consider breaking the pr down, into

  • Change in logic
  • Migration script And only add the former if in case a long-running migration script is not desired

We actually want to remove all old ballot so we can easily query all active ballots

lumtis avatar Dec 19 '24 22:12 lumtis

The PR looks good to me, let's just wrap up v25 first before merging it

lumtis avatar Jan 08 '25 14:01 lumtis