-
Notifications
You must be signed in to change notification settings - Fork 193
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
refactor(perp): use collections for state management #952
Conversation
Why is failing for me on Go test in my local? |
go1.19 has a compiler bug |
In order to make this pr easier to review I will address #931 in another PR. |
collections/index_multi.go
Outdated
|
||
// Insert inserts fetches the index key IK from the object v. | ||
// And then maps the index key to the primary key. | ||
func (i *MultiIndex[IK, PK, V]) Insert(ctx sdk.Context, pk PK, v V) { |
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.
Can you add unit tests for MultiIndex
?
// K1 returns the first part of the key, | ||
// if present. If the key is not present | ||
// the zero value is returned. | ||
func (t Pair[K1, K2]) K1() K1 { |
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.
Are these used anywhere?
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.
Leftovers from multi index... but we can keep this since it's going to be needed
@@ -35,7 +35,7 @@ func (m msgServer) RemoveMargin(ctx context.Context, msg *types.MsgRemoveMargin, | |||
return &types.MsgRemoveMarginResponse{ | |||
MarginOut: marginOut, | |||
FundingPayment: fundingPayment, | |||
Position: position, | |||
Position: &position, |
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.
Is there a benefit to returning a pointer in the response?
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.
we avoid the copy but it's more because proto imposes pointers on every message
@@ -62,7 +68,7 @@ func (q queryServer) QueryTraderPosition( | |||
} | |||
|
|||
return &types.QueryTraderPositionResponse{ | |||
Position: position, | |||
Position: &position, |
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.
Is there a benefit to returning a pointer in the response?
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.
we avoid the copy but it's more because proto imposes pointers on every message
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.
What if we set (gogoproto.nullable) = false
?
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.
we break proto API, because then it's impossible to assert presence on the msg, there are some cases in which it's done in the sdk but im not a fan if i have to be honest.
Description
Moves perp positions to collections
Implements query positions by traders.
Purpose