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 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ where
{
unhashed::get(&Self::storage_double_map_final_key(k1, k2)).ok_or(())
}

0xmovses marked this conversation as resolved.
Show resolved Hide resolved
fn set<KArg1: EncodeLike<K1>, KArg2: EncodeLike<K2>>(k1: KArg1, k2: KArg2, q: Self::Query) {
match G::from_query_to_optional_value(q) {
Some(v) => Self::insert(k1, k2, v),
Expand Down
46 changes: 46 additions & 0 deletions substrate/frame/vesting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,52 @@ 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());

assert!(l <= u8::MAX.into());
// Give target existing locks.
add_locks::<T>(&target, l as u8);

let transfer_amount = T::MinVestedTransfer::get();
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
let per_block = transfer_amount.checked_div(&20u32.into()).unwrap();

let number_of_schedules_after_removal = T::MAX_VESTING_SCHEDULES - 1;
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
let expected_balance = transfer_amount.checked_mul(&number_of_schedules_after_removal.into()).unwrap();

// It will remove last vesting schedule.
let schedule_index = T::MAX_VESTING_SCHEDULES - 1;
0xmovses marked this conversation as resolved.
Show resolved Hide resolved

let vesting_schedule = VestingInfo::new(
transfer_amount,
per_block,
1u32.into(),
);

for _ in 0..s {
assert_ok!(Vesting::<T>::do_vested_transfer(
source_lookup.clone(),
target_lookup.clone(),
vesting_schedule.into()
));
}
}: _(RawOrigin::Root, target_lookup, schedule_index)
verify {
assert_eq!(
Vesting::<T>::vesting_balance(&target),
Some(expected_balance),
"Vesting schedule was not removed",
);
}

not_unlocking_merge_schedules {
let l in 0 .. MaxLocksOf::<T>::get() - 1;
let s in 2 .. T::MAX_VESTING_SCHEDULES;
Expand Down
19 changes: 19 additions & 0 deletions substrate/frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ pub mod pallet {
Self::do_vested_transfer(source, target, schedule)
}

/// 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::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,
) -> DispatchResult {
ensure_root(origin)?;
let who = T::Lookup::lookup(target)?;
Self::remove_vesting_schedule(&who, schedule_index)
}
0xmovses marked this conversation as resolved.
Show resolved Hide resolved

/// Merge two vesting schedules together, creating a new vesting schedule that unlocks over
/// the highest possible start and end blocks. If both schedules have already started the
/// current block will be used as the schedule start; with the caveat that if one schedule
Expand Down
39 changes: 39 additions & 0 deletions substrate/frame/vesting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,42 @@ fn vested_transfer_less_than_existential_deposit_fails() {
);
});
}


#[test]
fn remove_vesting_schedule() {
ExtBuilder::default().existential_deposit(ED).build().execute_with(|| {
let user3_free_balance = Balances::free_balance(&3);
let user4_free_balance = Balances::free_balance(&4);
assert_eq!(user3_free_balance, 256 * 30);
assert_eq!(user4_free_balance, 256 * 40);
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
// 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>::NotVesting
0xmovses marked this conversation as resolved.
Show resolved Hide resolved
);
});
}
7 changes: 7 additions & 0 deletions substrate/frame/vesting/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading