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-654] add listing module state init into v7 upgrade handler #2432

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Oct 2, 2024

Changelist

Set markets hard cap and default listing vault params for the listing module state in v7 upgrade handler

Test Plan

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

    • Integrated a new listing module into the upgrade process, enhancing state initialization during upgrades.
    • Added a hard cap on the number of listed markets and established deposit parameters for the listing vault.
  • Bug Fixes

    • Implemented error handling to ensure proper initialization of the listing module's state.
  • Tests

    • Introduced checks to validate the listing module's state after upgrades, ensuring correct setup and functionality.
    • Enhanced post-upgrade validation process with specific checks for the listing module.

@shrenujb shrenujb requested a review from a team as a code owner October 2, 2024 18:04
Copy link

linear bot commented Oct 2, 2024

Copy link
Contributor

coderabbitai bot commented Oct 2, 2024

Walkthrough

The changes involve modifications to the setupUpgradeHandlers method in the protocol/app/upgrades.go file, where the ListingKeeper is added as a parameter to the CreateUpgradeHandler function. Additionally, the upgrade.go file in the v_7_0_0 package introduces a new function to initialize the listing module's state, setting parameters and error handling. The upgrade_container_test.go file is updated to include tests for the listing module's state after upgrades, ensuring proper integration and functionality.

Changes

File Change Summary
protocol/app/upgrades.go Updated setupUpgradeHandlers to include ListingKeeper in CreateUpgradeHandler.
protocol/app/upgrades/v7.0.0/upgrade.go Added initListingModuleState to initialize the listing module's state with hard cap and deposit params.
protocol/app/upgrades/v7.0.0/upgrade_container_test.go Introduced postUpgradeListingModuleStateCheck to validate listing module state after upgrades.
protocol/x/listing/types/constants.go Added new constant DefaultMarketsHardCap with a value of 500.

Possibly related PRs

Suggested labels

revshare

Suggested reviewers

  • vincentwschau
  • roy-dydx

🐰 In the land of code, where changes bloom,
A ListingKeeper joins, dispelling all gloom.
With upgrades in hand, we set the stage,
For modules to thrive, as we turn the page.
Tests stand ready, to check and ensure,
That all is well, and our upgrades are pure! 🌼


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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@vincentwschau
Copy link
Contributor

Add listing module store to the upgrades here.

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

🧹 Outside diff range and nitpick comments (2)
protocol/app/upgrades/v7.0.0/upgrade_container_test.go (1)

212-241: LGTM: New function for checking listing module state.

The postUpgradeListingModuleStateCheck function is well-implemented and correctly verifies the initialization of the listing module state. It follows the existing patterns in the file and uses appropriate error handling.

Consider extracting the magic number 500 used for the markets hard cap into a named constant at the top of the file for better maintainability and clarity.

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

200-215: Consider defining the hard cap value as a constant

The hard-coded value 500 in SetMarketsHardCap could be defined as a constant to enhance readability and maintainability. This practice makes it easier to manage and update the value in the future.

Apply this diff to define the hard cap as a constant:

+const (
+	MarketsHardCap = 500
+)
+
func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) {
	// Set hard cap on listed markets
-	err := listingKeeper.SetMarketsHardCap(ctx, 500)
+	err := listingKeeper.SetMarketsHardCap(ctx, MarketsHardCap)
	if err != nil {
		panic(fmt.Sprintf("failed to set markets hard cap: %s", err))
	}

	// Set listing vault deposit params
	err = listingKeeper.SetListingVaultDepositParams(
		ctx,
		listingtypes.DefaultParams(),
	)
	if err != nil {
		panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err))
	}
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2438dd and cd2d378.

📒 Files selected for processing (3)
  • protocol/app/upgrades.go (1 hunks)
  • protocol/app/upgrades/v7.0.0/upgrade.go (3 hunks)
  • protocol/app/upgrades/v7.0.0/upgrade_container_test.go (3 hunks)
🔇 Additional comments (6)
protocol/app/upgrades.go (1)

36-36: 💡 Codebase verification

ListingKeeper Not Utilized in v7.0.0 Upgrade Handler

The ListingKeeper is added as a parameter to the v7_0_0.CreateUpgradeHandler call in protocol/app/upgrades.go. However, the current implementation of the v7.0.0 upgrade handler does not utilize the ListingKeeper. This may result in the listing module state not being properly initialized during the upgrade.

Next Steps:

  • Ensure that v7_0_0.CreateUpgradeHandler correctly integrates and utilizes the ListingKeeper to handle listing module state initialization.
🔗 Analysis chain

LGTM. Verify v7.0.0 upgrade handler implementation.

The addition of app.ListingKeeper to the v7_0_0.CreateUpgradeHandler call is consistent with the PR objective of integrating the listing module state initialization into the v7 upgrade handler. This change looks good and aligns with the expected functionality.

