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 force remove vesting #1982

Merged
merged 62 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
57a68b3
add diff from stale PR 11910
0xmovses Oct 22, 2023
805c048
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 23, 2023
fa8d739
add force_remove_vesting
0xmovses Oct 23, 2023
16cc611
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 23, 2023
59f63b8
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 24, 2023
8acf1b5
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Oct 26, 2023
21c6feb
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Oct 26, 2023
946593d
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 26, 2023
069e75e
integrate PR feedback
0xmovses Oct 27, 2023
0916c05
change call_index order
0xmovses Oct 27, 2023
24e2fee
update benchmark
0xmovses Oct 29, 2023
5574f97
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Oct 29, 2023
e31c6c0
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Oct 29, 2023
07fa040
".git/.scripts/commands/fmt/fmt.sh"
Oct 29, 2023
ce1cbfb
fix CI job
0xmovses Oct 29, 2023
dd32ff1
add weights
0xmovses Oct 29, 2023
3cf226b
change result type
0xmovses Oct 30, 2023
97ccb07
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 30, 2023
da70ea4
remove unused
0xmovses Oct 30, 2023
22a5d2a
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 31, 2023
2a4329a
DispatchResultWithPostInfo
0xmovses Oct 31, 2023
072ad0c
into on Option
0xmovses Oct 31, 2023
907a848
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 31, 2023
017996e
".git/.scripts/commands/fmt/fmt.sh"
Oct 31, 2023
46e01da
clippy
0xmovses Oct 31, 2023
89f29fa
add_vesting_schedules
0xmovses Oct 31, 2023
722ba6a
fix CI remove mut
0xmovses Oct 31, 2023
b79d3c8
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Oct 31, 2023
68deac0
remove use of add_vesting_schedules
0xmovses Oct 31, 2023
a58d11e
adjust test
0xmovses Nov 1, 2023
b5d88c9
assert on vesting
0xmovses Nov 1, 2023
ff28fdb
fix CI?
0xmovses Nov 1, 2023
bb05335
remove unused in benchmark test
0xmovses Nov 1, 2023
dbb346d
don't hit max limit vesting_schedules
0xmovses Nov 1, 2023
b1a80da
remove add_locks, fix linux benchmarks CI
0xmovses Nov 1, 2023
32c6978
back to previous
0xmovses Nov 1, 2023
fb30513
test CI
0xmovses Nov 1, 2023
32fd595
remove assert length
0xmovses Nov 1, 2023
cac1462
call add_vesting_schedules
0xmovses Nov 1, 2023
17f10d5
remove ensure
0xmovses Nov 1, 2023
9ded73e
rerun CI
0xmovses Nov 1, 2023
90b9569
bubble up error
0xmovses Nov 2, 2023
a56c43a
remove unused CI warning
0xmovses Nov 2, 2023
0fcc12d
".git/.scripts/commands/fmt/fmt.sh"
Nov 2, 2023
794d927
give source account enough funds to meet ED, re order locks logic
0xmovses Nov 2, 2023
2a5a9ed
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Nov 2, 2023
7f57804
Update substrate/frame/vesting/src/lib.rs
0xmovses Nov 2, 2023
255694b
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Nov 2, 2023
350f066
integrate pisaltu feedback
0xmovses Nov 2, 2023
e9be915
remove unused dev deps
0xmovses Nov 2, 2023
58d50b0
remove unused runtimes
0xmovses Nov 2, 2023
f7e770e
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Nov 2, 2023
841da6e
merge cargo.lock from master
0xmovses Nov 2, 2023
6e5af41
merge cargo.lock from master
0xmovses Nov 2, 2023
1a9d9f4
Update substrate/frame/vesting/src/lib.rs
0xmovses Nov 3, 2023
789e212
Update substrate/frame/vesting/src/tests.rs
0xmovses Nov 4, 2023
d96e8d4
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Nov 4, 2023
52366bf
Update substrate/frame/vesting/src/benchmarking.rs
0xmovses Nov 4, 2023
4b3cd21
remove redundant comment
0xmovses Nov 4, 2023
b408a10
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Nov 4, 2023
db2367b
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Nov 6, 2023
0a8899e
Merge branch 'master' into 0xmovses-force-remove-vesting
0xmovses Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions polkadot/runtime/rococo/src/weights/pallet_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,29 @@ impl<T: frame_system::Config> pallet_vesting::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: Vesting Vesting (r:1 w:1)
/// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// Storage: Balances Freezes (r:1 w:0)
/// Proof: Balances Freezes (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: `Vesting::Vesting` (r:1 w:1)
/// Proof: `Vesting::Vesting` (`max_values`: None, `max_size`: Some(1057), added: 3532, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:1 w:1)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:0)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(67), added: 2542, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// The range of component `l` is `[0, 49]`.
/// The range of component `s` is `[2, 28]`.
fn force_remove_vesting_schedule(l: u32, s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `555 + l * (25 ±0) + s * (36 ±0)`
// Estimated: `4764`
// Minimum execution time: 41_497_000 picoseconds.
Weight::from_parts(38_763_834, 4764)
// Standard Error: 2_030
.saturating_add(Weight::from_parts(99_580, 0).saturating_mul(l.into()))
// Standard Error: 3_750
.saturating_add(Weight::from_parts(132_188, 0).saturating_mul(s.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
fn not_unlocking_merge_schedules(l: u32, s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `378 + l * (25 ±0) + s * (36 ±0)`
Expand Down
24 changes: 24 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,28 @@ impl<T: frame_system::Config> pallet_vesting::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
}

/// Storage: `Vesting::Vesting` (r:1 w:1)
/// Proof: `Vesting::Vesting` (`max_values`: None, `max_size`: Some(1057), added: 3532, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:1 w:1)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:0)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(67), added: 2542, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// The range of component `l` is `[0, 49]`.
/// The range of component `s` is `[2, 28]`.
fn force_remove_vesting_schedule(l: u32, s: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `555 + l * (25 ±0) + s * (36 ±0)`
// Estimated: `4764`
// Minimum execution time: 41_497_000 picoseconds.
Weight::from_parts(38_763_834, 4764)
// Standard Error: 2_030
.saturating_add(Weight::from_parts(99_580, 0).saturating_mul(l.into()))
// Standard Error: 3_750
.saturating_add(Weight::from_parts(132_188, 0).saturating_mul(s.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
}
27 changes: 27 additions & 0 deletions substrate/frame/vesting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,33 @@ benchmarks! {
);
}

force_remove_vesting_schedule {
let l in 0 .. MaxLocksOf::<T>::get() - 1;
let s in 2 .. T::MAX_VESTING_SCHEDULES;

let source: T::AccountId = account("source", 0, SEED);
let source_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(source.clone());
T::Currency::make_free_balance_be(&source, BalanceOf::<T>::max_value());

let target: T::AccountId = account("target", 0, SEED);
let target_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(target.clone());
T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance());

// Give target existing locks.
add_locks::<T>(&target, l as u8);
let _ = add_vesting_schedules::<T>(target_lookup.clone(), s)?;

// The last vesting schedule.
let schedule_index = s - 1;
}: _(RawOrigin::Root, target_lookup, schedule_index)
verify {
assert_eq!(
Vesting::<T>::vesting(&target).unwrap().len(),
schedule_index as usize,
"Schedule count should reduce by 1"
);
}

impl_benchmark_test_suite!(
Vesting,
crate::mock::ExtBuilder::default().existential_deposit(256).build(),
Expand Down
30 changes: 30 additions & 0 deletions substrate/frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,36 @@ pub mod pallet {

Ok(())
}

/// Force remove a vesting schedule
///
/// The dispatch origin for this call must be _Root_.
///
/// - `target`: An account that has a vesting schedule
/// - `schedule_index`: The vesting schedule index that should be removed
#[pallet::call_index(5)]
#[pallet::weight(
T::WeightInfo::force_remove_vesting_schedule(MaxLocksOf::<T>::get(), T::MAX_VESTING_SCHEDULES)
)]
pub fn force_remove_vesting_schedule(
origin: OriginFor<T>,
target: <T::Lookup as StaticLookup>::Source,
schedule_index: u32,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let who = T::Lookup::lookup(target)?;

let schedules_count = Vesting::<T>::decode_len(&who).unwrap_or_default();
ensure!(schedule_index < schedules_count as u32, Error::<T>::InvalidScheduleParams);

Self::remove_vesting_schedule(&who, schedule_index)?;

Ok(Some(T::WeightInfo::force_remove_vesting_schedule(
MaxLocksOf::<T>::get(),
schedules_count as u32,
))
.into())
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions substrate/frame/vesting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,39 @@ fn vested_transfer_less_than_existential_deposit_fails() {
);
});
}

