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

Adding try_state hook for Vesting pallet #2847

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
prdoc added
  • Loading branch information
Doordashcon committed Jan 9, 2024
commit a716860996e158075a5aefa3736e2a5d3341e3d3
9 changes: 9 additions & 0 deletions prdoc/pr_2847.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Adding `try-state` hook to vesting pallet

doc:
- audience: Runtime User
description: |
At the blocks before vesting begins, the locked amount of a vesting schedule must be product of the duration and the release per block amount when the locked amount is divisible by the per block amount, else the final vesting block should be equal to the unvested amount. This should also hold true during vesting shechules.

crates:
- name: pallet-vesting
12 changes: 7 additions & 5 deletions substrate/frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ impl<T: Config> Pallet<T> {
/// * the locked amount of a vesting schedule must be equal to the
/// product of the duration(`schedules_left` - `starting_block`) and the per block amount when
/// the locked amount is divisible by the per block amount.
/// * However, If the locked amount is not divisible by the per block amount, the final vesting block
/// * However, If the locked amount is not divisible by the per block amount, the final vesting
/// block
/// (`schedules_left` - 1), the unvested amount should be equal to the remainder.
///
/// `handle_during_schedule`:
Expand All @@ -717,8 +718,9 @@ impl<T: Config> Pallet<T> {
let schedules_left: BalanceOf<T> =
info.ending_block_as_balance::<T::BlockNumberToBalance>();
let starting_block = T::BlockNumberToBalance::convert(info.starting_block());
let current_block_to_balance =
T::BlockNumberToBalance::convert(<frame_system::Pallet<T>>::block_number());
let current_block_to_balance = T::BlockNumberToBalance::convert(
T::BlockNumberProvider::current_block_number(),
);

if current_block_to_balance < starting_block {
Self::handle_before_schedule_starts(info, starting_block, schedules_left)?;
Expand All @@ -739,7 +741,7 @@ impl<T: Config> Pallet<T> {

if (info.locked() % info.per_block()).is_zero() {
ensure!(
info.locked_at::<T::BlockNumberToBalance>(frame_system::Pallet::<T>::block_number()) == (count * info.per_block()),
info.locked_at::<T::BlockNumberToBalance>(T::BlockNumberProvider::current_block_number()) == (count * info.per_block()),
TryRuntimeError::Other("Before schedule starts, the vesting balance should be equal to the total per block releases")
);
} else {
Expand Down Expand Up @@ -772,7 +774,7 @@ impl<T: Config> Pallet<T> {
current_block_to_balance: BalanceOf<T>,
schedules_left: BalanceOf<T>,
) -> Result<(), TryRuntimeError> {
let current_block = frame_system::Pallet::<T>::block_number();
let current_block = T::BlockNumberProvider::current_block_number();

let still_vesting = info.locked_at::<T::BlockNumberToBalance>(current_block);

Expand Down