To ensure full compatibility, please verify that the v7.0.0 upgrade handler implementation correctly utilizes the ListingKeeper. Run the following script to check the implementation:

This script will help confirm that the ListingKeeper is properly integrated into the v7.0.0 upgrade logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the v7.0.0 upgrade handler uses ListingKeeper

# Test: Search for ListingKeeper usage in the v7.0.0 upgrade handler
rg --type go -A 5 'ListingKeeper' $(fd -t f -e go v7_0_0)

Length of output: 7460

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

9-10: LGTM: Import statement for listing module types.

The addition of the listingtypes import is consistent with the PR objectives and follows Go conventions.


63-65: LGTM: Addition of listing module state check.

The new function call postUpgradeListingModuleStateCheck is appropriately placed within the postUpgradeChecks function and aligns with the PR objectives.


Line range hint 1-241: Summary: Changes align well with PR objectives.

The modifications to this file successfully integrate the listing module state initialization into the v7 upgrade handler test suite. The changes are consistent, well-structured, and follow the established patterns in the file. They effectively address the PR objectives by:

  1. Adding the necessary import for the listing module types.
  2. Incorporating a new check in the postUpgradeChecks function.
  3. Implementing a detailed postUpgradeListingModuleStateCheck function to verify the correct initialization of the listing module state.

These changes enhance the test coverage for the upgrade process, ensuring that the listing module is properly initialized during the upgrade.

protocol/app/upgrades/v7.0.0/upgrade.go (2)

241-243: Listing module state initialization is correctly integrated

The call to initListingModuleState within the CreateUpgradeHandler ensures that the listing module state is properly initialized during the upgrade. This integration aligns with the upgrade process and sets up the necessary state for the listing module.


223-223: Ensure all invocations of CreateUpgradeHandler are updated with the new parameter

The function CreateUpgradeHandler now includes an additional parameter listingKeeper listingkeeper.Keeper. Please verify that all calls to this function throughout the codebase have been updated accordingly to prevent build failures or unexpected behavior.

Run the following script to find all usages of CreateUpgradeHandler and check their parameters:

✅ Verification successful

All invocations of CreateUpgradeHandler have been verified and no usages were found in the codebase. No further action is needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all calls to CreateUpgradeHandler include the new 'listingKeeper' parameter.

# Test: Search for function calls to CreateUpgradeHandler.
# Expect: All calls should have the updated parameter list.

ast-grep --lang go --pattern $'CreateUpgradeHandler($$$)' \
--json --pretty \
| jq -r '.matches[].match | .text' \
| while read -r line; do
	echo "Found usage: $line"
done

Length of output: 385


Script:

#!/bin/bash
# Description: Verify that all calls to CreateUpgradeHandler include the new 'listingKeeper' parameter without using unsupported flags.

# Test: Search for function calls to CreateUpgradeHandler.
# Expect: All calls should have the updated parameter list.

ast-grep --lang go --pattern $'CreateUpgradeHandler($$$)' \
--json \
| jq -r '.matches[].match | .text' \
| while read -r line; do
	echo "Found usage: $line"
done

Length of output: 182


Script:

#!/bin/bash
# Description: Inspect raw JSON output from CreateUpgradeHandler searches to determine correct jq parsing.

# Test: Output raw JSON from ast-grep without parsing.
# Expect: To understand the structure of the JSON for accurate jq filtering.

ast-grep --lang go --pattern $'CreateUpgradeHandler($$$)' \
--json \
> astgrep_output.json

cat astgrep_output.json

Length of output: 94

Comment on lines 200 to 215
func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) {
// Set hard cap on listed markets
err := listingKeeper.SetMarketsHardCap(ctx, 500)
if err != nil {
panic(fmt.Sprintf("failed to set markets hard cap: %s", err))
}

// Set listing vault deposit params
err = listingKeeper.SetListingVaultDepositParams(
ctx,
listingtypes.DefaultParams(),
)
if err != nil {
panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review error handling for better upgrade resilience

While panicking on errors during state initialization ensures that issues are caught immediately, it may be beneficial to handle errors more gracefully to prevent the entire upgrade process from failing unexpectedly. Consider logging the errors and returning them up the call stack if appropriate.

Adjust the error handling to return errors:

func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) error {
	// Set hard cap on listed markets
	err := listingKeeper.SetMarketsHardCap(ctx, MarketsHardCap)
	if err != nil {
-		panic(fmt.Sprintf("failed to set markets hard cap: %s", err))
+		return fmt.Errorf("failed to set markets hard cap: %w", err)
	}

	// Set listing vault deposit params
	err = listingKeeper.SetListingVaultDepositParams(
		ctx,
		listingtypes.DefaultParams(),
	)
	if err != nil {
-		panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err))
+		return fmt.Errorf("failed to set listing vault deposit params: %w", err)
	}

