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

[TRA-109] Filter out transfers between child subaccounts of same parent. #1544

Merged
merged 3 commits into from
May 21, 2024

Conversation

vincentwschau
Copy link
Contributor

@vincentwschau vincentwschau commented May 17, 2024

Changelist

Update socks to filter out transfers between child subaccounts for the same parent subaccount for the parent subaccount websocket channel.

Test Plan

Unit tests.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Enhanced transfer functionality to handle transfers between child subaccounts of the same parent subaccount.
  • Tests

    • Added tests for filtering transfers between child subaccounts for the parent subaccount channel.
    • Added tests for various transfer scenarios including transfers between other parent/child subaccounts, deposits, and withdrawals.

Copy link

linear bot commented May 17, 2024

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Walkthrough

The recent updates focus on improving the handling of subaccount transfers within the indexer service. These changes include introducing new type declarations for transfer messages and enhancing test coverage for different transfer scenarios. A significant aspect is the refinement of handling transfers between child subaccounts for parent subaccount channels, ensuring accurate tracking of transactions. These modifications enhance the clarity and reliability of the transfer logic in the from-kafka-helpers.ts file.

Changes

File Path Change Summary
.../indexer/services/socks/__tests__/constants.ts Added TransferSubaccountMessageContents and TransferType declarations.
.../indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts Enhanced imports and added tests for various transfer scenarios, including filtering child subaccount transfers.
.../indexer/services/socks/src/helpers/from-kafka-helpers.ts Updated getParentSubaccountContents to handle child subaccount transfers and added necessary imports.

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>.
    • 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 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 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.

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.
  • 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.

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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 333df84 and b27f8e5.
Files selected for processing (3)
  • indexer/services/socks/tests/constants.ts (2 hunks)
  • indexer/services/socks/tests/helpers/from-kafka-helpers.test.ts (3 hunks)
  • indexer/services/socks/src/helpers/from-kafka-helpers.ts (3 hunks)
