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

[IND-481] Remove market cache. #818

Merged
merged 3 commits into from
Nov 29, 2023
Merged

[IND-481] Remove market cache. #818

merged 3 commits into from
Nov 29, 2023

Conversation

lcwik
Copy link
Contributor

@lcwik lcwik commented Nov 29, 2023

Changelist

[IND-481] Remove market cache.

More clean-up in preparation of migration to SQL based block processor.

Test Plan

Updated existing 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 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.

More clean-up in preparation of migration to SQL based block processor.
Copy link

linear bot commented Nov 29, 2023

IND-481 Update ender block handler with a single SQL handler that delegates to sub-handlers

Update ender block handler with a single SQL handler that delegates to sub-handlers

Copy link
Contributor

coderabbitai bot commented Nov 29, 2023

Walkthrough

The recent updates involve the removal of marketRefresher across various components of the indexer system. This includes eliminating imports, function calls, and related logic that interacted with the marketRefresher module. The changes suggest a refactoring or redesign that has made the marketRefresher functionality obsolete or replaced it with a different mechanism for refreshing market data.

Changes

File(s) Change Summary
indexer/packages/postgres/src/index.ts Removed export of marketRefresher.
indexer/services/ender/__tests__/.../block-cache.test.ts, .../asset-handler.test.ts, .../perpetual-market-handler.test.ts, .../on-message.test.ts, .../asset-validator.test.ts, .../perpetual-market-validator.test.ts Removed imports and calls to marketRefresher methods in various test cases.
indexer/services/ender/src/caches/block-cache.ts, .../handlers/markets/market-create-handler.ts, .../market-modify-handler.ts, .../market-price-update-handler.ts, .../index.ts, .../lib/cache-manager.ts Removed imports of marketRefresher and calls to its methods in various source files.
indexer/services/ender/src/handlers/markets/.../market-create-handler.ts, .../market-modify-handler.ts, .../market-price-update-handler.ts (duplicates) Removed imports and logic related to marketRefresher, including database query result handling and market updates.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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 f9b92e5 and 24f2464.
Files selected for processing (13)
  • indexer/packages/postgres/src/index.ts (1 hunks)
  • indexer/services/ender/tests/caches/block-cache.test.ts (5 hunks)
  • indexer/services/ender/tests/handlers/asset-handler.test.ts (2 hunks)
  • indexer/services/ender/tests/handlers/perpetual-market-handler.test.ts (3 hunks)
  • indexer/services/ender/tests/lib/on-message.test.ts (3 hunks)
  • indexer/services/ender/tests/validators/asset-validator.test.ts (2 hunks)
  • indexer/services/ender/tests/validators/perpetual-market-validator.test.ts (2 hunks)
  • indexer/services/ender/src/caches/block-cache.ts (2 hunks)
  • indexer/services/ender/src/handlers/markets/market-create-handler.ts (2 hunks)
  • indexer/services/ender/src/handlers/markets/market-modify-handler.ts (2 hunks)
  • indexer/services/ender/src/handlers/markets/market-price-update-handler.ts (2 hunks)
  • indexer/services/ender/src/index.ts (2 hunks)
  • indexer/services/ender/src/lib/cache-manager.ts (2 hunks)
Files skipped from review due to trivial changes (3)
  • indexer/packages/postgres/src/index.ts
  • indexer/services/ender/tests/handlers/asset-handler.test.ts
  • indexer/services/ender/tests/handlers/perpetual-market-handler.test.ts
Additional comments: 14
indexer/services/ender/__tests__/caches/block-cache.test.ts (1)
  • 35-36: The summary states that calls to marketRefresher methods have been removed, but the hunks show calls to perpetualMarketRefresher.clear() and assetRefresher.clear(). Please verify if these are part of the intended changes and update the summary or the code accordingly.
indexer/services/ender/__tests__/lib/on-message.test.ts (2)
  • 892-902: The code still contains calls to perpetualMarketRefresher.updatePerpetualMarkets() and perpetualMarketRefresher.clear(), which should have been removed according to the summary and pull request details.
-    await perpetualMarketRefresher.updatePerpetualMarkets();
-    assetRefresher.clear();
-    perpetualMarketRefresher.clear();
  • 906-909: The code still contains calls to perpetualMarketRefresher.getPerpetualMarketsMap(), which should have been removed according to the summary and pull request details.