+	return nil
}

Update the call in CreateUpgradeHandler:

	// Initialize listing module state.
-	initListingModuleState(sdkCtx, listingKeeper)
+	if err := initListingModuleState(sdkCtx, listingKeeper); err != nil {
+		return nil, err
+	}

Committable suggestion was skipped due to low confidence.

@shrenujb shrenujb added the pml permissionless market listing label Oct 2, 2024
@@ -194,12 +197,30 @@ func migrateVaultSharesToMegavaultShares(ctx sdk.Context, k vaultkeeper.Keeper)
ctx.Logger().Info("Successfully migrated vault shares to megavault shares")
}

func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) {
// Set hard cap on listed markets
err := listingKeeper.SetMarketsHardCap(ctx, 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Do we want to add this as a constant in the listing module rather than a magic number here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A default number in the listing module can change down the line so don't want to reference it here. This code is also just gonna run once

Copy link
Contributor

Choose a reason for hiding this comment

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

Add to constants.go instead then?

@shrenujb
Copy link
Contributor Author

shrenujb commented Oct 2, 2024

Add listing module store to the upgrades here

The listing module store key was already added in v6. Do I need it again here?

Signed-off-by: Shrenuj Bansal <[email protected]>
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 cd2d378 and ec2028a.

📒 Files selected for processing (2)
  • protocol/app/upgrades/v7.0.0/upgrade.go (3 hunks)
  • protocol/x/listing/types/constants.go (1 hunks)
🔇 Additional comments (5)
protocol/app/upgrades/v7.0.0/upgrade.go (5)

8-9: Import statement for listingtypes added correctly

The import for listingtypes is appropriately added and necessary for the listing module functionality.


17-17: Import statement for listingkeeper added correctly

The import for listingkeeper is appropriately added to access the listing module's keeper.


200-215: Initialization of listing module state is implemented correctly

The initListingModuleState function properly initializes the listing module state by setting the markets hard cap and listing vault deposit parameters using the default values.


223-223: Added listingKeeper parameter to CreateUpgradeHandler

The additional listingKeeper parameter in CreateUpgradeHandler is correctly incorporated to pass the listing keeper to the upgrade handler.


241-243: Listing module state initialized within the upgrade handler

The call to initListingModuleState ensures that the listing module state is initialized during the upgrade process, which is necessary for the module's proper operation post-upgrade.

Comment on lines +17 to +18

DefaultMarketsHardCap = 500
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add a descriptive comment for DefaultMarketsHardCap

The constant DefaultMarketsHardCap is correctly added and utilized in the upgrade process. To enhance code clarity and maintainability, please add a comment explaining its purpose and the rationale behind the chosen value. For example:

// DefaultMarketsHardCap defines the maximum number of markets that can be listed.
// The value of 500 is based on [insert rationale here].
DefaultMarketsHardCap = 500
🔗 Analysis chain

New constant DefaultMarketsHardCap added

The addition of DefaultMarketsHardCap with a value of 500 seems appropriate. However, consider the following points:

  1. The constant name follows the existing naming convention (PascalCase), which is good.
  2. The value 500 appears to be a reasonable default for a markets hard cap, but it would be helpful to add a comment explaining the rationale behind this specific value.
  3. Consider adding a unit to the constant name for clarity, e.g., DefaultMarketsHardCapCount.

Consider adding a brief comment above the constant to explain its purpose and the reasoning behind the chosen value. For example:

// DefaultMarketsHardCap defines the maximum number of markets that can be listed.
// This value was chosen based on [insert rationale here].
DefaultMarketsHardCap = 500

To ensure this constant is used appropriately throughout the codebase, let's search for its usage:


To ensure DefaultMarketsHardCap is utilized correctly, let's examine the implementation of the SetMarketsHardCap method:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of DefaultMarketsHardCap
rg --type go "DefaultMarketsHardCap"

Length of output: 224


Script:

#!/bin/bash
# Find the implementation of SetMarketsHardCap method
rg --type go "func.*SetMarketsHardCap"

Length of output: 4100

@shrenujb shrenujb merged commit 922a9b5 into main Oct 3, 2024
22 checks passed
@shrenujb shrenujb deleted the sbansal/tra654 branch October 3, 2024 01:11
@shrenujb
Copy link
Contributor Author

shrenujb commented Oct 3, 2024

@Mergifyio backport release/protocol/v7.x

Copy link
Contributor

mergify bot commented Oct 3, 2024

backport release/protocol/v7.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pml permissionless market listing protocol
Development

Successfully merging this pull request may close these issues.

3 participants