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

paginate liquidation daemon response #2118

Merged
merged 3 commits into from
Aug 21, 2024
Merged

paginate liquidation daemon response #2118

merged 3 commits into from
Aug 21, 2024

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Aug 20, 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

    • Introduced a new response page limit for the Liquidation Daemon, allowing for improved control over the number of items processed.
    • Added pagination capabilities for sending liquidatable subaccount IDs, enhancing performance with large datasets.
  • Bug Fixes

    • Improved the robustness of the liquidation process by ensuring proper handling of edge cases in test scenarios involving subaccount IDs.
  • Refactor

    • Consolidated multiple update methods for daemon liquidation information into a single method to improve code maintainability and readability.
  • Tests

    • Enhanced test coverage by incorporating additional parameters related to block heights in several test cases, ensuring more comprehensive validation of the liquidation process.

@jayy04 jayy04 requested a review from a team as a code owner August 20, 2024 21:16
Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Walkthrough

The recent changes enhance the liquidation daemon's functionality by introducing new configuration options, particularly for pagination limits. Notably, a ResponsePageLimit flag has been added, along with related adjustments across the codebase to improve data processing control. These updates streamline the handling of subaccount data, bolster test robustness, and enhance the overall efficiency of the liquidation process.

Changes

Files Change Summary
protocol/daemons/flags/flags.go Introduced FlagLiquidationDaemonResponsePageLimit constant and ResponsePageLimit field in LiquidationFlags. Updated default values and command-line interface. Enhanced flag retrieval logic.
protocol/daemons/flags/flags_test.go Added tests for the new ResponsePageLimit flag in existing test functions, ensuring proper configuration and validation in the daemon's operations.
protocol/daemons/liquidation/client/grpc_helper.go Modified SendLiquidatableSubaccountIds to include a pageLimit parameter, enabling request pagination. Introduced helper functions for generating paginated requests.
protocol/daemons/liquidation/client/grpc_helper_test.go Enhanced tests for SendLiquidatableSubaccountIds with new configurations for handling different subaccount IDs and edge cases.
protocol/daemons/liquidation/client/sub_task_runner.go Updated RunLiquidationDaemonTaskLoop to accept liqFlags.ResponsePageLimit for improved task processing control.
protocol/daemons/server/liquidation.go Consolidated update logic for daemonLiquidationInfo into a single Update method to enhance code maintainability and readability.
protocol/daemons/server/types/liquidations/daemon_liquidation_info.go Introduced a new Update method in DaemonLiquidationInfo, allowing batch updates with block height checks for data integrity and improved state management.
protocol/daemons/server/types/liquidations/daemon_liquidation_info_test.go Updated method calls to include block height in tests, ensuring new parameter handling is validated.
protocol/x/clob/abci_test.go Added block height parameter to UpdateLiquidatableSubaccountIds method call in tests, enhancing the transaction context for state updates.
protocol/x/clob/keeper/deleveraging_test.go Modified UpdateSubaccountsWithPositions call to include block height, improving context-aware updates in tests.
protocol/x/clob/keeper/liquidations_test.go Updated UpdateSubaccountsWithPositions in tests to include block height, enhancing the simulation of the liquidation process with current blockchain context.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant LiquidationDaemon
    participant Server
    participant DaemonLiquidationInfo
    
    Client->>LiquidationDaemon: Send liquidatable subaccount IDs
    LiquidationDaemon->>Server: Process liquidation request
    Server->>DaemonLiquidationInfo: Update liquidatable subaccounts with page limit
    DaemonLiquidationInfo-->>Server: Confirm update
    Server-->>LiquidationDaemon: Send response
    LiquidationDaemon-->>Client: Return success
Loading

🐰 In the meadow, hops a little hare,
With flags and limits, he dances with flair.
Pagination's here, oh what a delight,
Liquidation's smooth, everything feels right!
A tweak here, a change there, oh so grand,
Our daemon's now ready, together we stand! 🌼


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b441185 and 374379a.