Additional Context Used
Path-based Instructions (3)
indexer/services/socks/__tests__/constants.ts (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

indexer/services/socks/src/helpers/from-kafka-helpers.ts (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Additional comments not posted (3)
indexer/services/socks/__tests__/constants.ts (2)

9-10: The addition of TransferSubaccountMessageContents and TransferType aligns with the PR's objectives to handle subaccount transfers more effectively.


108-123: The defaultTransferContents constant is well-defined and crucial for testing the new functionality of filtering subaccount transfers. Ensure its usage is consistent across all relevant tests.

Verification successful

The defaultTransferContents constant is well-defined and crucial for testing the new functionality of filtering subaccount transfers. It is used consistently in the from-kafka-helpers.test.ts file, ensuring its relevance in the test scenarios.

  • Locations:
    • indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `defaultTransferContents` in tests.

# Test: Search for the constant usage in test files. Expect: Usage in relevant test scenarios.
rg --type typescript $'defaultTransferContents' -- 'indexer/services/socks/__tests__/*.ts'

Length of output: 124



Script:

#!/bin/bash
# Description: Verify the usage of `defaultTransferContents` in tests.

# Test: Search for the constant usage in test files. Expect: Usage in relevant test scenarios.
rg 'defaultTransferContents' --glob 'indexer/services/socks/__tests__/*.ts'

Length of output: 197



Script:

#!/bin/bash
# Description: Verify the usage of `defaultTransferContents` in all TypeScript files within the test directory.

# Test: Search for the constant usage in all TypeScript files. Expect: Usage in relevant test scenarios.
rg 'defaultTransferContents' --glob 'indexer/services/socks/**/*.ts'

Length of output: 709

indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts (1)

159-192: The new test effectively verifies the filtering of transfers between child subaccounts for the parent subaccount channel. Consider adding more edge cases to ensure robustness, such as scenarios with malformed transfer data.

Verification successful

The getMessageToForward function decodes the Kafka message and processes it based on the channel. However, the snippet provided does not show the handling for the V4_PARENT_ACCOUNTS channel. To ensure the filtering logic is correctly implemented, we need to see the complete implementation of the getMessageToForward function, especially the part handling the V4_PARENT_ACCOUNTS channel.


The getMessageToForward function includes handling for the V4_PARENT_ACCOUNTS channel, where it decodes the SubaccountMessage and uses the getParentSubaccountContents function to filter the contents. This aligns with the test case that verifies the filtering of transfers between child subaccounts.

The test case and the implementation appear to be correctly aligned, ensuring that transfers between child subaccounts are filtered out for the parent subaccount channel.

  • : The test case effectively verifies the filtering of transfers between child subaccounts for the parent subaccount channel. The implementation of getMessageToForward correctly handles this scenario.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the effectiveness of the new test.

# Test: Run the test suite and check for failures in this specific test. Expect: All tests pass.
# Command to run the test suite (assuming a typical Node.js environment):
npm test -- indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts

Length of output: 152



Script:

#!/bin/bash
# Description: Verify the effectiveness of the new test.

# Check if yarn is available
if command -v yarn &> /dev/null
then
    # Run the test suite using yarn
    yarn test indexer/services/socks/__tests__/helpers/from-kafka-helpers.test.ts
else
    echo "Neither npm nor yarn is available to run the tests."
fi

Length of output: 130



Script:

#!/bin/bash
# Description: Locate and review the implementation of `getMessageToForward` and related helper functions.

# Find the implementation of `getMessageToForward`
ast-grep --lang typescript --pattern 'function getMessageToForward($_, $_) { $$$ }'

# Find the implementation of `createKafkaMessage`
ast-grep --lang typescript --pattern 'function createKafkaMessage($_) { $$$ }'

Length of output: 166



Script:

#!/bin/bash
# Description: Locate the implementation of `getMessageToForward` and `createKafkaMessage` using `rg`.

# Search for the implementation of `getMessageToForward`
rg 'function getMessageToForward'

# Search for the implementation of `createKafkaMessage`
rg 'function createKafkaMessage'

Length of output: 1993



Script:

#!/bin/bash
# Description: Extract and display the code for `getMessageToForward` and `createKafkaMessage`.

# Display the implementation of `getMessageToForward`
rg -A 20 'export function getMessageToForward' indexer/services/socks/src/helpers/from-kafka-helpers.ts

# Display the implementation of `createKafkaMessage`
rg -A 20 'export function createKafkaMessage' indexer/services/socks/__tests__/helpers/kafka.ts

Length of output: 1152



Script:

#!/bin/bash
# Description: Extract and display the complete implementation of `getMessageToForward`.

# Display the complete implementation of `getMessageToForward`
rg -A 50 'export function getMessageToForward' indexer/services/socks/src/helpers/from-kafka-helpers.ts

Length of output: 1945



Script:

#!/bin/bash
# Description: Extract and display the complete implementation of `getMessageToForward` with an increased line limit.

# Display the complete implementation of `getMessageToForward`
rg -A 100 'export function getMessageToForward' indexer/services/socks/src/helpers/from-kafka-helpers.ts

Length of output: 3890


function getParentSubaccountContents(msg: SubaccountMessage): SubaccountMessageContents {
// Filter out transfers between child subaccounts of the same parent subaccount.
const contents: SubaccountMessageContents = JSON.parse(msg.contents) as SubaccountMessageContents;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorta unrelated to this change but why does SubaccountMessageContents have multiples of positions, orders, fills but only a singular transfer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's tech debt that was never fixed.

…st.ts

Co-authored-by: shrenujb <98204323+shrenujb@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b27f8e5 and 576e8d1.
Files selected for processing (1)
  • indexer/services/socks/tests/helpers/from-kafka-helpers.test.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/socks/tests/helpers/from-kafka-helpers.test.ts

@vincentwschau vincentwschau merged commit 22ac170 into main May 21, 2024
11 checks passed
@vincentwschau vincentwschau deleted the vincentc/tra-109-filter-out-transfer-websocket branch May 21, 2024 14:43
@vincentwschau
Copy link
Contributor Author

@Mergifyio backport release/indexer/v5.x

Copy link
Contributor

mergify bot commented May 23, 2024

backport release/indexer/v5.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 23, 2024
vincentwschau added a commit that referenced this pull request May 23, 2024
…nt. (backport #1544) (#1577)

Co-authored-by: vincentwschau <99756290+vincentwschau@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants