Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
340 changes: 0 additions & 340 deletions pallets/parachain-staking/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,325 +795,6 @@ benchmarks! {
assert!(Pallet::<T>::is_delegator(&caller));
}

schedule_leave_delegators_worst {
// We assume that all candidates have full delegations with scheduled requests
let x in 1..T::MaxDelegationsPerDelegator::get();

let mut seed = Seed::new();

let delegator = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(
T::MinDelegation::get() * T::MaxDelegationsPerDelegator::get().into() * 3000u32.into()
),
AccountAction::None,
)?;

for c in 0..x {
let collator = create_account::<T>(
"collator",
seed.take(),
AccountBalance::MinCandidateStake,
AccountAction::JoinCandidates{ amount: Amount::All, candidate_count: c + 1 },
)?;

let mut decreasing_balance = <DecreasingBalance<T>>::new(
T::MinDelegation::get() * 2000u32.into(),
1u32.into(),
);
let mut col_del_count = 0u32;
for i in 0..T::MaxTopDelegationsPerCandidate::get() - 1 {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_delegator_bond_less(
RawOrigin::Signed(del).into(),
collator.clone(),
5u32.into(),
)?;
}

let last_top_delegator_bond = decreasing_balance.take();
<Pallet<T>>::delegate_with_auto_compound(
RawOrigin::Signed(delegator.clone()).into(),
collator.clone(),
last_top_delegator_bond,
Percent::from_percent(100),
col_del_count,
col_del_count,
c,
)?;
col_del_count += 1;

assert_eq!(
<BottomDelegations<T>>::get(&collator).map(|d| d.delegations.len()).unwrap_or_default(),
0,
);

for i in 0..T::MaxBottomDelegationsPerCandidate::get() {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_revoke_delegation(
RawOrigin::Signed(del).into(),
collator.clone(),
)?;
}

assert_eq!(
<BottomDelegations<T>>::get(&collator)
.map(|bd| bd.delegations.len() as u32)
.unwrap_or_default(),
T::MaxBottomDelegationsPerCandidate::get(),
);
}
}: {
<Pallet<T>>::schedule_leave_delegators(RawOrigin::Signed(delegator.clone()).into())?;
} verify {
assert!(Pallet::<T>::delegator_state(&delegator).expect("must exist").is_active());
}

cancel_leave_delegators_worst {
// We assume that all candidates have full delegations with scheduled requests
let x in 1..T::MaxDelegationsPerDelegator::get();

let mut seed = Seed::new();

let delegator = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(
T::MinDelegation::get() * T::MaxDelegationsPerDelegator::get().into() * 3000u32.into()
),
AccountAction::None,
)?;

for c in 0..x {
let collator = create_account::<T>(
"collator",
seed.take(),
AccountBalance::MinCandidateStake,
AccountAction::JoinCandidates{ amount: Amount::All, candidate_count: c + 1 },
)?;

let mut decreasing_balance = <DecreasingBalance<T>>::new(
T::MinDelegation::get() * 2000u32.into(),
1u32.into(),
);
let mut col_del_count = 0u32;
for i in 0..T::MaxTopDelegationsPerCandidate::get() - 1 {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_delegator_bond_less(
RawOrigin::Signed(del).into(),
collator.clone(),
5u32.into(),
)?;
}

let last_top_delegator_bond = decreasing_balance.take();
<Pallet<T>>::delegate_with_auto_compound(
RawOrigin::Signed(delegator.clone()).into(),
collator.clone(),
last_top_delegator_bond,
Percent::from_percent(100),
col_del_count,
col_del_count,
c,
)?;
col_del_count += 1;

assert_eq!(
<BottomDelegations<T>>::get(&collator).map(|d| d.delegations.len()).unwrap_or_default(),
0,
);

for i in 0..T::MaxBottomDelegationsPerCandidate::get() {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_revoke_delegation(
RawOrigin::Signed(del).into(),
collator.clone(),
)?;
}

assert_eq!(
<BottomDelegations<T>>::get(&collator)
.map(|bd| bd.delegations.len() as u32)
.unwrap_or_default(),
T::MaxBottomDelegationsPerCandidate::get(),
);
}

