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-209] Skip various order placement logic for vault orders #1332

Merged
merged 2 commits into from
Apr 4, 2024
Merged

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Apr 4, 2024

Changelist

skip following for vault orders: persistent tags, deferred logs / metrics, cancellation / removal check, equity tier limit check, collateralization check

Test Plan

existing / new unit 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.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Walkthrough

The updates involve enhancing the order placement functionality in a trading protocol to differentiate between internal and external orders. By introducing the isInternalOrder boolean parameter in key function signatures, the system can now handle internal orders differently, skipping certain checks. These changes are implemented across various protocol components, including mocks, keeper logic, and test cases, ensuring comprehensive integration and validation of the new order handling logic.

Changes

File(s) Change Summary
protocol/mocks/ClobKeeper.go
protocol/x/clob/types/clob_keeper.go
protocol/x/vault/types/expected_keepers.go
Added isInternalOrder bool parameter to HandleMsgPlaceOrder and PlaceStatefulOrder methods.
protocol/x/clob/keeper/.../msg_server_place_order.go
protocol/x/clob/keeper/orders.go
Updated function signatures to include isInternalOrder and modified PlaceStatefulOrder logic for internal orders.
protocol/x/clob/ante/clob.go
protocol/x/clob/ante/clob_test.go
protocol/x/clob/keeper/.../msg_server_place_order_test.go
protocol/x/clob/keeper/orders_test.go
Adjusted method calls to include the new isInternalOrder parameter; added and updated tests.
protocol/x/vault/keeper/orders.go
protocol/x/vault/keeper/orders_test.go
Refactored order placement to use PlaceVaultClobOrder, adapting to the updated order handling logic.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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/coderabbit-overrides.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: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 39981f1 and 55e9013.
Files selected for processing (11)
  • protocol/mocks/ClobKeeper.go (3 hunks)
  • protocol/x/clob/ante/clob.go (1 hunks)
  • protocol/x/clob/ante/clob_test.go (4 hunks)
  • protocol/x/clob/keeper/msg_server_place_order.go (2 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (2 hunks)
  • protocol/x/clob/keeper/orders.go (3 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/types/clob_keeper.go (2 hunks)
  • protocol/x/vault/keeper/orders.go (2 hunks)
  • protocol/x/vault/keeper/orders_test.go (1 hunks)
  • protocol/x/vault/types/expected_keepers.go (1 hunks)
Files not reviewed due to errors (1)
  • (no review received)
Additional Context Used
Path-based Instructions (11)
protocol/x/vault/types/expected_keepers.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/types/clob_keeper.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/ante/clob_test.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/vault/keeper/orders_test.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/mocks/ClobKeeper.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

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

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Learnings (1)
protocol/x/clob/ante/clob_test.go (1)
User: jonfung-dydx"
PR: dydxprotocol/v4-chain#1009
File: protocol/x/clob/memclob/memclob_place_order_test.go:4108-4108
Timestamp: 2024-02-05T20:01:55.204Z
Learning: The `assertPlaceOrderOffchainMessages` function in `memclob_test_util.go` indeed requires `ctx` as a parameter for its operations, contrary to the initial comment made.
Additional comments not posted (14)
protocol/x/vault/types/expected_keepers.go (1)

29-29: The addition of the isInternalOrder parameter to the HandleMsgPlaceOrder function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.

protocol/x/clob/types/clob_keeper.go (2)

50-50: The addition of the isInternalOrder parameter to the HandleMsgPlaceOrder function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.


60-64: The addition of the isInternalOrder parameter to the PlaceStatefulOrder method is aligned with the PR objectives and introduces a clear way to differentiate internal orders.

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

28-28: Ensure that the addition of the isInternalOrder parameter and the conditional logic based on it in the HandleMsgPlaceOrder function do not compromise the system's integrity by skipping necessary validations or metrics for internal orders.

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

88-88: The addition of the false parameter to the PlaceStatefulOrder function call is aligned with the PR objectives and introduces a clear way to differentiate internal orders.

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

86-86: The introduction of the PlaceVaultClobOrder method and its usage in the RefreshVaultClobOrders method is aligned with the PR objectives and introduces a clear way to differentiate internal orders.

protocol/x/clob/ante/clob_test.go (4)

103-103: The addition of the false parameter to the PlaceStatefulOrder method calls in the test function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.


117-117: The addition of the false parameter to the PlaceStatefulOrder method calls in the test function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.


160-160: The addition of the false parameter to the PlaceStatefulOrder method calls in the test function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.


189-189: The addition of the false parameter to the PlaceStatefulOrder method calls in the test function is aligned with the PR objectives and introduces a clear way to differentiate internal orders.

protocol/x/vault/keeper/orders_test.go (1)

112-112: Replace direct calls to HandleMsgPlaceOrder with PlaceVaultClobOrder to streamline the order placement process for vault orders.

-						err := tApp.App.ClobKeeper.HandleMsgPlaceOrder(ctx, order)
+						err := tApp.App.VaultKeeper.PlaceVaultClobOrder(ctx, order)

This change correctly aligns with the PR objectives to optimize the order placement process for vault orders by introducing a more streamlined method for placing these orders.

protocol/mocks/ClobKeeper.go (1)

962-972: Ensure that the new isInternalOrder parameter in PlaceStatefulOrder is properly documented to explain its purpose and effect on the function's behavior.

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

358-394: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [307-391]

Consider adding a comment explaining the purpose of the isInternalOrder parameter for future maintainability.

func (k Keeper) PlaceStatefulOrder(
	ctx sdk.Context,
	msg *types.MsgPlaceOrder,
+	// isInternalOrder indicates if the order is internal to the protocol, which affects certain checks.
	isInternalOrder bool,
) (err error) {

358-394: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [307-391]

Ensure that all external calls to PlaceStatefulOrder have been updated to include the new isInternalOrder parameter.

Verification successful

The verification process did not find any calls to PlaceStatefulOrder with exactly three parameters, suggesting that all external calls to this function have been correctly updated to include the new isInternalOrder parameter. This supports the conclusion that the review comment has been addressed in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to PlaceStatefulOrder without the isInternalOrder parameter. Expecting no results.
ast-grep --lang go --pattern $'PlaceStatefulOrder($_, $_, $_)'

Length of output: 63

protocol/mocks/ClobKeeper.go Show resolved Hide resolved
protocol/x/clob/keeper/msg_server_place_order_test.go Outdated Show resolved Hide resolved
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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 39981f1 and 0055fb2.
Files selected for processing (11)
  • protocol/mocks/ClobKeeper.go (3 hunks)
  • protocol/x/clob/ante/clob.go (1 hunks)
  • protocol/x/clob/ante/clob_test.go (4 hunks)
  • protocol/x/clob/keeper/msg_server_place_order.go (2 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (2 hunks)
  • protocol/x/clob/keeper/orders.go (3 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/types/clob_keeper.go (2 hunks)
  • protocol/x/vault/keeper/orders.go (2 hunks)
  • protocol/x/vault/keeper/orders_test.go (1 hunks)
  • protocol/x/vault/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (11)
  • protocol/mocks/ClobKeeper.go
  • protocol/x/clob/ante/clob.go
  • protocol/x/clob/ante/clob_test.go
  • protocol/x/clob/keeper/msg_server_place_order.go
  • protocol/x/clob/keeper/msg_server_place_order_test.go
  • protocol/x/clob/keeper/orders.go
  • protocol/x/clob/keeper/orders_test.go
  • protocol/x/clob/types/clob_keeper.go
  • protocol/x/vault/keeper/orders.go
  • protocol/x/vault/keeper/orders_test.go
  • protocol/x/vault/types/expected_keepers.go

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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b5ed196 and 0a6f18f.
Files selected for processing (10)
  • protocol/mocks/ClobKeeper.go (3 hunks)
  • protocol/x/clob/ante/clob.go (1 hunks)
  • protocol/x/clob/ante/clob_test.go (4 hunks)
  • protocol/x/clob/keeper/msg_server_place_order.go (2 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (2 hunks)
  • protocol/x/clob/keeper/orders.go (3 hunks)
  • protocol/x/clob/types/clob_keeper.go (2 hunks)
  • protocol/x/vault/keeper/orders.go (2 hunks)
  • protocol/x/vault/keeper/orders_test.go (1 hunks)
  • protocol/x/vault/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • protocol/mocks/ClobKeeper.go
  • protocol/x/clob/ante/clob.go
  • protocol/x/clob/ante/clob_test.go
  • protocol/x/clob/keeper/msg_server_place_order.go
  • protocol/x/clob/keeper/msg_server_place_order_test.go
  • protocol/x/clob/keeper/orders.go
  • protocol/x/clob/types/clob_keeper.go
  • protocol/x/vault/keeper/orders.go
  • protocol/x/vault/keeper/orders_test.go
  • protocol/x/vault/types/expected_keepers.go

Comment on lines 336 to 340
err := k.clobKeeper.HandleMsgPlaceOrder(ctx, clobtypes.NewMsgPlaceOrder(*order), true)
if err != nil {
return err
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just return err here

Comment on lines 91 to 107
if !isInternalOrder {
cancelledOrderIds := lib.UniqueSliceToSet(processProposerMatchesEvents.PlacedStatefulCancellationOrderIds)
if _, found := cancelledOrderIds[order.GetOrderId()]; found {
return errorsmod.Wrapf(
types.ErrStatefulOrderPreviouslyCancelled,
"PlaceOrder: order (%+v)",
order,
)
}
removedOrderIds := lib.UniqueSliceToSet(processProposerMatchesEvents.RemovedStatefulOrderIds)
if _, found := removedOrderIds[order.GetOrderId()]; found {
return errorsmod.Wrapf(
types.ErrStatefulOrderPreviouslyRemoved,
"PlaceOrder: order (%+v)",
order,
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

on a second thought - this isn't too expensive, right? let's maybe keep this to keep the logic consistent?

Comment on lines 48 to 55
// Attach various logging tags relative to this request. These should be static with no changes.
ctx = log.AddPersistentTagsToLogger(ctx,
log.Module, log.Clob,
log.ProposerConsAddress, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress),
log.Callback, lib.TxMode(ctx),
log.BlockHeight, ctx.BlockHeight(),
log.Handler, log.PlaceOrder,
log.Msg, msg,
Copy link
Contributor

Choose a reason for hiding this comment

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

let's also keep the persistent tags at the for the initial version. in case we have issues this helps us debug

can skip the defered func below

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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0a6f18f and b8ed41c.
Files selected for processing (3)
  • protocol/x/clob/keeper/msg_server_place_order.go (4 hunks)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (2 hunks)
  • protocol/x/vault/keeper/orders.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/x/clob/keeper/msg_server_place_order.go
  • protocol/x/clob/keeper/msg_server_place_order_test.go
  • protocol/x/vault/keeper/orders.go

@tqin7 tqin7 merged commit 8e3ac79 into main Apr 4, 2024
16 checks passed
@tqin7 tqin7 deleted the tq/tra-209 branch April 4, 2024 17:24
tqin7 added a commit that referenced this pull request Apr 4, 2024
* Skip various order placement logic for vault orders
@tqin7
Copy link
Contributor Author

tqin7 commented Apr 4, 2024

@Mergifyio backport release/protocol/v5.x

Copy link
Contributor

mergify bot commented Apr 4, 2024

backport release/protocol/v5.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Apr 4, 2024
* Skip various order placement logic for vault orders

(cherry picked from commit 8e3ac79)
tqin7 added a commit that referenced this pull request Apr 4, 2024
…#1337)

* Skip various order placement logic for vault orders

(cherry picked from commit 8e3ac79)

Co-authored-by: Tian <tian@dydx.exchange>
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