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

dex: track total number of positions per pair #4167

Merged
merged 6 commits into from
Apr 8, 2024

Conversation

erwanor
Copy link
Member

@erwanor erwanor commented Apr 5, 2024

Describe your changes

Working towards achieving #4077.

This PR adds a PositionCounter extension trait which implements a TradingPair scoped position counter. I am not totally sold on a u16 for the counter type, yet, but it's useful for testing anyway.

Checklist before requesting a review

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

    This is consensus-breaking because it introduces a new implicit validation rule: a hard-limit on the number of position opened for each trading pair (via counter overflow). It could also be consensus breaking if there was a bug in the DEX that allowed closed positions to be updated, but my assumption is that it's not the case.

@erwanor erwanor added the A-dex Area: Relates to the dex label Apr 5, 2024
@erwanor erwanor added this to the Sprint 3 milestone Apr 5, 2024
@erwanor erwanor added A-shielded-crypto Area: Cryptographic design for Penumbra's shielded transaction model consensus-breaking breaking change to execution of on-chain data and removed A-shielded-crypto Area: Cryptographic design for Penumbra's shielded transaction model labels Apr 5, 2024
@erwanor erwanor marked this pull request as ready for review April 6, 2024 01:28
@erwanor
Copy link
Member Author

erwanor commented Apr 8, 2024

I am going to merge this because the full eviction mechanism relies on it, but feel free to review asynchronously (please). I have three other separate PRs:

@erwanor erwanor merged commit 65b8498 into main Apr 8, 2024
7 checks passed
@erwanor erwanor deleted the erwan/4077_position_counter branch April 8, 2024 15:17
Copy link
Contributor

@cratelyn cratelyn left a comment

Choose a reason for hiding this comment

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

✔️

erwanor added a commit that referenced this pull request Apr 9, 2024
## Describe your changes

This PR implements an inventory index, together with #4167, this PR
works toward #4077 which contain the full eviction mechanism along with
the adequate protocol specification update.


The state key added:

- $\text{I}_{A \rightarrow B} \coloneqq \text{prefix} \Vert BE(R_A)
\Vert \text{id}$
- $\text{I}_{B \rightarrow A} \coloneqq \text{prefix} \Vert BE(R_B)
\Vert \text{id}$

each corresponding to an index of position `Id`s ordered by reserves
(ascending).

I plan to immediately follow-up this PR with a proposal to refactor the
inner `PositionManager` index implementations.

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

> It adds a state key to nonverifiable storage, and absent the actual
eviction mechanism, this isn't actually consensus breaking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dex Area: Relates to the dex consensus-breaking breaking change to execution of on-chain data
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants