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

[OTE-130] implement new geo-blocking strategy for socks #1049

Merged
merged 6 commits into from
Feb 26, 2024
Merged

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Feb 6, 2024

Changelist

remove geoblocking from socks endpoints:

  • v4_markets channel
  • v4_orderbooks channel
  • v4_trades channel

add the country header from the connection request to the request sent to comlink to enable blocking subscriptions to v4_subaccount

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.

Copy link

coderabbitai bot commented Feb 6, 2024

Walkthrough

The changes involve removing geoblocking features from the WebSocket service of the indexer. This includes the deletion of imports and code related to country restrictions, specifically the CountryRestrictor class and related compliance checks. Instead, a new approach is introduced with the header-utils.ts file, which includes a getCountry function to extract the country code from request headers, simplifying the process of handling country information without enforcing restrictions.

Changes

File Path Change Summary
.../__tests__/lib/subscriptions.test.ts Removed functionality related to checking restricted countries, including references to isRestrictedCountry and nonRestrictedCountry.
.../socks/src/lib/subscription.ts Removed country parameter from method signatures in Subscriptions class, adjusted method calls, and eliminated country-based blocking logic.
.../socks/src/helpers/header-utils.ts Added new file with getCountry function to extract the country code from incoming request headers.
.../socks/src/websocket/index.ts Removed CountryRestrictor class, imported and used getCountry from header-utils for retrieving country codes, altering country restriction logic.

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-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 from git 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.

Copy link

@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 a6ca7b8 and 984f3e7.
Files selected for processing (3)
  • indexer/services/socks/tests/websocket/index.test.ts (4 hunks)
  • indexer/services/socks/src/helpers/header-utils.ts (1 hunks)
  • indexer/services/socks/src/websocket/index.ts (4 hunks)
Additional comments: 4
indexer/services/socks/src/helpers/header-utils.ts (1)
  • 5-8: The implementation of getCountry function is correct and aligns with the PR's objective of handling country information without imposing restrictions. It properly uses TypeScript's type assertion to ensure the request headers include the expected cf-ipcountry property. This approach is both efficient and maintainable.
indexer/services/socks/__tests__/websocket/index.test.ts (1)
  • 17-17: The introduction of COUNTRY_HEADER_KEY from @dydxprotocol-indexer/compliance in the test file is appropriate and aligns with the PR's objectives of handling country information differently after the removal of geoblocking functionality. This change ensures that the tests accurately reflect the updated logic in the main codebase.
indexer/services/socks/src/websocket/index.ts (2)
  • 8-8: The import of getCountry from header-utils is correctly implemented and aligns with the PR's objective of handling country information without imposing restrictions. This change is necessary for the WebSocket service to adapt to the removal of geoblocking functionality.
  • 106-106: The usage of getCountry within the onConnection method to extract the country code from incoming requests is appropriate and aligns with the PR's objectives. This approach ensures that the WebSocket service can identify country information without enforcing access restrictions, which is consistent with the removal of geoblocking functionality.

Copy link

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 984f3e7 and 9d850b7.
Files selected for processing (2)
  • indexer/services/socks/tests/lib/subscriptions.test.ts (8 hunks)
  • indexer/services/socks/src/lib/subscription.ts (5 hunks)
Additional comments: 2
indexer/services/socks/src/lib/subscription.ts (2)
  • 132-132: The removal of geoblocking logic, including the elimination of country-based checks, is consistent with the PR's objectives. However, ensure that the removal of this logic does not inadvertently affect other functionalities, especially error handling and rate limiting. It's also important to verify that the new approach to handling country information, as indicated by the introduction of header-utils.ts in the PR summary, is adequately integrated and tested within the subscription logic.
  • 576-576: With the removal of geoblocking functionality, it's essential to ensure that the new method for handling country information (getCountry from header-utils.ts) is properly integrated into the subscription process, especially for functionalities that might still require country information for non-restrictive purposes. This integration should be seamless and maintain the service's overall functionality and performance.

Comment on lines 10 to 15
import { axiosRequest } from '../../src/lib/axios';
import { AxiosSafeServerError, makeAxiosSafeServerError } from '@dydxprotocol-indexer/base';
import { BlockedError } from '../../src/lib/errors';
import { isRestrictedCountry } from '@dydxprotocol-indexer/compliance';

jest.mock('ws');
jest.mock('../../src/helpers/wss');
Copy link

Choose a reason for hiding this comment

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

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

The removal of geoblocking functionality, including references to restrictedCountry and nonRestrictedCountry, aligns with the PR's objectives. However, it's crucial to ensure that the removal of these tests does not reduce the coverage of other important functionalities within the Subscriptions class. Consider adding or enhancing tests to cover any new logic introduced or existing logic that may now behave differently without geoblocking.

Copy link

@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 9d850b7 and 8b1f4c0.
Files selected for processing (2)
  • indexer/services/socks/tests/lib/subscriptions.test.ts (9 hunks)
  • indexer/services/socks/src/lib/subscription.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • indexer/services/socks/tests/lib/subscriptions.test.ts
  • indexer/services/socks/src/lib/subscription.ts

Copy link

@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 8b1f4c0 and 25f7f07.
Files selected for processing (2)
  • indexer/services/socks/tests/lib/subscriptions.test.ts (14 hunks)
  • indexer/services/socks/src/lib/subscription.ts (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • indexer/services/socks/tests/lib/subscriptions.test.ts
  • indexer/services/socks/src/lib/subscription.ts

@dydxwill dydxwill changed the title remove geoblocking from socks endpoints [OTE-130] remove geoblocking from socks endpoints Feb 21, 2024
Copy link

linear bot commented Feb 21, 2024

@dydxwill dydxwill changed the title [OTE-130] remove geoblocking from socks endpoints [OTE-130] implement geo-blocking for socks Feb 21, 2024
@dydxwill dydxwill changed the title [OTE-130] implement geo-blocking for socks [OTE-130] implement new geo-blocking strategy for socks Feb 21, 2024
@dydxwill dydxwill merged commit 48e582b into main Feb 26, 2024
11 checks passed
@dydxwill dydxwill deleted the wl/s2 branch February 26, 2024 17:27
dydxwill added a commit that referenced this pull request Mar 5, 2024
* remove geoblocking from Indexer endpoints (#1029)

* [OTE-130] implement new geo-blocking strategy for socks (#1049)
dydxwill added a commit that referenced this pull request Mar 5, 2024
* remove geoblocking from Indexer endpoints (#1029)

* [OTE-130] implement new geo-blocking strategy for socks (#1049)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants