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-487] Move currency pair id cache to store #2072

Merged
merged 16 commits into from
Sep 16, 2024

Conversation

chenyaoy
Copy link
Contributor

@chenyaoy chenyaoy commented Aug 9, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

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
    • Added new caching methods to improve currency pair management within the Keeper structure.
    • Introduced a new method for retrieving market parameters that enhances data management.
    • Enhanced upgrade functionality to initialize currency pair ID cache during upgrades.
    • Added functionality to handle addition and removal of currency pair IDs in the store.
  • Bug Fixes
    • Improved error handling and logging in cache management during market parameter updates.
    • Added error handling for invalid market pair formats during modifications.
  • Refactor
    • Streamlined the Keeper struct by removing unnecessary methods to enhance maintainability.
    • Enhanced method organization for better encapsulation and abstraction within the Keeper.
  • Tests
    • Increased test coverage for caching mechanisms related to currency pairs.
    • Added post-upgrade checks for currency pair ID cache state to enhance testing logic.
    • New test case for validating error handling when invalid market pair formats are provided.

Copy link
Contributor

coderabbitai bot commented Aug 9, 2024

Walkthrough

The recent updates across various files involve significant refactoring within the Keeper struct to enhance currency pair management, including the introduction of new methods and improved error handling. The changes aim to simplify state management, improve code maintainability, and ensure robust caching mechanisms without altering core functionality. Additionally, unit tests have been enhanced to improve coverage and reliability.

Changes

