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
[CLOB-1054] state R/W methods for last trade price #910
Conversation
WalkthroughThe recent changes involve the introduction of functionality for managing and tracking the last trade prices of perpetual contracts within the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit's AI:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (4)
- protocol/x/clob/keeper/match_state.go (1 hunks)
- protocol/x/clob/keeper/match_state_test.go (1 hunks)
- protocol/x/clob/keeper/stores.go (1 hunks)
- protocol/x/clob/types/keys.go (1 hunks)
Additional comments: 4
protocol/x/clob/keeper/match_state.go (2)
10-25: The
GetLastTradePriceForPerpetual
method is implemented correctly, ensuring that the last trade price is retrieved from the memory store and unmarshaled properly.27-40: The
SetLastTradePriceForPerpetual
method is implemented correctly, ensuring that the last trade price is set in the memory store as expected.protocol/x/clob/types/keys.go (1)
- 78-80: The addition of the
LastTradePricePrefix
constant is appropriate for its intended use in retrieving the last trade price for a perpetual.protocol/x/clob/keeper/stores.go (1)
- 154-161: The
GetLastTradePriceMemStore
function is implemented correctly, creating a new prefix store for last trade prices using the appropriate byte prefix.
func TestGetSetLastTradePrice(t *testing.T) { | ||
// Setup keeper state and test parameters. | ||
memClob := memclob.NewMemClobPriceTimePriority(false) | ||
ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, &mocks.IndexerEventManager{}) | ||
|
||
// Get non-existent last trade price. | ||
price, found := ks.ClobKeeper.GetLastTradePriceForPerpetual(ks.Ctx, 0) | ||
require.Equal(t, price, types.Subticks(0)) | ||
require.False(t, found) | ||
|
||
// Set last trade price. | ||
ks.ClobKeeper.SetLastTradePriceForPerpetual(ks.Ctx, 0, types.Subticks(17)) | ||
|
||
// Get the last trade price, which should now exist. | ||
price, found = ks.ClobKeeper.GetLastTradePriceForPerpetual(ks.Ctx, 0) | ||
require.Equal(t, price, types.Subticks(17)) | ||
require.True(t, found) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test TestGetSetLastTradePrice
correctly checks the basic functionality of getting and setting the last trade price. Consider adding more test cases to cover edge cases, such as invalid perpetual IDs, concurrent access, and error handling scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- protocol/x/clob/keeper/match_state.go (1 hunks)
- protocol/x/clob/keeper/stores.go (1 hunks)
- protocol/x/clob/types/keys.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- protocol/x/clob/keeper/match_state.go
- protocol/x/clob/keeper/stores.go
Additional comments: 2
protocol/x/clob/types/keys.go (2)
56-58: The addition of the
LastTradePricePrefix
constant is consistent with the naming conventions and purpose of other constants in the file. Ensure that the new key prefix does not overlap with existing prefixes to avoid key collisions.52-60: The new constant
LastTradePricePrefix
is well-placed within theState
constants section and follows the existing pattern for key prefixes. It's important to verify that the new key prefix is integrated correctly in the codebase where it's intended to be used.Verification successful
The search results confirm that the
LastTradePricePrefix
constant is being used in thestores.go
file within theclob
module, which aligns with the intended purpose of the constant as described in the PR objectives and the AI-generated summaries. This suggests that the constant has been integrated into the codebase where it is meant to be used for accessing the last trade price for a perpetual.
- The constant is defined in
keys.go
as expected.- It is used in
stores.go
to presumably construct a key for data retrieval.Based on the information provided, there are no conflicts or issues with the integration of the new constant
LastTradePricePrefix
in the codebase.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usage of LastTradePricePrefix to ensure it's being used correctly. rg --type go 'LastTradePricePrefix'Length of output: 296
Changelist
Test Plan
[Describe how this PR was tested (if applicable)]
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.