Files selected for processing (11)
  • protocol/daemons/flags/flags.go (6 hunks)
  • protocol/daemons/flags/flags_test.go (3 hunks)
  • protocol/daemons/liquidation/client/grpc_helper.go (2 hunks)
  • protocol/daemons/liquidation/client/grpc_helper_test.go (4 hunks)
  • protocol/daemons/liquidation/client/sub_task_runner.go (1 hunks)
  • protocol/daemons/server/liquidation.go (1 hunks)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (3 hunks)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info_test.go (11 hunks)
  • protocol/x/clob/abci_test.go (1 hunks)
  • protocol/x/clob/keeper/deleveraging_test.go (1 hunks)
  • protocol/x/clob/keeper/liquidations_test.go (1 hunks)
Additional comments not posted (40)
protocol/daemons/server/liquidation.go (1)

45-50: LGTM! Streamlined update logic.

The consolidation of multiple update calls into a single Update method enhances code readability and maintainability.

Ensure that the Update method handles all necessary logic correctly.

Run the following script to verify the Update method usage:

Verification successful

The Update method handles parameters correctly. The method implementation correctly updates the necessary fields with proper locking for thread safety.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `Update` method.

# Test: Search for the `Update` method implementation and usage. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func (ls *DaemonLiquidationInfo) Update($_, $_, $_, $_) {
  $$$
}'

Length of output: 1571

protocol/daemons/flags/flags_test.go (3)

29-29: LGTM! New flag integration.

The FlagLiquidationDaemonResponsePageLimit is correctly added to the command flags.


57-57: LGTM! New flag in options map.

The flag is correctly set in the optsMap for testing.


88-88: LGTM! New flag assertion.

The assertion for FlagLiquidationDaemonResponsePageLimit ensures the flag's value is correctly retrieved.

Ensure that the flag is used correctly in the codebase.

Run the following script to verify the flag's usage:

Verification successful

Flag Usage Verified: FlagLiquidationDaemonResponsePageLimit

The flag FlagLiquidationDaemonResponsePageLimit is correctly retrieved, cast to uint64, and used to set the ResponsePageLimit in the result.Liquidation configuration. This confirms its proper handling in the codebase.

  • The flag is retrieved and used in protocol/daemons/flags/flags.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `FlagLiquidationDaemonResponsePageLimit`.

# Test: Search for the flag usage in the codebase. Expect: Correct handling in logic.
rg --type go --word-regexp 'FlagLiquidationDaemonResponsePageLimit'

Length of output: 706


Script:

#!/bin/bash
# Description: Verify the handling of the retrieved option for `FlagLiquidationDaemonResponsePageLimit`.

# Test: Search for the usage of the retrieved option in the codebase.
rg --type go 'appOpts.Get\(FlagLiquidationDaemonResponsePageLimit\)'

Length of output: 185


Script:

#!/bin/bash
# Description: Get surrounding code for the usage of `FlagLiquidationDaemonResponsePageLimit` in `flags.go`.

# Test: Extract the surrounding lines of the conditional block where the option is used.
rg --type go -A 10 'appOpts.Get\(FlagLiquidationDaemonResponsePageLimit\)' protocol/daemons/flags/flags.go

Length of output: 462

protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (4)

29-40: LGTM! Consolidated update method.

The Update method effectively consolidates multiple updates, improving modularity.


70-77: Ensure block height logic is robust.

The block height logic in UpdateNegativeTncSubaccountIds ensures updates are only applied for valid block heights. Verify that panic conditions are handled appropriately.


85-119: Ensure block height logic is robust.

The block height logic in UpdateSubaccountsWithPositions ensures updates are only applied for valid block heights. Verify that panic conditions are handled appropriately.


54-61: Ensure block height logic is robust.

The block height logic in UpdateLiquidatableSubaccountIds ensures updates are only applied for valid block heights. Verify that panic conditions are handled appropriately.

Run the following script to verify panic conditions:

Verification successful

Panic Condition in Block Height Logic Verified

The UpdateLiquidatableSubaccountIds method includes a panic condition that triggers when the blockHeight is less than the current ls.blockHeight. This ensures that updates are only applied for valid block heights, maintaining the robustness of the block height logic. The panic usage is correctly implemented.

  • Method: UpdateLiquidatableSubaccountIds
  • Panic condition: panic("UpdateLiquidatableSubaccountIds: block height cannot be less than the current block height")
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify panic conditions in `UpdateLiquidatableSubaccountIds`.

# Test: Search for panic usage in the method. Expect: Correct handling of block height conditions.
ast-grep --lang go --pattern $'func (ls *DaemonLiquidationInfo) UpdateLiquidatableSubaccountIds($_, $_) {
  $$$
  panic($_)
  $$$
}'

Length of output: 133


Script:

#!/bin/bash
# Search for the implementation of the UpdateLiquidatableSubaccountIds method to verify panic usage.
ast-grep --lang go --pattern $'func (ls *DaemonLiquidationInfo) UpdateLiquidatableSubaccountIds($_, $_) {
  $$$
}'

Length of output: 1587

protocol/daemons/server/types/liquidations/daemon_liquidation_info_test.go (9)

28-28: LGTM! Test update for block height.

The test for UpdateLiquidatableSubaccountIds now includes block height, aligning with method changes.


42-42: LGTM! Test update for block height.

The test for UpdateNegativeTncSubaccountIds now includes block height, aligning with method changes.


63-63: LGTM! Test update for block height.

The test for UpdateSubaccountsWithPositions now includes block height, aligning with method changes.


81-97: LGTM! Multiple writes test with block height.

The test for multiple writes to UpdateLiquidatableSubaccountIds correctly incorporates block height.


108-124: LGTM! Multiple writes test with block height.

The test for multiple writes to UpdateNegativeTncSubaccountIds correctly incorporates block height.


Line range hint 143-184: LGTM! Multiple writes test with block height.

The test for multiple writes to UpdateSubaccountsWithPositions correctly incorporates block height.


199-205: LGTM! Empty update test with block height.

The test for empty updates to UpdateLiquidatableSubaccountIds correctly incorporates block height.


216-222: LGTM! Empty update test with block height.

The test for empty updates to UpdateNegativeTncSubaccountIds correctly incorporates block height.


240-250: LGTM! Empty update test with block height.

The test for empty updates to UpdateSubaccountsWithPositions correctly incorporates block height.

protocol/daemons/liquidation/client/sub_task_runner.go (1)

86-86: LGTM! Enhanced task loop with response page limit.

The addition of liqFlags.ResponsePageLimit enhances the function's ability to manage response sizes efficiently.

protocol/daemons/flags/flags.go (5)

29-29: New constant FlagLiquidationDaemonResponsePageLimit added.

This constant is introduced to define a limit on the number of items sent to the main application by the Liquidation Daemon. Ensure that this flag is used consistently across the codebase.


67-68: New field ResponsePageLimit added to LiquidationFlags.

This field is used to store the pagination limit for responses sent by the Liquidation Daemon. Ensure that this field is properly initialized and used throughout the application.


112-112: Default value for ResponsePageLimit set to 2,000.

This default value is set in the GetDefaultDaemonFlags function. Ensure that this value is appropriate for the expected load and can be overridden if necessary.


191-195: CLI flag for ResponsePageLimit added.

The command-line interface now includes a flag for setting the ResponsePageLimit. Ensure that this is documented and that users are aware of how to configure this setting.


289-293: Handling of ResponsePageLimit in GetDaemonFlagValuesFromOptions.

The function now retrieves the ResponsePageLimit from application options. Ensure that this integration is tested to confirm that the value is correctly parsed and applied.

protocol/daemons/liquidation/client/grpc_helper.go (7)

214-214: Added pageLimit parameter to SendLiquidatableSubaccountIds.

This parameter allows for pagination of requests, improving the handling of large datasets. Ensure that this parameter is consistently used in all related function calls.


245-252: Use of GenerateLiquidateSubaccountsPaginatedRequests.

The function generates paginated requests for liquidatable subaccount IDs. Ensure that the pagination logic correctly handles edge cases, such as when the number of IDs is less than the page limit.


