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

feat: IBC packet tracking adjustments #748

Merged
merged 7 commits into from
Jan 7, 2025
Merged

Conversation

crnbarr93
Copy link
Contributor

@crnbarr93 crnbarr93 commented Jan 4, 2025

Motivation

These changes are to aid in off chain tracking of packets. This includes:

  • Several adjustments to emitted events and their attributes
  • A fix for a bug found with sending multiple IBC messages via the kernel in one message
  • A fix for a bug found in the splitter related to each AMP message containing the funds for every message

Testing

The splitter test for IBC was updated to reflect the fixes from above

Version Changes

kernel: 1.2.0-b.3 -> 1.2.0-b.4
splitter: 2.3.0-b.1 -> 2.3.0-b.2

Summary by CodeRabbit

Release Notes

  • New Features

    • Added IBC packet tracking adjustments
    • Enhanced splitter functionality with multi-recipient support
  • Changes

    • Limited rates recipients to one address
    • Updated address validation for cross-chain recipients
    • Modified Weighted Splitter to replace Recipient with AndrAddr
    • Improved coin distribution and message generation in splitter contract
  • Bug Fixes

    • Resolved kernel issues with IBC handling
    • Fixed local AMP message processing with custom configurations
  • Performance

    • Added coin processing limit to prevent potential DoS attacks
    • Streamlined message handling and relay processes

@crnbarr93 crnbarr93 requested a review from joemonem January 4, 2025 10:05
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

This pull request introduces several updates across the Andromeda protocol's contracts, focusing on improvements in the splitter contract, kernel execution, and IBC packet handling. The changes include version bumps for the andromeda-splitter and andromeda-kernel packages, modifications to the splitter's coin distribution logic, enhanced error handling in the kernel's execute functions, and updates to test cases for cross-chain recipient functionality.

Changes

File Change Summary
CHANGELOG.md Added entries for IBC packet tracking, rate recipient limitations, and cross-chain recipient updates
contracts/finance/andromeda-splitter/Cargo.toml Version bumped from 2.3.0-b.1 to 2.3.0-b.2
contracts/finance/andromeda-splitter/src/contract.rs Optimized execute_send function with coin distribution logic, added 5-coin limit check
contracts/os/andromeda-kernel/Cargo.toml Version bumped from 1.2.0-b.3 to 1.2.0-b.4
contracts/os/andromeda-kernel/src/execute.rs Enhanced send, trigger_relay, and amp_receive functions with improved message handling and error checking
tests-integration/tests/splitter.rs Updated test cases for splitter with multiple recipients and increased fund distribution

Sequence Diagram

sequenceDiagram
    participant Sender
    participant Splitter
    participant Recipients
    
    Sender->>Splitter: Send funds
    Splitter->>Splitter: Calculate recipient shares
    Splitter->>Recipients: Distribute funds
    Splitter-->>Sender: Confirm distribution
Loading

Possibly related PRs

Poem

🐰 Hop, hop, through code so bright,
Splitter's logic takes new flight!
Coins divided, messages clear,
Andromeda's path grows ever near.
A rabbit's dance of smart contract glee! 🚀


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

@crnbarr93 crnbarr93 marked this pull request as ready for review January 4, 2025 11:43
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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests-integration/tests/splitter.rs (1)

617-637: Validate IBC Recipient Strings for Safety

The cross-chain recipients use strings like "ibc://osmosis/...". Consider adding validation checks or a parsing routine to ensure the chain IDs and addresses adhere to your conventional format, avoiding potential injection or encoding issues.

contracts/os/andromeda-kernel/src/execute.rs (2)

47-47: Consider More Descriptive Error Handling

Using .expect("No packet found for channel_id and sequence") triggers a panic. Replacing it with a custom ContractError or returning an error would offer a cleaner failure path and consistent error handling.

