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

Do not overwrite existing CLOSE_ONLY/BLOCKED compliance statuses #1926

Merged
merged 6 commits into from
Jul 17, 2024

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Jul 16, 2024

Changelist

Do not overwrite existing CLOSE_ONLY/BLOCKED compliance statuses

Test Plan

Unit tested

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

    • Introduced more granular compliance status filtering, differentiating between statuses like "close only" and "blocked".
  • Bug Fixes

    • Enhanced test cases to verify updates on active addresses without affecting existing "close only" positions.
  • Improvements

    • Extended compliance status queries to support multiple status values, improving the flexibility of compliance data updates.

Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Walkthrough

The changes primarily involve enhancing the handling of compliance status data within the system. The updates include modifying import entities, altering the logic for filtering compliance statuses, and enabling the handling of multiple compliance statuses in queries. Additionally, a new test case was added to verify the updated compliance status behavior. These modifications aim to improve the efficiency and accuracy of compliance status updates and queries.

Changes

File Change Summary
.../src/tasks/update-compliance-data.ts Modified imports and runTask function logic, introduced new variables for filtering compliance status objects.
.../src/tasks/perform-compliance-status-transitions.ts Changed the status property handling to support arrays for compliance statuses.
.../query-types.ts Updated ComplianceStatusQueryConfig interface to allow arrays for STATUS field.
.../compliance-status-table.ts Altered findAll function to use whereIn for filtering by status.
.../compliance-status-table.test.ts Modified test to handle array of compliance statuses in ComplianceStatusTable.findAll method call.
.../update-compliance-data.test.ts Added a test case for updating compliance data without altering existing CLOSE_ONLY positions.

Sequence Diagram(s)

sequenceDiagram
    participant Task as update-compliance-data.ts
    participant DB as ComplianceStatusTable
    participant Status as ComplianceStatusFromDatabase
    
    Task->>DB: Fetch compliance statuses
    DB-->>Task: Return statuses as array
    Task->>Status: Process and filter statuses
    Status-->>Task: Return filtered statuses
    Task->>DB: Upsert filtered compliance statuses
    DB-->>Task: Confirmation of upsert
Loading

Poem

🐰 In the code, new changes flow,
Compliance statuses in tow.
Filter, query, in arrays they stay,
Ensuring data’s bright all day.
Tests to guard, updates to prize,
Our system now complies, so wise.
🌟


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

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.

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

Outside diff range, codebase verification and nitpick comments (1)
indexer/services/roundtable/src/tasks/update-compliance-data.ts (1)

Line range hint 186-212: Approve changes but consider performance implications.

The introduction of closeOnlyStatuses and closeOnlyAddresses to filter compliance status updates aligns with the PR objectives. However, consider the performance impact of these operations, especially with large datasets.

Consider implementing more efficient querying or caching mechanisms if performance issues arise.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af58e6c and bb3d920.

Files selected for processing (1)
  • indexer/services/roundtable/src/tasks/update-compliance-data.ts (4 hunks)
Additional comments not posted (2)
indexer/services/roundtable/src/tasks/update-compliance-data.ts (2)

9-12: Verify correct integration of new imports.

New entities ComplianceStatusFromDatabase and ComplianceStatusUpsertObject have been introduced, and ComplianceTable has been reordered. Ensure that these changes are integrated correctly throughout the codebase.

Verification successful

Verified correct integration of new imports.

The new entities ComplianceStatusFromDatabase, ComplianceStatusUpsertObject, and ComplianceTable are used correctly across the codebase, including in test files and other modules. No issues were found related to their integration.

  • ComplianceStatusFromDatabase and ComplianceStatusUpsertObject are used in multiple files, including compliance-status-table.test.ts and update-compliance-data.ts.
  • ComplianceTable is used in files like update-compliance-data.ts and compliance-controller.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify integration of new imports in the codebase.

# Test: Search for the usage of new imports. Expect: Correct usage patterns.
rg --type typescript -A 5 $'ComplianceStatusFromDatabase|ComplianceStatusUpsertObject|ComplianceTable'

Length of output: 138


Script:

#!/bin/bash
# Description: Verify integration of new imports in the codebase.

# Test: Search for the usage of new imports. Expect: Correct usage patterns.
rg --type ts -A 5 $'ComplianceStatusFromDatabase|ComplianceStatusUpsertObject|ComplianceTable'

Length of output: 64906


283-289: Verify and enhance error handling.

The error handling in getComplianceData function logs failed compliance data retrievals. Verify that the error details provided are sufficient for troubleshooting and consider enhancing the error logging to include more contextual information if necessary.

Verification successful

Error handling in getComplianceData function is sufficient.

The error logging in the getComplianceData function includes detailed contextual information, making it adequate for troubleshooting.

  • indexer/services/roundtable/src/tasks/update-compliance-data.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error logging details.

