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

Add ValueRange type #53

Merged
merged 8 commits into from
Jun 19, 2023
Merged

Add ValueRange type #53

merged 8 commits into from
Jun 19, 2023

Conversation

ethanfrey
Copy link
Collaborator

@ethanfrey ethanfrey commented Jun 9, 2023

Requires #52 (merge that first)

This is inspired by the work in #49 about defining possible ranges of values as a lightweight partial lock for in-flight IBC transactions

Basic functionality is there and tested. It would be good to have some more realistic tests cases to ensure this API would be useful in real conditions

@ethanfrey ethanfrey marked this pull request as ready for review June 9, 2023 13:14
@ethanfrey ethanfrey mentioned this pull request Jun 9, 2023
9 tasks
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Looks good, but it's difficult for me to see how useful this is until hitting the real use case.

What we need is a couple of values that we can keep track against a couple of min (typically, zero) and max (typically, max cap?), values.

A given set of pending unordered TXs will be valid (that means, it can be accepted for processing without locking), if:

  • All of the reduce stack ones are above the min (when / if successfully processed), in the face of all of the increase stack ones failing.
  • Vice versa: All of the increase stack ones are below the max (when / if successfully processed) in the face of all the decrease stack ones failing.

Not difficult to reason about, actually. Good if the ValueRange type helps us in that regard.

@ethanfrey
Copy link
Collaborator Author

That is exactly the use case I was considering. And I think done with this API. I need to make better examples and likely adjust a bit.

A ValueRange keeps the min and max of all pending either succeeding or failing. We can also sum a number of them (think Sum over all liens to find total_slashable). And get the max of the max and min of the min.

It allows implementing a lock not on one element (eg user's OSMO balance), but on a portion of one element (500 OSMO of the user's balance). Want to try to write some such example as a test and give feedback on the API?

@maurolacy
Copy link
Collaborator

maurolacy commented Jun 12, 2023

I have a rough idea on how to implement this:

Based on a set of pending TXs. And (I think) we don't need locking, but just a check before accepting a new TX: It either passes (is compatible with the current set of pending TXs, in the sense of not exceeding the min and max caps). Or, it fails, and is rejected upfront.

Are you proposing using the Lockable type to try and define the amounts associated with the set of pending TXs? Or are you proposing to use locking if the compatibility check fails?

I can try implementing this on the external-staking contract, and we can discuss there over the PR if you want.

@ethanfrey
Copy link
Collaborator Author

I think we need to agree on the IBC docs and add IBC before we start using this in contracts.

My idea is rather than have to reason though every possible transaction that touches the same contracts as an IBC transaction, the IBC transaction just locks the critical sections it will update (either a WriteLock, or a ValueRange).

Then anything that could conflict would error. In lockable, this would be a read, a write, or another lock on the same value. With ValueRange, we reserve some more of that value, and it fails if any point in the range (any combination of pending tx succeeding or failing) would violate some limit (eg below 0 or above some max cap, eg collateral)

The main point is to modify the values such that all tx will execute this lock-check code. And not having to go through every path and making sure we add checks

Copy link
Collaborator

@JakeHartnell JakeHartnell left a comment

Choose a reason for hiding this comment

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

Looks good! Another useful package.

PR to fix clippy errors: #56

Base automatically changed from add-lock-sync-primitives to main June 15, 2023 10:34
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

LGTM. Some comments on usability / API design, as I still find it confusing.

packages/sync/src/range.rs Outdated Show resolved Hide resolved
packages/sync/src/range.rs Outdated Show resolved Hide resolved
packages/sync/src/range.rs Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Collaborator Author

Okay, I made suggested improvements.
Adding another PR with examples to shake it out in real-world usage

@ethanfrey ethanfrey merged commit 470f726 into main Jun 19, 2023
@ethanfrey ethanfrey deleted the value-range branch June 19, 2023 20:49
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.

3 participants