255-262: Use of GenerateNegativeTNCSubaccountsPaginatedRequests.

This function appends paginated requests for negative TNC subaccount IDs. Verify that the logic correctly handles different sizes of input lists.


265-272: Use of GenerateSubaccountOpenPositionPaginatedRequests.

This function appends paginated requests for subaccount open position info. Ensure that the pagination logic is efficient and handles all potential input scenarios.


283-307: Function GenerateLiquidateSubaccountsPaginatedRequests added.

This function creates paginated requests for liquidatable subaccounts. Ensure that the logic correctly handles empty input and that the pagination is efficient.


309-333: Function GenerateNegativeTNCSubaccountsPaginatedRequests added.

This function creates paginated requests for negative TNC subaccounts. Ensure that the logic correctly handles empty input and that the pagination is efficient.


335-382: Function GenerateSubaccountOpenPositionPaginatedRequests added.

This function creates paginated requests for subaccount open positions. Ensure that the logic correctly handles empty input and that the pagination is efficient.

protocol/daemons/liquidation/client/grpc_helper_test.go (7)

472-475: Test case for LiquidateSubaccounts with LiquidatableSubaccountIds.

This test case ensures that requests with liquidatable subaccount IDs are handled correctly. Verify that the test covers all relevant scenarios and edge cases.


476-482: Test case for LiquidateSubaccounts with NegativeTncSubaccountIds.

This test case ensures that requests with negative TNC subaccount IDs are handled correctly. Verify that the test covers all relevant scenarios and edge cases.


483-497: Test case for LiquidateSubaccounts with SubaccountOpenPositionInfo.

This test case ensures that requests with subaccount open position info are handled correctly. Verify that the test covers all relevant scenarios and edge cases.


538-543: Test case for empty LiquidatableSubaccountIds.

This test case ensures that the function handles empty lists of liquidatable subaccount IDs correctly. Verify that the test covers all relevant scenarios and edge cases.


544-550: Test case for empty NegativeTncSubaccountIds.

This test case ensures that the function handles empty lists of negative TNC subaccount IDs correctly. Verify that the test covers all relevant scenarios and edge cases.


551-555: Test case for empty SubaccountOpenPositionInfo.

This test case ensures that the function handles empty lists of subaccount open position info correctly. Verify that the test covers all relevant scenarios and edge cases.


565-566: Error propagation test case.

This test case ensures that errors are correctly propagated when requests fail. Verify that the test covers all relevant scenarios and edge cases.

protocol/x/clob/abci_test.go (1)

1268-1271: Updated UpdateLiquidatableSubaccountIds to include block height.

The method now requires the block height as an additional parameter, providing more context. Ensure that this change is correctly integrated and that the block height is used appropriately.

protocol/x/clob/keeper/deleveraging_test.go (1)

870-871: Updated UpdateSubaccountsWithPositions to include block height.

The method now requires the block height as an additional parameter, providing more context. Ensure that this change is correctly integrated and that the block height is used appropriately.

protocol/x/clob/keeper/liquidations_test.go (1)

2136-2136: Verify the usage of uint32(ctx.BlockHeight()).

Ensure that the UpdateSubaccountsWithPositions method correctly handles the block height parameter. This change might affect how subaccount positions are updated based on the block height.

Run the following script to verify the implementation of UpdateSubaccountsWithPositions and ensure it handles the block height correctly:

Verification successful

Block height handling is correctly implemented in UpdateSubaccountsWithPositions.

The function properly resets or appends to the subaccountsWithPositions map based on the block height, ensuring accurate updates to subaccount positions. No issues found with the current implementation.

  • The map is reset if the block height increases.
  • The map is appended to if the block height remains the same.
  • A panic is triggered if the block height decreases.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `UpdateSubaccountsWithPositions` to ensure it handles the block height.

# Test: Search for the method implementation. Expect: Correct handling of block height.
ast-grep --lang go --pattern $'func ($_ $_) UpdateSubaccountsWithPositions($_, $_) {
  $$$
}' 

Length of output: 5011

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 374379a and 0c550b3.

