Skip to content

Add tests for the vesting update procedure #17297

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

Open
wants to merge 1 commit into
base: compatible
Choose a base branch
from

Conversation

cjjdespres
Copy link
Member

Explain your changes:

Tests have been added to ensure that the vesting parameter update equations in the slot reduction MIP preserve the guarantees included in the MIP, namely that the minimum balance at the hardfork slot itself is unchanged, and funds unlock at the same system times as they would have had the hardfork not occurred.

Explain how you tested your changes:

I ran the tests manually and confirmed that they all passed.

Checklist:

  • Dependency versions are unchanged
  • Modified the current draft of release notes with details on what is completed or incomplete within this project
    (not applicable, I think)
  • Document code purpose, how to use it
  • Tests were added for the new behavior
  • All tests pass (CI will check this if you didn't)
  • Serialized types are in stable-versioned modules
  • Does this close issues? Not applicable.

@cjjdespres cjjdespres requested a review from a team as a code owner May 27, 2025 20:35
@cjjdespres
Copy link
Member Author

There are still more test variants I could add (explicitly simulating the vesting times of accounts, for instance) but it's otherwise complete. I wanted to have this up for review and perhaps merging before I kept going.

Copy link
Member

@glyh glyh left a comment

Choose a reason for hiding this comment

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

Left some questions :)

@@ -67,7 +67,7 @@ module As_record = struct
; vesting_period : 'slot_span
; vesting_increment : 'amount
}
[@@deriving equal, hlist, fields, annot]
[@@deriving equal, hlist, fields, annot, sexp_of]
Copy link
Member

Choose a reason for hiding this comment

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

Could we use yojson instead of sexp?

EDIT: looks like this is enforced by Janestreet's quickcheck. I've ran into this in other parts of our code, so unfortunately, no.

that won't take ages to finish *)
let gen_small_timing =
(* At 90s slot time, this slot will occur 375 years after slot 0 *)
let vesting_end_max = UInt32.(div max_int (of_int 32)) in
Copy link
Member

Choose a reason for hiding this comment

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

Why 32, is this just a random constant to shift upper boundary to a period human care while making it proportional to UInt32.max_int?

Copy link
Member Author

Choose a reason for hiding this comment

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

I should document that. Yes, I just chose some small-ish value that would result in a vesting schedule that's comfortably within the guarantees provided by the MIP.

let final_vesting_slot (t : Account_timing.as_record) =
(* timing_final_vesting_slot assumes vesting_increment is non-zero, but we
want to be able to handle such accounts here. *)
if Amount.(equal t.vesting_increment zero) then t.cliff_time
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this logic inside Account.timing_final_vesting_slot so it deals with corner case as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably. I can move it in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Not crucial, though. we could do it in subsequent PRs if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, might be better not to complicate this one

hardfork_slot
+ of_int 2
* ( t.vesting_period
- ((hardfork_slot - t.cliff_time) mod t.vesting_period) ))
Copy link
Member

@glyh glyh Jun 2, 2025

Choose a reason for hiding this comment

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

Okay, this is calculating the time difference of the closest vesting slot to the HF slot. Double the span and add back the HF slot to get the new slot of closest vesting. Make sense.

then Some (timing, hardfork_slot, vesting_end)
else None )
in
let total_vesting_slots =
Copy link
Member

Choose a reason for hiding this comment

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

This is a span, not number of slots it seems? if it's number of slot we need to add 1.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the number of slots, but the account isn't considered actively vesting at vesting_end, so this should be the length of the interval [hardfork_slot, vesting_end).

The new tests ensure that the vesting parameter update equations in the
slot reduction MIP preserve the guarantees included in the MIP, namely
that the minimum balance at the hardfork slot itself is unchanged, and
funds unlock at the same system times as they would have had the
hardfork not occurred.
@cjjdespres cjjdespres force-pushed the cjjdespres/vesting-schedule-test branch from 8be8a9c to 23549d7 Compare June 4, 2025 12:07
@cjjdespres
Copy link
Member Author

!ci-build-me

@cjjdespres
Copy link
Member Author

I think that should be everything, other than a few items for follow-up PRs.

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.

2 participants