Pallet::<T>::schedule_leave_delegators(RawOrigin::Signed(delegator.clone()).into())?;
}: {
<Pallet<T>>::cancel_leave_delegators(RawOrigin::Signed(delegator.clone()).into())?;
} verify {
assert!(Pallet::<T>::delegator_state(&delegator).expect("must exist").is_active());
}

execute_leave_delegators_worst {
// We assume that all candidates have full delegations with scheduled requests
let x in 1..T::MaxDelegationsPerDelegator::get();

let mut seed = Seed::new();

let delegator = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(
T::MinDelegation::get() * T::MaxDelegationsPerDelegator::get().into() * 3000u32.into()
),
AccountAction::None,
)?;

let author = create_account::<T>(
"collator",
seed.take(),
AccountBalance::MinCandidateStake,
AccountAction::JoinCandidates{ amount: Amount::All, candidate_count: 1u32 },
)?;

for c in 0..x {
let collator = create_account::<T>(
"collator",
seed.take(),
AccountBalance::MinCandidateStake,
AccountAction::JoinCandidates{ amount: Amount::All, candidate_count: c + 2 },
)?;

let mut decreasing_balance = <DecreasingBalance<T>>::new(
T::MinDelegation::get() * 2000u32.into(),
1u32.into(),
);
let mut col_del_count = 0u32;
for i in 0..T::MaxTopDelegationsPerCandidate::get() - 1 {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_delegator_bond_less(
RawOrigin::Signed(del).into(),
collator.clone(),
5u32.into(),
)?;
}

let last_top_delegator_bond = decreasing_balance.take();
<Pallet<T>>::delegate_with_auto_compound(
RawOrigin::Signed(delegator.clone()).into(),
collator.clone(),
last_top_delegator_bond,
Percent::from_percent(100),
col_del_count,
col_del_count,
c,
)?;
col_del_count += 1;

assert_eq!(
<BottomDelegations<T>>::get(&collator).map(|d| d.delegations.len()).unwrap_or_default(),
0,
);

for i in 0..T::MaxBottomDelegationsPerCandidate::get() {
let del = create_account::<T>(
"delegator",
seed.take(),
AccountBalance::Value(decreasing_balance.take()),
AccountAction::Delegate{
collator: collator.clone(),
amount: Amount::All,
auto_compound: Percent::from_percent(100),
collator_delegation_count: col_del_count,
collator_auto_compound_delegation_count: col_del_count,
},
)?;
col_del_count += 1;

Pallet::<T>::schedule_revoke_delegation(
RawOrigin::Signed(del).into(),
collator.clone(),
)?;
}

assert_eq!(
<BottomDelegations<T>>::get(&collator)
.map(|bd| bd.delegations.len() as u32)
.unwrap_or_default(),
T::MaxBottomDelegationsPerCandidate::get(),
);
}

Pallet::<T>::schedule_leave_delegators(RawOrigin::Signed(delegator.clone()).into())?;
roll_to_and_author::<T>(2, author.clone());
}: {
<Pallet<T>>::execute_leave_delegators(
RawOrigin::Signed(delegator.clone()).into(),
delegator.clone(),
x,
)?;
} verify {
assert!(Pallet::<T>::delegator_state(&delegator).is_none());
}

schedule_revoke_delegation {
// x controls the number of other scheduled requests
let x in 0..(
Expand Down Expand Up @@ -2543,27 +2224,6 @@ mod tests {
});
}

#[test]
fn bench_schedule_leave_delegators() {
new_test_ext().execute_with(|| {
assert_ok!(Pallet::<Test>::test_benchmark_schedule_leave_delegators_worst());
});
}

#[test]
fn bench_execute_leave_delegators() {
new_test_ext().execute_with(|| {
assert_ok!(Pallet::<Test>::test_benchmark_execute_leave_delegators_worst());
});
}

#[test]
fn bench_cancel_leave_delegators() {
new_test_ext().execute_with(|| {
assert_ok!(Pallet::<Test>::test_benchmark_cancel_leave_delegators_worst());
});
}

#[test]
fn bench_schedule_revoke_delegation() {
new_test_ext().execute_with(|| {
Expand Down
Loading