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

Update reward pool on provider_boost or unstake #1699 #1948

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c0c5d78
updates to design docs to use a capacity rewards interface
shannonwells May 23, 2023
3ab6b51
make check and make test working
shannonwells Jun 1, 2023
deb3642
change staking target extrinsic, closes #1570 (#1623)
shannonwells Jul 7, 2023
31a1049
* Refactor staking type to go in StakingTargetDetails
shannonwells Oct 3, 2023
c5812c1
Feat/reward pool history (#1710)
shannonwells Oct 16, 2023
5653c78
Feat/split stake extrinsic #1699 (#1717)
shannonwells Oct 17, 2023
75849e9
Feat/split storage #1726 (#1744)
shannonwells Oct 30, 2023
149f653
fix e2e tests, correction to implementation design doc
shannonwells Oct 30, 2023
124fe64
* Fix benchmarks
shannonwells Oct 18, 2023
4b0246e
stubbed tests for when staking types are split up
shannonwells Oct 20, 2023
e952d94
updating reward pool total_staked on stake and calculating rest on er…
shannonwells Oct 31, 2023
8a8cdc6
unstake unlocks common storage, some tests, small refactor in test ut…
shannonwells Nov 1, 2023
fcc32b1
unstake unlocks common storage, some tests, small refactor in test ut…
shannonwells Nov 1, 2023
060a995
some updates after rebase
shannonwells Apr 22, 2024
2a89064
some more updates after rebasing w/ origin branch
shannonwells Apr 22, 2024
b310d91
moved commented-out code from another branch to be implemented
shannonwells Apr 22, 2024
ec74a0a
WIP putting reward pool updates back to good state
shannonwells Apr 23, 2024
62baa65
* Fix warnings
shannonwells Apr 25, 2024
a6db4de
undo design doc changes
shannonwells Apr 25, 2024
0b5d184
update benchmarks and related weights
shannonwells Apr 25, 2024
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
4 changes: 2 additions & 2 deletions designdocs/provider_boosting_implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ It does not give regard to what the economic model actually is, since that is ye

## Staking Token Rewards

### StakingAccountDetails --> StakingDetails
### StakingDetails --> StakingDetails
New fields are added. The field **`last_rewarded_at`** is to keep track of the last time rewards were claimed for this Staking Account.
MaximumCapacity staking accounts MUST always have the value `None` for `last_rewarded_at`.

This is a second version of this storage, to replace StakingAccountDetails, and StakingAccountDetails data will need to be migrated.
This is a second version of this storage, to replace StakingDetails, and StakingDetails data will need to be migrated.
```rust
pub struct StakingDetails<T: Config> {
pub active: BalanceOf<T>,
Expand Down
118 changes: 86 additions & 32 deletions pallets/capacity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,47 @@ pub fn set_up_epoch<T: Config>(current_block: BlockNumberFor<T>, current_epoch:
CurrentEpochInfo::<T>::set(EpochInfo { epoch_start });
}

// caller stakes the given amount to the given target
pub fn setup_provider_stake<T: Config>(
caller: &T::AccountId,
target: &MessageSourceId,
staking_amount: BalanceOf<T>,
) {
let capacity_amount: BalanceOf<T> = Capacity::<T>::capacity_generated(staking_amount);

let mut staking_account = StakingDetails::<T>::default();
let mut target_details = StakingTargetDetails::<BalanceOf<T>>::default();
let mut capacity_details =
CapacityDetails::<BalanceOf<T>, <T as Config>::EpochNumber>::default();

staking_account.deposit(staking_amount);
target_details.deposit(staking_amount, capacity_amount);
capacity_details.deposit(&staking_amount, &capacity_amount);

Capacity::<T>::set_staking_account_and_lock(caller, &staking_account)
.expect("Failed to set staking account");
Capacity::<T>::set_target_details_for(caller, *target, target_details);
Capacity::<T>::set_capacity_for(*target, capacity_details);
}

// fill up unlock chunks to max bound - 1
fn fill_unlock_chunks<T: Config>(caller: &T::AccountId, count: u32) {
let mut unlocking: UnlockChunkList<T> = BoundedVec::default();
for _i in 0..count {
let unlock_chunk: UnlockChunk<BalanceOf<T>, T::EpochNumber> =
UnlockChunk { value: 1u32.into(), thaw_at: 3u32.into() };
assert_ok!(unlocking.try_push(unlock_chunk));
}
UnstakeUnlocks::<T>::set(caller, Some(unlocking));
}

benchmarks! {
stake {
let caller: T::AccountId = create_funded_account::<T>("account", SEED, 105u32);
let amount: BalanceOf<T> = T::MinimumStakingAmount::get();
let capacity: BalanceOf<T> = Capacity::<T>::capacity_generated(amount);
let target = 1;
let staking_type = StakingType::MaximumCapacity;
let staking_type = MaximumCapacity;

register_provider::<T>(target, "Foo");

Expand All @@ -57,12 +91,7 @@ benchmarks! {

withdraw_unstaked {
let caller: T::AccountId = create_funded_account::<T>("account", SEED, 5u32);
let mut unlocking: UnlockChunkList<T> = BoundedVec::default();
for _i in 0..T::MaxUnlockingChunks::get() {
let unlock_chunk: UnlockChunk<BalanceOf<T>, T::EpochNumber> = UnlockChunk { value: 1u32.into(), thaw_at: 3u32.into() };
assert_ok!(unlocking.try_push(unlock_chunk));
}
UnstakeUnlocks::<T>::set(&caller, Some(unlocking));
fill_unlock_chunks::<T>(&caller, T::MaxUnlockingChunks::get());

CurrentEpoch::<T>::set(T::EpochNumber::from(5u32));

Expand Down Expand Up @@ -90,31 +119,16 @@ benchmarks! {
let target = 1;
let block_number = 4u32;

let mut staking_account = StakingDetails::<T>::default();
let mut target_details = StakingTargetDetails::<BalanceOf<T>>::default();
let mut capacity_details = CapacityDetails::<BalanceOf<T>, <T as Config>::EpochNumber>::default();

staking_account.deposit(staking_amount);
target_details.deposit(staking_amount, capacity_amount);
capacity_details.deposit(&staking_amount, &capacity_amount);

Capacity::<T>::set_staking_account_and_lock(&caller.clone(), &staking_account).expect("Failed to set staking account");
Capacity::<T>::set_target_details_for(&caller.clone(), target, target_details);
Capacity::<T>::set_capacity_for(target, capacity_details);

// fill up unlock chunks to max bound - 1
let count = T::MaxUnlockingChunks::get()-1;
let mut unlocking: UnlockChunkList<T> = BoundedVec::default();
for _i in 0..count {
let unlock_chunk: UnlockChunk<BalanceOf<T>, T::EpochNumber> = UnlockChunk { value: 1u32.into(), thaw_at: 3u32.into() };
assert_ok!(unlocking.try_push(unlock_chunk));
}
UnstakeUnlocks::<T>::set(&caller, Some(unlocking));


setup_provider_stake::<T>(&caller, &target, staking_amount);
fill_unlock_chunks::<T>(&caller, T::MaxUnlockingChunks::get() - 1);
}: _ (RawOrigin::Signed(caller.clone()), target, unstaking_amount.into())
verify {
assert_last_event::<T>(Event::<T>::UnStaked {account: caller, target: target, amount: unstaking_amount.into(), capacity: Capacity::<T>::calculate_capacity_reduction(unstaking_amount.into(), staking_amount, capacity_amount) }.into());
assert_last_event::<T>(Event::<T>::UnStaked {
account: caller.clone(),
target,
amount: unstaking_amount.into(),
capacity: Capacity::<T>::calculate_capacity_reduction(unstaking_amount.into(), staking_amount,capacity_amount)
}.into());
}

set_epoch_length {
Expand All @@ -125,7 +139,47 @@ benchmarks! {
assert_last_event::<T>(Event::<T>::EpochLengthUpdated {blocks: epoch_length}.into());
}

change_staking_target {
shannonwells marked this conversation as resolved.
Show resolved Hide resolved
let caller: T::AccountId = create_funded_account::<T>("account", SEED, 5u32);
let from_msa = 33;
let to_msa = 34;
// amount in addition to minimum
let from_msa_amount = 32u32;
let to_msa_amount = 1u32;

register_provider::<T>(from_msa, "frommsa");
register_provider::<T>(to_msa, "tomsa");
setup_provider_stake::<T>(&caller, &from_msa, from_msa_amount.into());
setup_provider_stake::<T>(&caller, &to_msa, to_msa_amount.into());
let restake_amount = 11u32;

}: _ (RawOrigin::Signed(caller.clone(), ), from_msa, to_msa, restake_amount.into())
verify {
assert_last_event::<T>(Event::<T>::StakingTargetChanged {
account: caller,
from_msa,
to_msa,
amount: restake_amount.into()
}.into());
}

provider_boost {
shannonwells marked this conversation as resolved.
Show resolved Hide resolved
let caller: T::AccountId = create_funded_account::<T>("boostaccount", SEED, 260u32);
let boost_amount: BalanceOf<T> = 200u32.into(); // enough for 1 Cap boosted
let capacity: BalanceOf<T> = Capacity::<T>::capacity_generated(<T>::RewardsProvider::capacity_boost(boost_amount));
let target = 1;

register_provider::<T>(target, "Foo");

}: _ (RawOrigin::Signed(caller.clone()), target, boost_amount)
verify {
assert!(StakingAccountLedger::<T>::contains_key(&caller));
assert!(StakingTargetLedger::<T>::contains_key(&caller, target));
assert!(CapacityLedger::<T>::contains_key(target));
assert_last_event::<T>(Event::<T>::ProviderBoosted {account: caller, amount: boost_amount, target, capacity}.into());
}

impl_benchmark_test_suite!(Capacity,
crate::tests::mock::new_test_ext(),
crate::tests::mock::Test);
tests::mock::new_test_ext(),
tests::mock::Test);
}
Loading