-    expect(perpetualMarketRefresher.getPerpetualMarketsMap()).not.toEqual({});
indexer/services/ender/__tests__/validators/asset-validator.test.ts (2)
  • 1-6:
    The removal of marketRefresher from the import statement is consistent with the summary and pull request description.

  • 15-19:
    The beforeEach hook has been correctly updated to remove the call to marketRefresher.updateMarkets(), aligning with the changes described in the summary and pull request.

indexer/services/ender/src/caches/block-cache.ts (2)
  • 5-9: The import statements for perpetualMarketRefresher and assetRefresher are still present, which is consistent with the pull request summary that does not mention their removal.

  • 110-113: The calls to perpetualMarketRefresher.updatePerpetualMarkets({ txId }) and assetRefresher.updateAssets({ txId }) are still present, which aligns with the pull request summary that does not state their removal.

indexer/services/ender/src/handlers/markets/market-create-handler.ts (2)
  • 2-6: The removal of marketRefresher is consistent with the summary and pull request description. Ensure that the removal of this functionality does not leave any orphaned code or logic that depends on the removed functionality elsewhere in the codebase.

  • 51-56: The logic for updating the market cache has been removed from the MarketCreateHandler. Verify that this change aligns with the intended system behavior and that no other parts of the system are adversely affected by the removal of this functionality.

indexer/services/ender/src/handlers/markets/market-modify-handler.ts (1)
  • 55-56: The method internalHandle() is now returning an empty array, which is consistent with the summary stating that the return type has been changed to void. However, the method signature still indicates that it returns an array. Please verify if the method signature should be updated to reflect that it now returns void, or if the implementation should be changed to match the expected return type.
indexer/services/ender/src/handlers/markets/market-price-update-handler.ts (2)
  • 3-9: The removal of marketRefresher from the imports is consistent with the summary and pull request description.

  • 62-67: The code within MarketPriceUpdateHandler has been updated to remove the market cache update logic, which is consistent with the summary and pull request description.

indexer/services/ender/src/index.ts (2)
  • 3-5: The import statement for marketRefresher is still present, which might be an oversight if it's no longer used in the file. Please verify if marketRefresher is used elsewhere in the file or if the import should be removed.

  • 24-28: The changes to the startKafka function reflect the removal of the marketRefresher.updateMarkets() call, which aligns with the intent to remove the market cache functionality. This change appears to be correct and consistent with the summary and pull request.

