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

Store stateful order expirations individually in state #1875

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

roy-dydx
Copy link
Contributor

@roy-dydx roy-dydx commented Jul 9, 2024

Changelist

  • Store these individually to prevent lots of serde when receiving many orders with the same GTT

Test Plan

  • Modified and added 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

  • Refactor

    • Improved stateful order management by renaming and restructuring functions.
    • Enhanced efficiency in removing expired stateful orders.
  • Tests

    • Updated test cases to align with the new function names and signatures.
  • Chores

    • Cleaned up deprecated function calls and unused imports.

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The changes modify handling of stateful orders expiration in a clob protocol, replacing functions and altering interfaces for streamlined management. They adjust Keeper methods, testing setups, and key prefixes, improving expiration order processing.

Changes

Files Change Summary
protocol/x/clob/abci.go Renamed RemoveExpiredStatefulOrdersTimeSlices to RemoveExpiredStatefulOrders.
protocol/x/clob/abci_test.go, protocol/x/clob/e2e/... Renamed MustAddOrderToStatefulOrdersTimeSlice to AddStatefulOrderIdExpiration.
protocol/x/clob/keeper/*.go, protocol/x/clob/keeper/*_test.go Updated function calls and signatures to use AddStatefulOrderIdExpiration and refactored several methods to use storetypes.KVStore for order ID management.
protocol/x/clob/keeper/stateful_order_state.go Added new functions for handling stateful order ID expirations and removing expired stateful orders more effectively.
protocol/x/clob/keeper/stores.go Removed getStatefulOrdersTimeSliceStore.
protocol/x/clob/types/clob_keeper.go, protocol/x/clob/types/keys.go Removed several time slice methods and renamed key prefixes related to expiration handling.
protocol/x/clob/types/keys_test.go Removed specific assertion related to time slice prefix in tests.
protocol/x/clob/types/mem_clob_keeper.go Removed MustAddOrderToStatefulOrdersTimeSlice from the MemClobKeeper interface.

Sequence Diagram(s)

State Order Expiration Handling - Before Changes

sequenceDiagram
    participant User
    participant ClobKeeper
    participant TimeSliceStore
    participant ExpirationHandler

    User->>ClobKeeper: Place Order
    ClobKeeper->>TimeSliceStore: MustAddOrderToStatefulOrdersTimeSlice
    TimeSliceStore-->>ClobKeeper: Order Added
    ClobKeeper-->>User: Order Placed

    ClobKeeper-->>ExpirationHandler: RemoveExpiredStatefulOrdersTimeSlices
    ExpirationHandler->>TimeSliceStore: Fetch Expired TimeSlice
    TimeSliceStore-->>ExpirationHandler: Return TimeSlice
    ExpirationHandler-->>ClobKeeper: Orders Removed
Loading

State Order Expiration Handling - After Changes

sequenceDiagram
    participant User
    participant ClobKeeper
    participant KVStore
    participant ExpirationHandler

    User->>ClobKeeper: Place Order
    ClobKeeper->>KVStore: AddStatefulOrderIdExpiration
    KVStore-->>ClobKeeper: Order Added
    ClobKeeper-->>User: Order Placed

    ClobKeeper-->>ExpirationHandler: RemoveExpiredStatefulOrders
    ExpirationHandler->>KVStore: Fetch Expired Orders
    KVStore-->>ExpirationHandler: Return Expired Orders
    ExpirationHandler-->>ClobKeeper: Orders Removed
Loading

Poem

In the code where changes bloom,
Orders dance within their room,
No more time slices to expire,
New methods now conspire,
To keep the clob neat and trim,
With expiration's gentle hymn,
Orders fall like rabbit's rhyme.


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

@roy-dydx roy-dydx marked this pull request as ready for review July 9, 2024 14:50
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 b0ca050 and 6cd5293.

Files selected for processing (20)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (8 hunks)
  • protocol/x/clob/e2e/app_test.go (3 hunks)
  • protocol/x/clob/e2e/long_term_orders_test.go (1 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (1 hunks)
  • protocol/x/clob/keeper/msg_server_cancel_orders_test.go (1 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (1 hunks)
  • protocol/x/clob/keeper/order_cancellation_test.go (8 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (3 hunks)
  • protocol/x/clob/keeper/process_operations_test.go (2 hunks)
  • protocol/x/clob/keeper/process_proposer_matches_events.go (6 hunks)
  • protocol/x/clob/keeper/process_proposer_matches_events_test.go (2 hunks)
  • protocol/x/clob/keeper/stateful_order_state.go (5 hunks)
  • protocol/x/clob/keeper/stateful_order_state_test.go (17 hunks)
  • protocol/x/clob/keeper/stores.go (1 hunks)
  • protocol/x/clob/types/clob_keeper.go (2 hunks)
  • protocol/x/clob/types/keys.go (1 hunks)
  • protocol/x/clob/types/keys_test.go (1 hunks)
  • protocol/x/clob/types/mem_clob_keeper.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • protocol/x/clob/keeper/stores.go
  • protocol/x/clob/types/clob_keeper.go
  • protocol/x/clob/types/keys_test.go
Additional comments not posted (61)
protocol/x/clob/types/keys.go (2)

56-58: Deprecation Notice: LegacyStatefulOrdersTimeSlicePrefix

The LegacyStatefulOrdersTimeSlicePrefix is marked as deprecated. Ensure this prefix is not used in new code.


60-62: New Key Prefix: StatefulOrdersExpirationsKeyPrefix

A new key prefix StatefulOrdersExpirationsKeyPrefix has been introduced. Ensure this is used consistently across the codebase.

protocol/x/clob/keeper/process_proposer_matches_events.go (17)

8-8: New Import: storetypes

The storetypes package is imported. Ensure it is used correctly and consistently.


75-76: Store Instance: memStore

The memStore instance is correctly retrieved using ctx.KVStore(k.memKey).


79-85: Function Call: ResetOrderedOrderIds

The ResetOrderedOrderIds function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


96-96: Function Call: AppendOrderedOrderId

The AppendOrderedOrderId function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


108-108: Function Call: AppendOrderedOrderId

The AppendOrderedOrderId function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


118-118: Function Call: SetUnorderedOrderId

The SetUnorderedOrderId function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


123-123: Function Call: GetOrderIds

The GetOrderIds function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


128-128: Function Call: GetOrderIds

The GetOrderIds function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


133-133: Function Call: GetOrderIds

The GetOrderIds function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


139-139: Function Call: HasUnorderedOrderId

The HasUnorderedOrderId function now takes an additional store parameter. Ensure all calls to this function are updated accordingly.


142-150: Function Update: ResetOrderedOrderIds

The ResetOrderedOrderIds function now takes an additional store parameter. Ensure the new implementation correctly resets the ordered order IDs.


153-157: Function Update: ResetUnorderedOrderIds

The ResetUnorderedOrderIds function now takes an additional store parameter. Ensure the new implementation correctly resets the unordered order IDs.


163-178: Function Update: AppendOrderedOrderId

The AppendOrderedOrderId function now takes an additional store parameter. Ensure the new implementation correctly appends the ordered order IDs.


Line range hint 183-193:
Function Update: GetOrderIds

The GetOrderIds function now takes an additional store parameter. Ensure the new implementation correctly retrieves the order IDs.


199-204: Function Update: HasUnorderedOrderId

The HasUnorderedOrderId function now takes an additional store parameter. Ensure the new implementation correctly checks the existence of unordered order IDs.


209-214: Function Update: SetUnorderedOrderId

The SetUnorderedOrderId function now takes an additional store parameter. Ensure the new implementation correctly sets the unordered order IDs.


217-224: New Function: RemoveUnorderedOrderId

The RemoveUnorderedOrderId function is a new addition. Ensure this function is used correctly and consistently across the codebase.

protocol/x/clob/keeper/process_proposer_matches_events_test.go (6)

200-201: Store Instance: memStore

The memStore instance is correctly retrieved using ks.Ctx.KVStore(ks.MemKey).


203-205: Function Call: AppendOrderedOrderId

The AppendOrderedOrderId function now takes an additional memStore parameter. Ensure all calls to this function are updated accordingly.


207-211: Function Calls: ResetOrderedOrderIds and AppendOrderedOrderId

The ResetOrderedOrderIds and AppendOrderedOrderId functions now take an additional memStore parameter. Ensure all calls to these functions are updated accordingly.


241-242: Store Instance: memStore

The memStore instance is correctly retrieved using ks.Ctx.KVStore(ks.MemKey).


244-246: Function Call: SetUnorderedOrderId

The SetUnorderedOrderId function now takes an additional memStore parameter. Ensure all calls to this function are updated accordingly.


248-252: Function Calls: ResetOrderedOrderIds and SetUnorderedOrderId

The ResetOrderedOrderIds and SetUnorderedOrderId functions now take an additional memStore parameter. Ensure all calls to these functions are updated accordingly.

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

229-229: LGTM! Ensure the correctness of the new function usage.

The new function AddStatefulOrderIdExpiration is correctly used. Ensure that it behaves as expected in all test cases.

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

64-64: LGTM! Ensure the correctness of the new function usage.

The new function RemoveExpiredStatefulOrders is correctly used. Ensure that it behaves as expected in all scenarios.

protocol/x/clob/keeper/stateful_order_state.go (5)

178-188: LGTM! Ensure the correctness of the new function.

The new function GetStatefulOrderIdExpirations is correctly implemented. Ensure that it behaves as expected in all scenarios.


190-203: LGTM! Ensure the correctness of the new function.

The new function RemoveStatefulOrderIdExpiration is correctly implemented. Ensure that it behaves as expected in all scenarios.


205-218: LGTM! Ensure the correctness of the new function.

The new function AddStatefulOrderIdExpiration is correctly implemented. Ensure that it behaves as expected in all scenarios.


220-238: LGTM! Ensure the correctness of the new function.

The new function RemoveExpiredStatefulOrders is correctly implemented. Ensure that it behaves as expected in all scenarios.


326-326: LGTM! Ensure the correctness of the new function usage.

The new function RemoveStatefulOrderIdExpiration is correctly used. Ensure that it behaves as expected in all scenarios.

protocol/x/clob/keeper/order_cancellation_test.go (2)

149-149: LGTM! Ensure the correctness of the new function usage.

The new function AddStatefulOrderIdExpiration is correctly used. Ensure that it behaves as expected in all test cases.


260-260: LGTM! Ensure the correctness of the new function usage.

The new function AddStatefulOrderIdExpiration is correctly used. Ensure that it behaves as expected in all test cases.

Also applies to: 289-289, 310-310, 330-330, 351-351, 371-371, 391-391

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

209-211: Ensure proper cleanup of stateful order ID expirations.

The addition of stateful order ID expirations is correctly implemented. However, ensure that these expirations are properly cleaned up after each test case to avoid state leakage between tests.

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

367-369: Ensure proper handling of stateful order ID expirations.

The addition of stateful order ID expirations is correctly implemented. Ensure that the expirations are properly managed and cleaned up to avoid state inconsistencies.


443-445: Ensure proper handling of stateful order ID expirations.

The addition of stateful order ID expirations is correctly implemented. Ensure that the expirations are properly managed and cleaned up to avoid state inconsistencies.

Also applies to: 455-457

protocol/x/clob/keeper/stateful_order_state_test.go (9)

41-44: LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


Line range hint 476-517:
LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


607-613: LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


654-658: LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


671-675: LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


Line range hint 706-716:
LGTM!

The changes align with the new function name GetStatefulOrderIdExpirations.


732-741: LGTM!

The changes align with the new function name RemoveExpiredStatefulOrders.


848-853: LGTM!

The changes align with the new function name AddStatefulOrderIdExpiration.


Line range hint 860-865:
LGTM!

The changes align with the new function name RemoveExpiredStatefulOrders.

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

666-666: Verify the usage of AddStatefulOrderIdExpiration.

Ensure that the new function AddStatefulOrderIdExpiration is used correctly and integrates well with the rest of the code. Verify that it correctly handles the order ID expirations as intended.

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

401-403: Ensure proper handling of stateful order expiration.

The addition of AddStatefulOrderIdExpiration looks correct. Ensure that the order.MustGetUnixGoodTilBlockTime() and order.GetOrderId() are correctly handled and validated before this call.

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

Line range hint 85-89: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


Line range hint 249-253: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


292-296: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


Line range hint 480-484: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


Line range hint 496-500: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


Line range hint 522-526: Correctness: Verify the function call replacement.

The function call MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function is correctly handling the stateful order ID expiration.


811-812: Correctness: Verify the function call replacement.

The function call GetStatefulOrdersTimeSlice has been replaced with GetStatefulOrderIdExpirations. Ensure that the new function is correctly handling the stateful order ID expirations.

protocol/x/clob/e2e/long_term_orders_test.go (1)

1782-1783: Ensure correct usage of AddStatefulOrderIdExpiration.

The added code segment correctly uses AddStatefulOrderIdExpiration to add the order ID to the expiration state. Ensure that the expiration time and order ID are correctly managed in the context.

protocol/x/clob/keeper/orders_test.go (3)

863-865: Verify correctness of function replacement.

The function MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function correctly handles the addition of stateful order ID expirations.


884-886: Verify correctness of function replacement.

The function MustAddOrderToStatefulOrdersTimeSlice has been replaced with AddStatefulOrderIdExpiration. Ensure that the new function correctly handles the addition of stateful order ID expirations.


906-907: Verify correctness of function replacement.

The function GetStatefulOrdersTimeSlice has been replaced with GetStatefulOrderIdExpirations. Ensure that the new function correctly retrieves stateful order ID expirations.

protocol/x/clob/keeper/process_operations_test.go (2)

2474-2476: Correctly replaced function call.

The function MustAddOrderToStatefulOrdersTimeSlice has been correctly replaced with AddStatefulOrderIdExpiration.


Line range hint 2486-2490:
Correctly replaced function call and added necessary trigger.

The function MustAddOrderToStatefulOrdersTimeSlice has been correctly replaced with AddStatefulOrderIdExpiration, and the necessary trigger for the conditional order has been added.

Comment on lines 229 to 230
// Increment the byte representation of `/` at the end of the prefix so that blockTime is included in the iteration
end[len(end)-1] += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

can this overflow? not sure what formatted time string this is using

there is a util function in sdk store types, which might be better

// InclusiveEndBytes returns the []byte that would end a
// range query such that the input would be included
func InclusiveEndBytes(inclusiveBytes []byte) []byte {
	return append(inclusiveBytes, byte(0x00))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the key prefix is Exp/%s:, if you do that, you'd get Exp/{time}:\00 as the exclusive end, which would not cover all the keys that the orders are stored it. For example `"Exp/{time}:{order_id}" would not get iterated over.

The idea is to increment the byte representation of : by 1 so that all order ids at the ending time would be included.

If you can think of better ways of doing this, I'm open to it.

Copy link
Contributor

@teddyding teddyding Jul 9, 2024

Choose a reason for hiding this comment

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

Thinking out loud - could we define another constant StatefulOrdersExpirationsKeyPrefixExclusiveEnd = "Exp/%s;", and do end := []byte(fmt.Sprintf(types.StatefulOrdersExpirationsKeyPrefixExclusiveEnd, sdk.FormatTimeString(blockTime)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's pretty much the same thing though.

Copy link
Contributor

Choose a reason for hiding this comment

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

there is also another function that we can use called PrefixEndBytes

// PrefixEndBytes returns the []byte that would end a
// range query for all []byte with a certain prefix
// Deals with last byte of prefix being FF without overflowing
func PrefixEndBytes(prefix []byte) []byte {
	if len(prefix) == 0 {
		return nil
	}

	end := make([]byte, len(prefix))
	copy(end, prefix)

	for {
		if end[len(end)-1] != byte(255) {
			end[len(end)-1]++
			break
		}

		end = end[:len(end)-1]

		if len(end) == 0 {
			end = nil
			break
		}
	}

	return end
}

Copy link
Contributor

@jayy04 jayy04 Jul 9, 2024

Choose a reason for hiding this comment

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

which handles overflow

memStore := ctx.KVStore(k.memKey)
store := prefix.NewStore(memStore, []byte(keyPrefix))
it := store.Iterator(nil, nil)
func (k Keeper) ResetUnorderedOrderIds(ctx sdk.Context, store storetypes.KVStore, keyPrefix string) {
Copy link
Contributor

@teddyding teddyding Jul 9, 2024

Choose a reason for hiding this comment

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

For my understanding what's the motivation behind changing this interface? Do we plan to call this with any store other than memstore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using it with persisted KVStore in this PR.

@@ -1216,12 +795,6 @@ func TestRemoveExpiredStatefulOrdersTimeSlices(t *testing.T) {
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test where multiple orders under the inclusive end blocktime are all removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified the existing test to cover this

store := ctx.KVStore(k.storeKey)
start := []byte(fmt.Sprintf(types.StatefulOrdersExpirationsKeyPrefix, sdk.FormatTimeString(time.Time{})))
end := []byte(fmt.Sprintf(types.StatefulOrdersExpirationsKeyPrefix, sdk.FormatTimeString(blockTime)))
// Increment the byte representation of `/` at the end of the prefix so that blockTime is included in the iteration
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Increment the byte representation of `/` at the end of the prefix so that blockTime is included in the iteration
// Increment the byte representation of `:` at the end of the prefix so that blockTime is included in the iteration

Do you mean this, given the key prefix format is Exp/%s:?

// GetStatefulOrdersTimeSlice gets a slice of stateful order IDs that expire at `goodTilBlockTime`,
// sorted by order ID.
func (k Keeper) GetStatefulOrdersTimeSlice(ctx sdk.Context, goodTilBlockTime time.Time) (
// GetStatefulOrderIdExpirations gets a slice stateful order IDs that expire at `goodTilBlockTime`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// GetStatefulOrderIdExpirations gets a slice stateful order IDs that expire at `goodTilBlockTime`,
// GetStatefulOrderIdExpirations gets a slice of stateful order IDs that expire at `goodTilBlockTime`,

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 6cd5293 and 53d65e3.

Files selected for processing (20)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (8 hunks)
  • protocol/x/clob/e2e/app_test.go (3 hunks)
  • protocol/x/clob/e2e/long_term_orders_test.go (1 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (1 hunks)
  • protocol/x/clob/keeper/msg_server_cancel_orders_test.go (1 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (1 hunks)
  • protocol/x/clob/keeper/order_cancellation_test.go (8 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (3 hunks)
  • protocol/x/clob/keeper/process_operations_test.go (2 hunks)
  • protocol/x/clob/keeper/process_proposer_matches_events.go (6 hunks)
  • protocol/x/clob/keeper/process_proposer_matches_events_test.go (2 hunks)
  • protocol/x/clob/keeper/stateful_order_state.go (5 hunks)
  • protocol/x/clob/keeper/stateful_order_state_test.go (17 hunks)
  • protocol/x/clob/keeper/stores.go (1 hunks)
  • protocol/x/clob/types/clob_keeper.go (2 hunks)
  • protocol/x/clob/types/keys.go (1 hunks)
  • protocol/x/clob/types/keys_test.go (1 hunks)
  • protocol/x/clob/types/mem_clob_keeper.go (2 hunks)
Files not summarized due to errors (1)
  • protocol/x/clob/keeper/stateful_order_state_test.go: Error: Message exceeds token limit
Files skipped from review due to trivial changes (2)
  • protocol/x/clob/keeper/msg_server_cancel_orders_test.go
  • protocol/x/clob/types/mem_clob_keeper.go
Files skipped from review as they are similar to previous changes (12)
  • protocol/x/clob/abci.go
  • protocol/x/clob/e2e/app_test.go
  • protocol/x/clob/keeper/clob_pair_test.go
  • protocol/x/clob/keeper/msg_server_place_order_test.go
  • protocol/x/clob/keeper/order_cancellation_test.go
  • protocol/x/clob/keeper/orders_test.go
  • protocol/x/clob/keeper/process_proposer_matches_events.go
  • protocol/x/clob/keeper/process_proposer_matches_events_test.go
  • protocol/x/clob/keeper/stateful_order_state.go
  • protocol/x/clob/keeper/stores.go
  • protocol/x/clob/types/clob_keeper.go
  • protocol/x/clob/types/keys.go
Additional comments not posted (16)
protocol/x/clob/keeper/orders.go (1)

401-403: Ensure correct expiration handling for stateful orders.

The addition of AddStatefulOrderIdExpiration appears to correctly handle the expiration of stateful orders by adding them to the expiration list. Ensure that the order.MustGetUnixGoodTilBlockTime() and order.GetOrderId() return the correct values and are consistent with the rest of the system.

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

85-88: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


249-252: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


292-295: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


480-483: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


496-499: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


522-525: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.


811-814: Ensure correctness of AddStatefulOrderIdExpiration usage.

The function AddStatefulOrderIdExpiration is correctly used to add stateful order ID expirations. Ensure that this change aligns with the new expiration management logic.

protocol/x/clob/e2e/long_term_orders_test.go (1)

1782-1782: Ensure proper handling of stateful order expirations.

The addition of AddStatefulOrderIdExpiration is appropriate for managing stateful order expirations. Verify that the expiration logic aligns with the new stateful order management implementation.

protocol/x/clob/keeper/process_operations_test.go (2)

2474-2475: LGTM! Ensure proper order expiration tracking.

The addition of AddStatefulOrderIdExpiration ensures that the order expiration is tracked correctly.


2486-2487: LGTM! Ensure proper order expiration tracking.

The addition of AddStatefulOrderIdExpiration ensures that the order expiration is tracked correctly.

protocol/x/clob/keeper/stateful_order_state_test.go (5)

41-41: LGTM!

The function createPartiallyFilledStatefulOrderInState correctly calls AddStatefulOrderIdExpiration.


476-476: Well-structured test cases.

The test function TestGetAddAndRemoveStatefulOrderExpirations is comprehensive and covers various scenarios effectively.


732-732: Well-structured test cases.

The test function TestRemoveExpiredStatefulOrders is comprehensive and covers various scenarios effectively.


793-793: Comprehensive test case.

The test case "Deletes all time slices before blockTime inclusive" ensures correct removal of all time slices before and including the block time.


805-805: Comprehensive test case.

The test case "Does not delete time slices after blockTime" ensures that time slices after the block time are not deleted.

constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTB30.OrderId,
},
constants.Time_21st_Feb_2021.Add(77): {
constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10.OrderId,
constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20.OrderId,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a test for multiple orders under the same block time.

Adding a test where multiple orders under the inclusive end block time are all removed would enhance coverage.

Do you want me to add this test case or open a GitHub issue to track this task?

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.

4 participants