#[test]
fn remove_vesting_schedule() {
ExtBuilder::default().existential_deposit(ED).build().execute_with(|| {
assert_eq!(Balances::free_balance(&3), 256 * 30);
assert_eq!(Balances::free_balance(&4), 256 * 40);
// Account 4 should not have any vesting yet.
assert_eq!(Vesting::vesting(&4), None);
// Make the schedule for the new transfer.
let new_vesting_schedule = VestingInfo::new(
ED * 5,
(ED * 5) / 20, // Vesting over 20 blocks
10,
);
assert_ok!(Vesting::vested_transfer(Some(3).into(), 4, new_vesting_schedule));
// Now account 4 should have vesting.
assert_eq!(Vesting::vesting(&4).unwrap(), vec![new_vesting_schedule]);
// Account 4 has 5 * 256 locked.
assert_eq!(Vesting::vesting_balance(&4), Some(256 * 5));
// Verify only root can call.
assert_noop!(Vesting::force_remove_vesting_schedule(Some(4).into(), 4, 0), BadOrigin);
// Verify that root can remove the schedule.
assert_ok!(Vesting::force_remove_vesting_schedule(RawOrigin::Root.into(), 4, 0));
// Verify that last event is VestingCompleted.
System::assert_last_event(Event::VestingCompleted { account: 4 }.into());
// Appropriate storage is cleaned up.
assert!(!<VestingStorage<Test>>::contains_key(4));
// Check the vesting balance is zero.
assert_eq!(Vesting::vesting(&4), None);
// Verifies that trying to remove a schedule when it doesnt exist throws error.
assert_noop!(
Vesting::force_remove_vesting_schedule(RawOrigin::Root.into(), 4, 0),
Error::<Test>::InvalidScheduleParams
);
});
}
Loading
Loading