@@ -13,7 +12,6 @@ export async function refreshDataCaches(): Promise<void> {
await Promise.all([
perpetualMarketRefresher.updatePerpetualMarkets({ txId, readReplica: true }),
assetRefresher.updateAssets({ txId, readReplica: true }),
marketRefresher.updateMarkets({ txId, readReplica: true }),
]);

await Transaction.rollback(txId);
Copy link
Contributor

Choose a reason for hiding this comment

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

The refreshDataCaches function ends with a rollback, which undoes any changes made within the transaction. This could be an error unless intentionally designed to simulate the updates without persisting them. Please verify the intended behavior.

-  await Transaction.rollback(txId);
+  await Transaction.commit(txId);

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
await Transaction.rollback(txId);
await Transaction.commit(txId);

@@ -1,7 +1,7 @@
import { logger, ParseMessageError } from '@dydxprotocol-indexer/base';
import { PerpetualMarketCreateEventV1, IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos';
import {
dbHelpers, marketRefresher, testMocks, perpetualMarketRefresher,
dbHelpers, testMocks, perpetualMarketRefresher,
Copy link
Contributor

Choose a reason for hiding this comment

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

The import of perpetualMarketRefresher should be removed as per the summary of changes.

-  dbHelpers, testMocks, perpetualMarketRefresher,
+  dbHelpers, testMocks,

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
dbHelpers, testMocks, perpetualMarketRefresher,
dbHelpers, testMocks,

Comment on lines 1 to 7
import { logger, ParseMessageError } from '@dydxprotocol-indexer/base';
import { PerpetualMarketCreateEventV1, IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos';
import {
dbHelpers, marketRefresher, testMocks, perpetualMarketRefresher,
dbHelpers, testMocks, perpetualMarketRefresher,
} from '@dydxprotocol-indexer/postgres';
import { DydxIndexerSubtypes } from '../../src/lib/types';
import {
Copy link
Contributor

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 patches, and no patch overlapping with it was found. Original lines [24-24]

The call to perpetualMarketRefresher.clear() in the afterEach hook should be removed as it is no longer necessary with the removal of the market cache functionality.

-    await perpetualMarketRefresher.clear();

Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [34-34]

The call to perpetualMarketRefresher.updatePerpetualMarkets() in the test case for 'throws error on existing perpetual market' should be removed as it is no longer necessary with the removal of the market cache functionality.

-      await perpetualMarketRefresher.updatePerpetualMarkets();

Comment on lines 79 to 80
expect(perpetualMarketRefresher.getPerpetualMarketsMap()).not.toEqual({});
expect(assetRefresher.getAssetsMap()).not.toEqual({});
Copy link
Contributor

Choose a reason for hiding this comment

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

The summary indicates that references to marketRefresher have been removed, but the test assertions still check the state of perpetualMarketRefresher.getPerpetualMarketsMap() and assetRefresher.getAssetsMap(). These assertions should be removed if marketRefresher and its methods are no longer used.

Comment on lines 90 to 91
expect(perpetualMarketRefresher.getPerpetualMarketsMap()).toEqual({});
expect(assetRefresher.getAssetsMap()).toEqual({});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test setup still contains calls to perpetualMarketRefresher.getPerpetualMarketsMap() and assetRefresher.getAssetsMap(), which should be removed according to the summary that states all references to marketRefresher have been removed.

Comment on lines 98 to 99
expect(perpetualMarketRefresher.getPerpetualMarketsMap()).not.toEqual({});
expect(assetRefresher.getAssetsMap()).not.toEqual({});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test assertions still check the state of perpetualMarketRefresher.getPerpetualMarketsMap() and assetRefresher.getAssetsMap(). If these are related to the marketRefresher that was removed, these assertions should also be removed.

@@ -111,7 +110,6 @@ export async function initializeAllCaches(): Promise<void> {
startCandleCache(txId),
perpetualMarketRefresher.updatePerpetualMarkets({ txId }),
assetRefresher.updateAssets({ txId }),
marketRefresher.updateMarkets({ txId }),
]);

await Transaction.rollback(txId);
Copy link
Contributor

Choose a reason for hiding this comment

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

The transaction in initializeAllCaches is being rolled back at the end of the function. This would undo any updates made by the refresh functions. If this is not intentional, it should be replaced with a commit.

-  await Transaction.rollback(txId);
+  await Transaction.commit(txId);

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
await Transaction.rollback(txId);
await Transaction.commit(txId);

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 24f2464 and d8e593a.
Files selected for processing (3)
  • indexer/services/ender/src/handlers/markets/market-create-handler.ts (3 hunks)
  • indexer/services/ender/src/handlers/markets/market-modify-handler.ts (3 hunks)
  • indexer/services/ender/src/handlers/markets/market-price-update-handler.ts (2 hunks)
Additional comments: 5
indexer/services/ender/src/handlers/markets/market-create-handler.ts (3)
  • 25-29: The changes from lines 25 to 29 show the updated rawQuery call without assigning the result to a variable, which is consistent with the summary. However, ensure that the lack of assignment does not affect any downstream logic that may have depended on the result of this query.

  • 46-46: The error handling logic on line 46 rethrows the error if it does not match the specific condition checked. Ensure that this behavior is intended and that there are no additional error cases that need to be handled here.

  • 49-49: The function now returns an empty array on line 49. Confirm that this is the intended behavior and that the consumers of this function are expecting an empty array as a valid response.

indexer/services/ender/src/handlers/markets/market-modify-handler.ts (1)
  • 52-53: The function internalHandle is still returning an empty array, which contradicts the summary stating that the return type has changed to void. Please verify if the return type should indeed be void or if the summary needs to be updated.
-    return [];
+    return; // If the function should return void
indexer/services/ender/src/handlers/markets/market-price-update-handler.ts (1)
  • 3-9: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [3-67]

The changes in the MarketPriceUpdateHandler class reflect the removal of the marketRefresher utility and its associated calls. The class now handles market price updates by directly querying the database and generating Kafka events, which aligns with the new architecture described in the pull request summary. The error handling and logging within the internalHandle method are appropriate, and the generateKafkaEvent method is correctly implemented to create the necessary Kafka event. Ensure that all dependent services and components are compatible with these changes and that the removal of the marketRefresher does not introduce any regressions or unexpected behavior.

@lcwik lcwik merged commit 1973bc2 into main Nov 29, 2023
11 checks passed
@lcwik lcwik deleted the lukeind481.2 branch November 29, 2023 17:31
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