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

collect requeued txs together #1222

Merged
merged 6 commits into from
Mar 4, 2024
Merged

collect requeued txs together #1222

merged 6 commits into from
Mar 4, 2024

Conversation

joe-bowman
Copy link
Contributor

@joe-bowman joe-bowman commented Mar 4, 2024

1. Summary

Fixes #1201

Instead of spawning a new withdrawal record for every failed tx, look for an existing requeued withdrawal record to update first.

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)

3. Implementation details

Instead of blindly spawning a requeued withdrawal record for every failed msg (because withdrawal record often spawn multiple validators), we should check for an existing requeued withdrawal record first.

Note: we also replace the way we store the WithdrawalRecordSequence, to be a protobuf encoded uint64, instead of storing the raw bytes. InitWithdrawalRecordSequence must be called by the upgrade handler.

Todo: need to write an upgrade handler to group existing requeued record by user.

Summary by CodeRabbit

  • New Features
    • Enhanced interchain staking functionality with support for multi-validator scenarios.
    • Improved the accuracy of distribution and burn amount calculations for withdrawals.
    • Added capability to handle final withdrawal record deletion and requeueing efficiently.
  • Bug Fixes
    • Modified withdrawal record sequence initialization and incrementation logic for better reliability.
  • Tests
    • Introduced new tests to validate the handling of failed undelegate scenarios.
    • Refined testing infrastructure with additional helper functions.
  • Refactor
    • Streamlined withdrawal record management by updating and creating records as needed.

Copy link

vercel bot commented Mar 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2024 8:01pm

Copy link
Contributor

coderabbitai bot commented Mar 4, 2024

Walkthrough

The changes introduced focus on enhancing the interchain staking mechanism, particularly addressing the handling of multi-validator scenarios and requeued withdrawal records. The improvements include better logic for withdrawal record management, adjustments in distribution and burn amount calculations, and the grouping of requeued unbondings. This ensures a more efficient and accurate processing of staking operations across different validators and user scenarios.

Changes

Files Summary of Changes
x/interchainstaking/keeper/ibc_packet_handlers.go, x/interchainstaking/keeper/ibc_packet_handlers_test.go Enhanced multi-validator handling, withdrawal record updates, and test improvements.
x/interchainstaking/keeper/withdrawal_record.go Improved withdrawal record sequence management and added functionality for handling requeued records.

Assessment against linked issues

Objective Addressed Explanation
Requeued unbondings should be grouped together (#1201)

Poem

In the realm where bytes and chains entwine,
A rabbit hopped, through code, it did refine.
With each leap, a fix, a tweak, a bind,
Ensuring staking's weave, tightly intertwined.
🌟 Through validators and records, it danced with grace,
🐇 For interchain staking, it set the pace.
In code, it whispered, "Let's embrace change," 🚀
For a blockchain world, vast and strange.


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>.
    • Generate unit-tests for this file.
  • 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 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 and a 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.

x/interchainstaking/keeper/ibc_packet_handlers_test.go Dismissed Show dismissed Hide dismissed
x/interchainstaking/keeper/ibc_packet_handlers_test.go Dismissed Show dismissed Hide dismissed
x/interchainstaking/keeper/ibc_packet_handlers_test.go Dismissed Show dismissed Hide dismissed
x/interchainstaking/keeper/ibc_packet_handlers_test.go Dismissed Show dismissed Hide dismissed
x/interchainstaking/keeper/ibc_packet_handlers_test.go Dismissed Show dismissed Hide dismissed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 8

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0a628d0 and d81f09c.
Files selected for processing (3)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (2 hunks)
  • x/interchainstaking/keeper/ibc_packet_handlers_test.go (4 hunks)
  • x/interchainstaking/keeper/withdrawal_record.go (3 hunks)
Additional comments: 15
x/interchainstaking/keeper/withdrawal_record.go (2)
  • 31-53: The GetNextWithdrawalRecordSequence function correctly retrieves, increments, and stores the global withdrawal record sequence. This implementation aligns with the PR objectives and ensures that each withdrawal record has a unique sequence number. The error handling in case of unmarshalling failure is done by panicking, which is a common pattern in blockchain systems where consistency is critical. However, it's important to ensure that such panics are caught and handled appropriately at higher levels to prevent system crashes.
  • 171-183: The addition of GetUserChainRequeuedWithdrawalRecord function is a significant improvement, as it allows for retrieving a requeued withdrawal record for a specific user and chain. This function directly supports the PR's objective of optimizing the handling of requeued transactions by updating existing records instead of creating new ones. The implementation iterates over withdrawal records with a specific status and returns the first matching requeued record for the given user and chain. This approach is efficient and aligns well with the described objectives. However, it's worth noting that if there are multiple requeued records for the same user and chain, this function will only return the first one encountered. Ensure this behavior is intended and documented.
x/interchainstaking/keeper/ibc_packet_handlers.go (13)
  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [35-48]

The DeserializeCosmosTxTyped function is implemented correctly. It properly handles the deserialization of Cosmos transactions into a slice of TypedMsg structs, including error handling.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [257-259]

The HandleTimeout function is correctly implemented as a placeholder for handling IBC packet timeouts. Ensure that appropriate timeout handling logic is added in the future if required by the application logic.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [431-474]

The HandleFailedBankSend function correctly handles the failure of a bank send message, including handling various scenarios based on the sender and receiver addresses. The structure and logic are consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [476-496]

The HandleFailedUnbondSend function correctly handles the failure of an unbond send message, including updating the withdrawal record status and requeuing the withdrawal. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1010-1042]