# Test: Search for error logging patterns. Expect: Sufficient contextual information in logs.
rg --type typescript -A 5 $'logger.error'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify error logging details.

# Test: Search for error logging patterns. Expect: Sufficient contextual information in logs.
rg --glob '*.ts' -A 5 'logger.error'

Length of output: 80631

@dydxwill dydxwill changed the title Do not overwrite existing CLOSE_ONLY updatedAt field Do not overwrite existing CLOSE_ONLY/BLOCKED compliance statuses Jul 16, 2024
Comment on lines 186 to 198
const closeOnlyStatuses: ComplianceStatusFromDatabase[] = await
ComplianceStatusTable.findAll(
{
address: addressesToQuery,
status: [ComplianceStatus.CLOSE_ONLY, ComplianceStatus.BLOCKED],
},
[],
);
const closeOnlyAddresses: string[] = _.chain(closeOnlyStatuses)
.map(ComplianceDataColumns.address)
.uniq()
.value();

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to exclude these addresses earlier than here? There's already been a query made to the compliance provider by this filter and the results for these addresses will then be un-used by still charged for.

},
[],
);
const closeOnlyAddresses: string[] = _.chain(closeOnlyAndBlockedStatuses)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: closeOnlyAndBlockedAddresses

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 bb3d920 and 427f16e.

Files selected for processing (6)
  • indexer/packages/postgres/tests/stores/compliance-status-table.test.ts (1 hunks)
  • indexer/packages/postgres/src/stores/compliance-status-table.ts (1 hunks)
  • indexer/packages/postgres/src/types/query-types.ts (1 hunks)
  • indexer/services/roundtable/tests/tasks/update-compliance-data.test.ts (1 hunks)
  • indexer/services/roundtable/src/tasks/perform-compliance-status-transitions.ts (1 hunks)
  • indexer/services/roundtable/src/tasks/update-compliance-data.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/roundtable/src/tasks/update-compliance-data.ts
Additional comments not posted (5)
indexer/services/roundtable/src/tasks/perform-compliance-status-transitions.ts (1)

24-24: Updated status query to handle arrays.

The change to accept an array for the status field instead of a single value is a significant improvement for flexibility in querying. This allows the function to handle multiple statuses at once, which is crucial for robust compliance management.

indexer/packages/postgres/src/stores/compliance-status-table.ts (1)

62-62: Use of whereIn for status filtering.

The modification to use whereIn for the status field supports the handling of multiple statuses in queries, enhancing the flexibility and robustness of the database operations. This is a positive change in line with the PR's objectives.

indexer/packages/postgres/__tests__/stores/compliance-status-table.test.ts (1)

101-101: Updated test to reflect new array input for status.

The test modification to handle an array for the status field is necessary to ensure that the new functionality is correctly tested. This change ensures that the tests align with the updated querying capabilities.

indexer/packages/postgres/src/types/query-types.ts (1)

286-286: Updated interface to handle array of statuses.

The change to allow an array of strings for the STATUS field in the ComplianceStatusQueryConfig interface is a necessary update to support the new querying capabilities. This ensures that the type definitions are consistent with the new functionality.

indexer/services/roundtable/__tests__/tasks/update-compliance-data.test.ts (1)

252-286: Test Case Review: Ensuring CLOSE_ONLY positions are not updated

This test case is crucial as it directly addresses the core functionality introduced in this PR. It specifically tests that an existing CLOSE_ONLY compliance status is not overwritten even when new compliance data is available.

  • Correctness: The test correctly sets up the scenario by creating a compliance status with CLOSE_ONLY and then running the updateComplianceDataTask. After the task, it checks that the status remains unchanged.
  • Completeness: The test appears to cover all necessary assertions to ensure the status is not updated.
  • Readability: The test is well-structured and easy to understand, with clear setup, action, and assertion phases.

Overall, this test case effectively validates the new behavior introduced in the PR. It's a good practice to include such targeted tests to ensure critical functionality is not regressed by future changes.

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 427f16e and 3dc9af5.

Files selected for processing (1)
  • indexer/services/roundtable/src/tasks/update-compliance-data.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/roundtable/src/tasks/update-compliance-data.ts

@dydxwill dydxwill merged commit a68a31e into main Jul 17, 2024
11 checks passed
@dydxwill dydxwill deleted the wl/rt12 branch July 17, 2024 15:57
@dydxwill
Copy link
Contributor Author

@Mergifyio backport release/indexer/v5.x

Copy link
Contributor

mergify bot commented Jul 17, 2024

backport release/indexer/v5.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jul 17, 2024
dydxwill added a commit that referenced this pull request Jul 17, 2024
…kport #1926) (#1930)

Co-authored-by: dydxwill <119354122+dydxwill@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.

3 participants