Files Change Summary
protocol/x/prices/keeper/*.go Refactored methods for currency pair management, introduced new caching methods, and enhanced error handling.
protocol/x/prices/keeper/market_param.go Improved handling for updating market parameters, including enhanced error checking; removed obsolete functions.
protocol/x/prices/keeper/slinky_adapter.go Added methods for efficient cache management and improved logic for retrieving currency pair IDs.
protocol/x/prices/types/keys_test.go Added assertion to verify CurrencyPairIDPrefix.
protocol/app/upgrades/*.go Modified upgrade handling to include PricesKeeper and added a new function for initializing currency pair ID cache.
protocol/app/upgrades/v7.0.0/*.go Added post-upgrade checks and new functions for managing currency pair ID cache state.
protocol/mocks/PricesKeeper.go Updated mock implementation to reflect new methods and removed obsolete functions.
protocol/mocks/SubaccountsKeeper.go Added new mock functions for handling subaccount updates.
protocol/mocks/VaultKeeper.go Removed obsolete mock function related to vault operations.
protocol/x/prices/keeper/slinky_adapter_test.go Updated test assertions to ensure accurate behavior of currency pair retrieval methods.
protocol/x/prices/keeper/market_param_test.go Added test case for error handling in market parameter modification.

Possibly related PRs

Suggested labels

indexer, proto

🐰 "In the code, we hop along,
With mocks and keys, we sing a song.
Version bumps and cleaner ways,
Enhance our code through sunny days!
With every change, we celebrate,
A brighter future, oh so great!" 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d4523c4 and 049d575.

Files selected for processing (2)
  • protocol/x/prices/keeper/market_param.go (1 hunks)
  • protocol/x/prices/keeper/market_param_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/prices/keeper/market_param_test.go
Additional comments not posted (2)
protocol/x/prices/keeper/market_param.go (2)

69-77: LGTM!

The error handling for the old market pair conversion and removal from the store is implemented correctly. The code now returns an error if the conversion fails, as suggested in the past review comment.


80-88: Looks good!

The addition of the new currency pair ID to the store is handled correctly. The error handling for the new market pair conversion is consistent with the handling of the old market pair conversion.


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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

@chenyaoy
Copy link
Contributor Author

chenyaoy commented Aug 9, 2024

I'll add upgrade handler to add CurrencyPairID for existing markets in a separate PR

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 3930d14 and d51c012.

Files selected for processing (62)
  • protocol/mocks/AnteDecorator.go (1 hunks)
  • protocol/mocks/AppOptions.go (1 hunks)
  • protocol/mocks/BankKeeper.go (1 hunks)
  • protocol/mocks/BridgeKeeper.go (1 hunks)
  • protocol/mocks/BridgeQueryClient.go (1 hunks)
  • protocol/mocks/BridgeServiceClient.go (1 hunks)
  • protocol/mocks/CacheMultiStore.go (1 hunks)
  • protocol/mocks/ClobKeeper.go (1 hunks)
  • protocol/mocks/Configurator.go (1 hunks)
  • protocol/mocks/DelayMsgKeeper.go (1 hunks)
  • protocol/mocks/EthClient.go (1 hunks)
  • protocol/mocks/ExchangeConfigUpdater.go (1 hunks)
  • protocol/mocks/ExchangeQueryHandler.go (1 hunks)
  • protocol/mocks/ExchangeToMarketPrices.go (1 hunks)
  • protocol/mocks/ExtendVoteHandler.go (1 hunks)
  • protocol/mocks/FileHandler.go (1 hunks)
  • protocol/mocks/GrpcClient.go (1 hunks)
  • protocol/mocks/GrpcServer.go (1 hunks)
  • protocol/mocks/HealthCheckable.go (1 hunks)
  • protocol/mocks/IndexerEventManager.go (1 hunks)
  • protocol/mocks/IndexerMessageSender.go (1 hunks)
  • protocol/mocks/Logger.go (1 hunks)
  • protocol/mocks/MarketPairFetcher.go (1 hunks)
  • protocol/mocks/MemClob.go (1 hunks)
  • protocol/mocks/MemClobKeeper.go (1 hunks)
  • protocol/mocks/MsgRouter.go (1 hunks)
  • protocol/mocks/MultiStore.go (1 hunks)
  • protocol/mocks/OracleClient.go (1 hunks)
  • protocol/mocks/PerpetualsClobKeeper.go (1 hunks)
  • protocol/mocks/PerpetualsKeeper.go (1 hunks)
  • protocol/mocks/PrepareBridgeKeeper.go (1 hunks)
  • protocol/mocks/PrepareClobKeeper.go (1 hunks)
  • protocol/mocks/PreparePerpetualsKeeper.go (1 hunks)
  • protocol/mocks/PriceFeedMutableMarketConfigs.go (1 hunks)
  • protocol/mocks/PriceFetcher.go (1 hunks)
  • protocol/mocks/PriceUpdateGenerator.go (1 hunks)
  • protocol/mocks/PricesKeeper.go (2 hunks)
  • protocol/mocks/ProcessBridgeKeeper.go (1 hunks)
  • protocol/mocks/ProcessClobKeeper.go (1 hunks)
  • protocol/mocks/ProcessPerpetualKeeper.go (1 hunks)
  • protocol/mocks/ProcessStakingKeeper.go (1 hunks)
  • protocol/mocks/QueryClient.go (1 hunks)
  • protocol/mocks/QueryServer.go (1 hunks)
  • protocol/mocks/RequestHandler.go (1 hunks)
  • protocol/mocks/SendingKeeper.go (1 hunks)
  • protocol/mocks/Server.go (1 hunks)
  • protocol/mocks/SubaccountsKeeper.go (1 hunks)
  • protocol/mocks/TimeProvider.go (1 hunks)
  • protocol/mocks/TxBuilder.go (1 hunks)
  • protocol/mocks/TxConfig.go (1 hunks)
  • protocol/mocks/UpdateMarketPriceTxDecoder.go (1 hunks)
  • protocol/mocks/VaultKeeper.go (1 hunks)
  • protocol/x/prices/keeper/keeper.go (4 hunks)
  • protocol/x/prices/keeper/market.go (1 hunks)
  • protocol/x/prices/keeper/market_param.go (2 hunks)
  • protocol/x/prices/keeper/market_test.go (2 hunks)
  • protocol/x/prices/keeper/slinky_adapter.go (4 hunks)
  • protocol/x/prices/keeper/slinky_adapter_test.go (2 hunks)
  • protocol/x/prices/module.go (3 hunks)
  • protocol/x/prices/types/keys.go (1 hunks)
  • protocol/x/prices/types/keys_test.go (1 hunks)
  • protocol/x/prices/types/types.go (1 hunks)
Files skipped from review due to trivial changes (51)
  • protocol/mocks/AnteDecorator.go
  • protocol/mocks/AppOptions.go
  • protocol/mocks/BankKeeper.go
  • protocol/mocks/BridgeKeeper.go
  • protocol/mocks/BridgeQueryClient.go
  • protocol/mocks/BridgeServiceClient.go
  • protocol/mocks/CacheMultiStore.go
  • protocol/mocks/ClobKeeper.go
  • protocol/mocks/Configurator.go
  • protocol/mocks/DelayMsgKeeper.go
  • protocol/mocks/EthClient.go
  • protocol/mocks/ExchangeConfigUpdater.go
  • protocol/mocks/ExchangeQueryHandler.go
  • protocol/mocks/ExchangeToMarketPrices.go
  • protocol/mocks/ExtendVoteHandler.go
  • protocol/mocks/FileHandler.go
  • protocol/mocks/GrpcClient.go
  • protocol/mocks/GrpcServer.go
  • protocol/mocks/HealthCheckable.go
  • protocol/mocks/IndexerEventManager.go
  • protocol/mocks/IndexerMessageSender.go
  • protocol/mocks/Logger.go
  • protocol/mocks/MarketPairFetcher.go
  • protocol/mocks/MemClob.go
  • protocol/mocks/MemClobKeeper.go
  • protocol/mocks/MsgRouter.go
  • protocol/mocks/MultiStore.go
  • protocol/mocks/OracleClient.go
  • protocol/mocks/PerpetualsClobKeeper.go
  • protocol/mocks/PerpetualsKeeper.go
  • protocol/mocks/PrepareBridgeKeeper.go
  • protocol/mocks/PrepareClobKeeper.go
  • protocol/mocks/PreparePerpetualsKeeper.go
  • protocol/mocks/PriceFeedMutableMarketConfigs.go
  • protocol/mocks/PriceFetcher.go
  • protocol/mocks/PriceUpdateGenerator.go
  • protocol/mocks/ProcessBridgeKeeper.go
  • protocol/mocks/ProcessClobKeeper.go
  • protocol/mocks/ProcessPerpetualKeeper.go
  • protocol/mocks/ProcessStakingKeeper.go
  • protocol/mocks/QueryClient.go
  • protocol/mocks/QueryServer.go
  • protocol/mocks/RequestHandler.go
  • protocol/mocks/SendingKeeper.go
  • protocol/mocks/Server.go
  • protocol/mocks/SubaccountsKeeper.go
  • protocol/mocks/TimeProvider.go
  • protocol/mocks/TxBuilder.go
  • protocol/mocks/TxConfig.go
  • protocol/mocks/UpdateMarketPriceTxDecoder.go
  • protocol/mocks/VaultKeeper.go
Additional comments not posted (18)
protocol/x/prices/types/keys_test.go (1)

18-19: Good addition to test coverage.

The new assertion in TestStateKeys ensures that the CurrencyPairIDPrefix is correctly defined, enhancing test coverage.

protocol/x/prices/types/keys.go (1)

20-22: Addition of CurrencyPairIDPrefix enhances key management.

The introduction of CurrencyPairIDPrefix provides a clear and explicit key prefix for currency pair IDs, improving semantic clarity in key management.

protocol/x/prices/types/types.go (1)

Line range hint 13-61:
Simplification of PricesKeeper interface.

The removal of InitializeCurrencyPairIdCache simplifies the PricesKeeper interface. Ensure that the initialization logic is correctly handled elsewhere if needed.

Verification successful

Removal of InitializeCurrencyPairIdCache is Appropriately Handled

The cache management logic, specifically the use of AddCurrencyPairIDToCache, ensures that currency pair IDs are added to the cache as needed within the market operations. This indicates that the removal of InitializeCurrencyPairIdCache from the PricesKeeper interface does not adversely affect the codebase. The initialization and management of the cache are effectively integrated into the existing logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the removal of `InitializeCurrencyPairIdCache` has any impact.

# Test: Search for any usage of `InitializeCurrencyPairIdCache`. Expect: No occurrences.
rg --type go 'InitializeCurrencyPairIdCache'

Length of output: 44


Script:

#!/bin/bash
# Search for any comments or methods related to currency pair ID initialization.
rg --type go 'currency pair id|initialization|cache'

Length of output: 18733


Script:

#!/bin/bash
# Extract relevant sections from market.go to verify cache handling logic.
rg --type go 'currency-pair-id cache' -A 5 -B 5 protocol/x/prices/keeper/market.go

Length of output: 455

protocol/x/prices/keeper/keeper.go (2)

43-50: Refactor: Simplified NewKeeper function.

The NewKeeper function no longer initializes the removed cache fields. Ensure that this simplification aligns with the new caching strategy and that the Keeper initialization remains complete and correct.


19-26: Refactor: Removed cache fields from Keeper struct.

The currencyPairIDCache and currencyPairIdCacheInitialized fields have been removed from the Keeper struct. This change likely indicates a refactoring of the caching mechanism. Ensure that the new caching strategy is well-documented and integrated into the system.

Verification successful

No references found for removed cache fields.

The fields currencyPairIDCache and currencyPairIdCacheInitialized were removed from the Keeper struct and are not referenced elsewhere in the codebase. This suggests that their removal is part of a refactoring effort and does not impact other parts of the system. Ensure that any new caching strategy is well-documented and integrated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if the removed fields `currencyPairIDCache` and `currencyPairIdCacheInitialized` are used elsewhere in the codebase.

# Test: Search for references to the removed fields.
rg --type go 'currencyPairIDCache|currencyPairIdCacheInitialized'

Length of output: 67

protocol/x/prices/keeper/slinky_adapter_test.go (2)

29-29: Improvement: Use require.False for clarity.

The assertion require.False(t, found) improves readability and clearly communicates the test's intent. This change ensures the test accurately reflects the expected behavior.


53-53: Improvement: Use require.False for clarity.

The assertion require.False(t, found) enhances readability and aligns with the test's purpose, ensuring the expected behavior is clearly communicated.

protocol/x/prices/keeper/market_param.go (2)

60-65: Improvement: Enhanced error handling when removing old currency pair.

The code now logs an error if removing the old currency pair from the cache fails. This improvement provides better visibility into potential issues during cache updates.


68-72: Improvement: Enhanced error handling when adding new currency pair.

The code now logs an error if adding the new currency pair to the cache fails. This change improves error visibility and aids in troubleshooting.

protocol/x/prices/keeper/slinky_adapter.go (5)

26-29: LGTM!

The getCurrencyPairIDStore method correctly initializes a prefix store for currency pair IDs.


87-99: LGTM!

The methods AddCurrencyPairIDToCache and RemoveCurrencyPairFromCache correctly manage cache entries.


Line range hint 48-70: LGTM! But verify cache update logic.

The method efficiently retrieves a market ID using cache and iterates over market parameters if necessary.

Ensure that the cache update logic in AddCurrencyPairIDToCache is functioning correctly.

Verification successful

Cache Update Logic Verified

The AddCurrencyPairIDToCache function correctly updates the cache by storing the market ID associated with a currency pair. The cache update logic is functioning as expected.

  • The function converts the currency pair to a string and uses it as a key.
  • It marshals the market ID and stores it in the cache.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify cache update logic in `AddCurrencyPairIDToCache`.

# Test: Search for the implementation of `AddCurrencyPairIDToCache`. Expect: Correct cache update.
ast-grep --lang go --pattern $'func (k Keeper) AddCurrencyPairIDToCache(ctx sdk.Context, marketId uint32, cp slinkytypes.CurrencyPair) {
  $$$
}'

Length of output: 810


74-85: LGTM! But verify unmarshalling process.

The method correctly retrieves and unmarshals a market ID from the cache.

Ensure that the unmarshalling process in MustUnmarshal is error-free.


Line range hint 31-44: LGTM! But verify error handling in GetMarketParam.

The method correctly retrieves and converts market parameters to a currency pair.

Ensure that GetMarketParam handles errors appropriately and returns valid data.

protocol/x/prices/keeper/market.go (1)

78-78: LGTM!

The refactoring in CreateMarket centralizes cache management, enhancing maintainability.

protocol/x/prices/keeper/market_test.go (2)

54-56: LGTM! Verify cache initialization.

The added assertions correctly verify the absence of the currency pair in the cache before market creation.


81-84: LGTM! Verify cache update.

The assertions confirm the presence of the currency pair in the cache after market creation, ensuring the cache is updated correctly.

protocol/mocks/PricesKeeper.go (1)

1-1: Verify impact of removed method on tests.

The InitializeCurrencyPairIdCache method has been removed from the mock. Ensure that any tests relying on this mock method are updated to reflect the new caching mechanism.

Verification successful

No impact from removed method InitializeCurrencyPairIdCache.

The InitializeCurrencyPairIdCache method is not referenced anywhere in the codebase, indicating that its removal does not affect any tests or functionality. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if tests are affected by the removal of `InitializeCurrencyPairIdCache`.

# Test: Search for occurrences of `InitializeCurrencyPairIdCache` in test files.
rg --type go 'InitializeCurrencyPairIdCache'

Length of output: 44


Script:

#!/bin/bash
# Description: Search for any references to `InitializeCurrencyPairIdCache` in the entire codebase.

rg 'InitializeCurrencyPairIdCache'

Length of output: 34

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 d51c012 and 9c9b53d.

Files selected for processing (4)
  • protocol/x/prices/keeper/market.go (1 hunks)
  • protocol/x/prices/keeper/market_param.go (2 hunks)
  • protocol/x/prices/keeper/slinky_adapter.go (4 hunks)
  • protocol/x/prices/types/keys_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/x/prices/keeper/market.go
  • protocol/x/prices/keeper/market_param.go
  • protocol/x/prices/types/keys_test.go
Additional comments not posted (5)
protocol/x/prices/keeper/slinky_adapter.go (5)

26-29: LGTM!

The getCurrencyPairIDStore method is correctly implemented to return a prefix store for market IDs.


Line range hint 31-44: Efficient data retrieval!

The GetCurrencyPairFromID method now efficiently retrieves market parameters using GetMarketParam. The error handling is appropriate.


Line range hint 48-71: Good fallback mechanism!

The GetIDForCurrencyPair method efficiently retrieves the market ID from the store and provides a fallback to iterate through market parameters. Adding the currency pair to the store after finding it is a good practice.


74-85: Correct store retrieval!

The GetCurrencyPairIDFromStore method correctly retrieves the market ID from the store using the currency pair string. The error handling is appropriate.


87-99: Effective store management!

The AddCurrencyPairIDToStore and RemoveCurrencyPairFromStore methods effectively manage the addition and removal of currency pair IDs in the store.

@chenyaoy chenyaoy changed the title Move currency pair id cache to store [TRA-487] Move currency pair id cache to store Aug 13, 2024
Copy link

linear bot commented Aug 13, 2024

if found {
return id, true
return uint64(marketId), true
}

// if not found, iterate through all market params and find the id
Copy link
Contributor

@teddyding teddyding Aug 19, 2024

Choose a reason for hiding this comment

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

For ease of reasoning, think we should maintain the invariant that the cache is always well-populated, instead of relying on a lazy approach which made more sense when the cache was transient.

This means:

  • Explicitly setting up the cache for all markets in v7 upgrade handler.
  • No need to maintain the "if not found" case

Let me know if this makes sense

@chenyaoy chenyaoy requested a review from a team as a code owner September 11, 2024 20:33
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 9c9b53d and b140706.

Files selected for processing (3)
  • protocol/app/upgrades.go (1 hunks)
  • protocol/app/upgrades/v7.0.0/upgrade.go (1 hunks)
  • protocol/app/upgrades/v7.0.0/upgrade_container_test.go (1 hunks)
Additional comments not posted (4)
protocol/app/upgrades/v7.0.0/upgrade.go (2)

15-24: LGTM!

The new initCurrencyPairIDCache function is well-implemented and follows best practices. It correctly initializes the currency pair ID cache based on existing market parameters and handles errors appropriately.


26-40: LGTM!

The modifications to the CreateUpgradeHandler function are well-implemented and follow best practices. The addition of the pricesKeeper parameter and the call to initCurrencyPairIDCache ensure that the currency pair ID cache is properly initialized before proceeding with the migration process.

protocol/app/upgrades/v7.0.0/upgrade_container_test.go (1)

47-48: LGTM!

The code changes are approved. The addition of the postUpgradeCurrencyPairIDCacheState function call within postUpgradeChecks improves the organization of the test code and enhances maintainability by separating concerns related to different aspects of the upgrade process.

protocol/app/upgrades.go (1)

33-33: LGTM!

The addition of app.PricesKeeper as a parameter to the CreateUpgradeHandler function call is approved. This change allows the upgrade handler to utilize pricing data or functionalities during the upgrade process, potentially enhancing how upgrades are managed and executed within the application.

protocol/app/upgrades/v7.0.0/upgrade_container_test.go Outdated Show resolved Hide resolved
if err == nil {
k.currencyPairIDCache.AddCurrencyPair(uint64(updatedMarketParam.Id), cp.String())
k.AddCurrencyPairIDToStore(ctx, updatedMarketParam.Id, newCurrencyPair)
} else {
k.Logger(ctx).Error("failed to add currency pair to cache", "pair", updatedMarketParam.Pair)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only log the error here? Since this is main point of the state change, seems like we should return error here (thus failing the transaction)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, good catch

@chenyaoy chenyaoy merged commit b7879b1 into main Sep 16, 2024
22 checks passed
@chenyaoy chenyaoy deleted the chenyao/move-currencyPairIDCache-to-store branch September 16, 2024 22:25
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