The HandleFailedRedeemTokens function correctly handles the failure of a redeem tokens for shares message, including decrementing the withdrawal waitgroup and triggering the redemption rate calculation. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1109-1141]

The HandleFailedDelegate function correctly handles the failure of a delegate message, including decrementing the withdrawal waitgroup and triggering the redemption rate calculation. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1143-1175]

The HandleUpdatedWithdrawAddress function correctly handles the update of a withdraw address, including updating the zone information. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1177-1196]

The GetValidatorForToken function correctly retrieves the validator for a given token based on its denomination, including error handling. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1198-1277]

The UpdateDelegationRecordsForAddress function correctly updates delegation records for a given address, including triggering ICQ requests for new or updated records. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1279-1348]

The UpdateDelegationRecordForAddress function correctly updates a specific delegation record for a given address, including updating the delegation amount and triggering the redemption rate calculation. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1350-1377]

The HandleWithdrawRewards function correctly handles the withdrawal of rewards, including decrementing the withdrawal waitgroup and triggering the redemption rate calculation. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1379-1403]

The TriggerRedemptionRate function correctly triggers the calculation of the redemption rate, including making an ICQ request to query all balances and then distributing rewards. The implementation is consistent with the rest of the file.

  • 855-896: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1405-1458]

The DistributeRewardsFromWithdrawAccount function correctly distributes rewards from the withdrawal account, including querying all balances, calculating fees, and preparing reward distribution messages. The implementation is consistent with the rest of the file.

x/interchainstaking/keeper/withdrawal_record.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/withdrawal_record.go Outdated Show resolved Hide resolved
@faddat
Copy link
Contributor

faddat commented Mar 4, 2024

@joe-bowman I'm going to fix lints, and this PR looks g2g otherwise.

@faddat faddat enabled auto-merge (squash) March 4, 2024 19:29
faddat
faddat previously approved these changes Mar 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d81f09c and 1401cb6.
Files selected for processing (3)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (3 hunks)
  • x/interchainstaking/keeper/ibc_packet_handlers_test.go (4 hunks)
  • x/interchainstaking/keeper/withdrawal_record.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/interchainstaking/keeper/ibc_packet_handlers.go
  • x/interchainstaking/keeper/withdrawal_record.go

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

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

Project coverage is 63.16%. Comparing base (305f3c2) to head (454bd7e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1222      +/-   ##
==========================================
+ Coverage   63.13%   63.16%   +0.02%     
==========================================
  Files         171      171              
  Lines       11247    11261      +14     
==========================================
+ Hits         7101     7113      +12     
- Misses       3422     3425       +3     
+ Partials      724      723       -1     
Flag Coverage Δ
unittests 63.16% <85.71%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
x/interchainstaking/keeper/ibc_packet_handlers.go 65.23% <100.00%> (+0.40%) ⬆️
x/interchainstaking/keeper/withdrawal_record.go 86.47% <73.91%> (-2.57%) ⬇️

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1401cb6 and bb07f92.
Files selected for processing (1)
  • x/interchainstaking/keeper/withdrawal_record.go (3 hunks)
Additional comments: 3
x/interchainstaking/keeper/withdrawal_record.go (3)
  • 9-10: The addition of gogotypes and sdkmath imports is appropriate for the protobuf encoding and mathematical operations required by the new functionality.
  • 20-27: The InitWithdrawalRecordSequence function initializes the sequence to a hardcoded value of 512. Consider making this value configurable or documenting the reason for this specific choice.
  • 16-55: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-183]

Overall, the changes in withdrawal_record.go integrate well with the existing codebase, enhancing functionality without disrupting existing logic. The modifications align with the PR's objectives and are consistent with Cosmos SDK patterns.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bb07f92 and 454bd7e.
Files selected for processing (1)
  • x/interchainstaking/keeper/withdrawal_record.go (3 hunks)
Additional comments: 1
x/interchainstaking/keeper/withdrawal_record.go (1)
  • 9-10: The addition of gogotypes and sdkmath imports aligns with the usage of protobuf for encoding and the new mathematical operations introduced in this file. Ensure that these libraries are used consistently throughout the project to avoid introducing multiple dependencies for similar functionalities.

@faddat faddat merged commit 62f89c9 into main Mar 4, 2024
25 checks passed
@joe-bowman joe-bowman deleted the 1200-collect-reqeued branch March 5, 2024 13:34
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.

Requeued unbondings should be grouped together
2 participants