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

refactor(perp): use collections for state management #952

Merged
merged 24 commits into from
Sep 22, 2022

Conversation

testinginprod
Copy link
Collaborator

@testinginprod testinginprod commented Sep 19, 2022

Description

Moves perp positions to collections
Implements query positions by traders.

Purpose

@testinginprod testinginprod marked this pull request as ready for review September 19, 2022 17:03
@testinginprod testinginprod requested a review from a team as a code owner September 19, 2022 17:03
@testinginprod testinginprod changed the title refactor(perp): use collections for position state management refactor(perp): use collections for state management Sep 20, 2022
@testinginprod testinginprod enabled auto-merge (squash) September 20, 2022 13:07
@AgentSmithMatrix
Copy link
Contributor

Why is failing for me on Go test in my local?

@testinginprod
Copy link
Collaborator Author

Why is failing for me on Go test in my local?

go1.19 has a compiler bug

@testinginprod
Copy link
Collaborator Author

In order to make this pr easier to review I will address #931 in another PR.


// 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) {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these used anywhere?

Copy link
Collaborator Author

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

x/perp/genesis.go Outdated Show resolved Hide resolved
x/perp/genesis.go Outdated Show resolved Hide resolved
x/perp/genesis.go Outdated Show resolved Hide resolved
x/perp/keeper/state_test.go Show resolved Hide resolved
x/perp/keeper/perp_test.go Show resolved Hide resolved
@@ -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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

x/perp/keeper/state.go Outdated Show resolved Hide resolved
@NibiruHeisenberg NibiruHeisenberg self-requested a review September 22, 2022 00:03
x/perp/keeper/withdraw.go Outdated Show resolved Hide resolved
x/perp/keeper/withdraw.go Outdated Show resolved Hide resolved
@testinginprod testinginprod enabled auto-merge (squash) September 22, 2022 09:56
@testinginprod testinginprod merged commit 94cbcf7 into master Sep 22, 2022
@testinginprod testinginprod deleted the mercilex/perp-collections branch September 22, 2022 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor(perp): align the state keeper to be in line with lockup and incentivization modules
4 participants