Files selected for processing (3)
  • protocol/daemons/liquidation/client/sub_task_runner_test.go (11 hunks)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (3 hunks)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info_test.go (11 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info_test.go
Additional comments not posted (5)
protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (3)

59-64: LGTM!

The function correctly appends updates to the list of liquidatable subaccount IDs.


68-73: LGTM!

The function correctly appends updates to the list of negative TNC subaccount IDs.


75-98: LGTM!

The function effectively manages updates to the map of subaccounts with positions, ensuring no duplicate entries.

protocol/daemons/liquidation/client/sub_task_runner_test.go (2)

Line range hint 91-699: Refactoring improves readability and maintainability.

The use of a helper function for setting up mock requests reduces code duplication and enhances test readability.


733-786: LGTM!

The helper function is well-structured and effectively centralizes the setup of mock requests, improving test setup consistency.

Comment on lines 29 to 49
func (ls *DaemonLiquidationInfo) Update(
blockHeight uint32,
liquidatableSubaccountIds []satypes.SubaccountId,
negativeTncSubaccountIds []satypes.SubaccountId,
subaccountsWithPositions []clobtypes.SubaccountOpenPositionInfo,
) {
ls.Lock()
defer ls.Unlock()
ls.blockHeight = blockHeight

if blockHeight > ls.blockHeight {
ls.liquidatableSubaccountIds = make([]satypes.SubaccountId, 0)
ls.negativeTncSubaccountIds = make([]satypes.SubaccountId, 0)
ls.subaccountsWithPositions = make(map[uint32]*clobtypes.SubaccountOpenPositionInfo)
} else if blockHeight < ls.blockHeight {
panic("UpdateLiquidatableSubaccountIds: block height cannot be less than the current block height")
}
ls.UpdateBlockHeight(blockHeight)

ls.UpdateLiquidatableSubaccountIds(liquidatableSubaccountIds, blockHeight)
ls.UpdateNegativeTncSubaccountIds(negativeTncSubaccountIds, blockHeight)
ls.UpdateSubaccountsWithPositions(subaccountsWithPositions, blockHeight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing panic with error handling.

Using panic for block height discrepancies might not be ideal in a production environment. Consider returning an error instead to handle this case more gracefully.

Refactor the function to return an error:

func (ls *DaemonLiquidationInfo) Update(
	blockHeight uint32,
	liquidatableSubaccountIds []satypes.SubaccountId,
	negativeTncSubaccountIds []satypes.SubaccountId,
	subaccountsWithPositions []clobtypes.SubaccountOpenPositionInfo,
) error {
	ls.Lock()
	defer ls.Unlock()

	if blockHeight > ls.blockHeight {
		ls.liquidatableSubaccountIds = make([]satypes.SubaccountId, 0)
		ls.negativeTncSubaccountIds = make([]satypes.SubaccountId, 0)
		ls.subaccountsWithPositions = make(map[uint32]*clobtypes.SubaccountOpenPositionInfo)
	} else if blockHeight < ls.blockHeight {
		return fmt.Errorf("block height cannot be less than the current block height")
	}
	ls.UpdateBlockHeight(blockHeight)

	ls.UpdateLiquidatableSubaccountIds(liquidatableSubaccountIds, blockHeight)
	ls.UpdateNegativeTncSubaccountIds(negativeTncSubaccountIds, blockHeight)
	ls.UpdateSubaccountsWithPositions(subaccountsWithPositions, blockHeight)
	return nil
}

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 0c550b3 and 5258b14.

Files selected for processing (2)
  • protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (4 hunks)
  • protocol/x/clob/e2e/withdrawal_gating_test.go (2 hunks)
Additional comments not posted (6)
protocol/daemons/server/types/liquidations/daemon_liquidation_info.go (4)

59-61: LGTM!

The UpdateBlockHeight method correctly updates the block height.


66-71: LGTM!

The UpdateLiquidatableSubaccountIds method correctly appends new subaccount IDs.


73-80: LGTM!

The UpdateNegativeTncSubaccountIds method correctly appends new subaccount IDs.


82-105: LGTM!

The UpdateSubaccountsWithPositions method correctly updates the map of subaccounts with open positions.

protocol/x/clob/e2e/withdrawal_gating_test.go (2)

415-415: Verify the static BlockHeight value.

The BlockHeight is set to a static value of 3. Ensure this aligns with the test's objectives.


517-518: LGTM!

The dynamic calculation of BlockHeight correctly simulates different scenarios.

Comment on lines +30 to +56
func (ls *DaemonLiquidationInfo) Update(
blockHeight uint32,
liquidatableSubaccountIds []satypes.SubaccountId,
negativeTncSubaccountIds []satypes.SubaccountId,
subaccountsWithPositions []clobtypes.SubaccountOpenPositionInfo,
) {
ls.Lock()
defer ls.Unlock()
ls.blockHeight = blockHeight

if blockHeight > ls.blockHeight {
ls.liquidatableSubaccountIds = make([]satypes.SubaccountId, 0)
ls.negativeTncSubaccountIds = make([]satypes.SubaccountId, 0)
ls.subaccountsWithPositions = make(map[uint32]*clobtypes.SubaccountOpenPositionInfo)
} else if blockHeight < ls.blockHeight {
panic(
fmt.Sprintf(
"UpdateLiquidatableSubaccountIds: block height %d cannot be less than the current block height %d",
blockHeight,
ls.blockHeight,
),
)
}
ls.UpdateBlockHeight(blockHeight)

ls.UpdateLiquidatableSubaccountIds(liquidatableSubaccountIds, blockHeight)
ls.UpdateNegativeTncSubaccountIds(negativeTncSubaccountIds, blockHeight)
ls.UpdateSubaccountsWithPositions(subaccountsWithPositions, blockHeight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing panic with error handling.

Using panic for block height discrepancies might not be ideal in a production environment. Consider returning an error instead to handle this case more gracefully.

Refactor the function to return an error:

func (ls *DaemonLiquidationInfo) Update(
	blockHeight uint32,
	liquidatableSubaccountIds []satypes.SubaccountId,
	negativeTncSubaccountIds []satypes.SubaccountId,
	subaccountsWithPositions []clobtypes.SubaccountOpenPositionInfo,
) error {
	ls.Lock()
	defer ls.Unlock()

	if blockHeight > ls.blockHeight {
		ls.liquidatableSubaccountIds = make([]satypes.SubaccountId, 0)
		ls.negativeTncSubaccountIds = make([]satypes.SubaccountId, 0)
		ls.subaccountsWithPositions = make(map[uint32]*clobtypes.SubaccountOpenPositionInfo)
	} else if blockHeight < ls.blockHeight {
		return fmt.Errorf("block height cannot be less than the current block height")
	}
	ls.UpdateBlockHeight(blockHeight)

	ls.UpdateLiquidatableSubaccountIds(liquidatableSubaccountIds, blockHeight)
	ls.UpdateNegativeTncSubaccountIds(negativeTncSubaccountIds, blockHeight)
	ls.UpdateSubaccountsWithPositions(subaccountsWithPositions, blockHeight)
	return nil
}

@jayy04
Copy link
Contributor Author

jayy04 commented Aug 21, 2024

@Mergifyio backport release/protocol/v5.2.x

Copy link
Contributor

mergify bot commented Aug 21, 2024

backport release/protocol/v5.2.x

✅ Backports have been created

@jayy04 jayy04 merged commit 909fc3a into main Aug 21, 2024
23 checks passed
@jayy04 jayy04 deleted the jy/fix-subaccount-info branch August 21, 2024 00:15
mergify bot pushed a commit that referenced this pull request Aug 21, 2024
jayy04 added a commit that referenced this pull request Aug 21, 2024
@jayy04
Copy link
Contributor Author

jayy04 commented Aug 21, 2024

@Mergifyio backport release/protocol/v6.x

Copy link
Contributor

mergify bot commented Aug 21, 2024

backport release/protocol/v6.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 21, 2024
jayy04 added a commit that referenced this pull request Aug 21, 2024
dydxwill pushed a commit that referenced this pull request Aug 26, 2024
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