-    .expect("No packet found for channel_id and sequence");
+    .map_err(|_| ContractError::InvalidPacket {
+        error: Some("No packet found for the specified channel_id and sequence".to_string()),
+    })?

215-219: Skipping the First Message

Explicitly skipping the first message is a practical way to differentiate it from the rest. Consider adding logs or commentary clarifying that the first message has already been processed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76bfa27 and 22a3351.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • contracts/finance/andromeda-splitter/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-splitter/src/contract.rs (1 hunks)
  • contracts/os/andromeda-kernel/Cargo.toml (1 hunks)
  • contracts/os/andromeda-kernel/src/execute.rs (8 hunks)
  • tests-integration/tests/splitter.rs (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • contracts/os/andromeda-kernel/Cargo.toml
  • contracts/finance/andromeda-splitter/Cargo.toml
🔇 Additional comments (13)
tests-integration/tests/splitter.rs (2)

654-654: Increased Funding for Splitter

Raising the split amount from 100 to 200 is acceptable. Ensure you have additional tests covering smaller or zero split amounts for edge-case scenarios.


674-674: Confirm Sufficient Post-Send Balance

The assertion verifying the entire 200 tokens reached the kernel is correct. If partial distributions are expected in other tests, consider adding them to ensure distribution logic remains robust.

contracts/finance/andromeda-splitter/src/contract.rs (1)

209-214: Streamlined Distribution Logic

Appending directly to amp_funds and immediately generating AMP messages simplifies the logic. Ensure any potential overflow or large coin calculations are still safe within these loops, and consider the maximum possible number of recipients to mitigate DoS concerns.

contracts/os/andromeda-kernel/src/execute.rs (9)

8-8: Good Use of Merged Coin Utilities

Bringing in has_coins_merged and merge_coins helps centralize coin-fund checks. This should reduce duplication and potential errors across code paths.


71-71: Maintaining Packet Sequence

Passing packet_sequence forward in the error handling is clear and consistent with the operation. Consider logging or storing the sequence in more contexts to ease debugging if an issue arises.


83-87: Refund Attributes Provide Clarity

Adding these attributes for a refund outcome boosts observability, allowing off-chain systems to parse logs for debug or analytics. This is a helpful pattern for multi-chain event tracking.


163-168: Enhanced Relay Success Metadata

The additional attributes for a successful relay highlight the chain ID, channel, and receiving kernel. This is an excellent improvement in cross-chain traceability.


179-180: Strengthened Access Control on AMP Reception

Verifying that info.sender == env.contract.address || query::verify_address(...)?.verify_address prevents unauthorized calls. Good to see robust permission checks aligned with the contract’s security model.


198-207: Handling the First AMP Message Explicitly

Processing only the first message separately can reduce complexity but be sure to handle all edge cases, like packets containing only one message versus multiple. The code is clear as written.


208-214: Message Aggregation for Additional AMP Messages

Appending the handled messages into res and building new_pkt for the remainder is a neat approach. Validate that large or invalid packets do not degrade performance or lead to memory issues.


221-230: Conditional Sub-packet Creation

Triggering a new sub-message only when subsequent AMP messages exist is efficient. If an external caller attempts to craft packets with extraneous data, it will be gracefully discarded.


856-859: Single Coin Restriction for ICS20 Transfers

Limiting funds.len() to exactly one in ICS20 ensures a simpler flow. Consider documenting or validating corner cases where bridging multiple coins might be desired in the future.

CHANGELOG.md (1)

30-30: Clear Documentation of IBC Packet Tracking Feature

Referencing PR #748 in the changelog is excellent. It helps maintainers trace changes. Make sure to include any known migration instructions or backward compatibility notes, if applicable.

@crnbarr93 crnbarr93 merged commit 1a6f458 into main Jan 7, 2025
13 checks passed
@crnbarr93 crnbarr93 deleted the connor/ibc-packet-tracking branch January 7, 2025 20:13
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.

2 participants