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

KTON staking #1408

Merged
merged 11 commits into from
Apr 15, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock

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

13 changes: 2 additions & 11 deletions pallet/account-migration/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ mod benchmarks {
);
<Ledgers<T>>::insert(
from,
Ledger {
OldLedger {
staked_ring: 1,
staked_kton: 1,
staked_deposits: BoundedVec::truncate_from(vec![
Default::default();
<T as darwinia_deposit::Config>::MaxDeposits::get()
Expand All @@ -130,15 +129,7 @@ mod benchmarks {
<T as darwinia_staking::Config>::MaxUnstakings::get()
as usize
]),
unstaking_kton: BoundedVec::truncate_from(vec![
hackfisher marked this conversation as resolved.
Show resolved Hide resolved
(
Default::default(),
Default::default()
);
<T as darwinia_staking::Config>::MaxUnstakings::get()
as usize
]),
unstaking_deposits: Default::default(),
..Default::default()
},
);
}
Expand Down
33 changes: 13 additions & 20 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub use weights::WeightInfo;

// darwinia
use darwinia_deposit::Deposit;
use darwinia_staking::Ledger;
use darwinia_staking::{migration::v2::OldLedger, Ledger};
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, Nonce};
// substrate
use frame_support::{
Expand All @@ -66,7 +66,7 @@ use frame_support::{
traits::{Currency, ExistenceRequirement::AllowDeath},
StorageHasher,
};
use frame_system::{pallet_prelude::*, AccountInfo, RawOrigin};
use frame_system::{pallet_prelude::*, AccountInfo};
use pallet_balances::AccountData;
use pallet_identity::{Judgement, Registration};
use sp_core::{
Expand Down Expand Up @@ -175,10 +175,10 @@ pub mod pallet {
Registration<Balance, ConstU32<100>, ConstU32<100>>,
>;

/// [`darwinia_staking::Ledgers`] data.
/// [`darwinia_staking::migration::v2::OldLedger`] data.
#[pallet::storage]
#[pallet::getter(fn ledger_of)]
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, Ledger<T>>;
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, OldLedger<T>>;

/// Multisig migration caches.
#[pallet::storage]
Expand Down Expand Up @@ -480,7 +480,6 @@ pub mod pallet {
let now = <frame_system::Pallet<T>>::block_number();

l.unstaking_ring.retain(|(_, t)| t > &now);
l.unstaking_kton.retain(|(_, t)| t > &now);
hackfisher marked this conversation as resolved.
Show resolved Hide resolved

let staking_pot = darwinia_staking::account_id();
let r = l.staked_ring + l.unstaking_ring.iter().map(|(r, _)| r).sum::<Balance>();
Expand All @@ -497,21 +496,15 @@ pub mod pallet {
)?;
}

let k = l.staked_kton + l.unstaking_kton.iter().map(|(k, _)| k).sum::<Balance>();

// To calculated the worst case in benchmark.
debug_assert!(k > 0);

if k != 0 {
<pallet_assets::Pallet<T>>::transfer(
RawOrigin::Signed(*to).into(),
KTON_ID.into(),
staking_pot,
k,
)?;
}

<darwinia_staking::Ledgers<T>>::insert(to, l);
<darwinia_staking::Ledgers<T>>::insert(
to,
Ledger {
staked_ring: l.staked_ring,
staked_deposits: l.staked_deposits,
unstaking_ring: l.unstaking_ring,
unstaking_deposits: l.unstaking_deposits,
},
);
}

Ok(())
Expand Down
1 change: 0 additions & 1 deletion pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ impl darwinia_staking::Config for Runtime {
type KtonStakerNotifier = ();
type MaxDeposits = ();
type MaxUnstakings = ();
type MigrationCurve = ();
type MinStakingDuration = ();
type Ring = Dummy;
type RuntimeEvent = RuntimeEvent;
Expand Down
2 changes: 0 additions & 2 deletions pallet/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ darwinia-deposit = { workspace = true, features = ["std"] }

# substrate
dc-inflation = { workspace = true, features = ["std"] }
pallet-assets = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
pallet-session = { workspace = true, features = ["std"] }
pallet-timestamp = { workspace = true, features = ["std"] }
Expand Down Expand Up @@ -88,7 +87,6 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]

Expand Down
34 changes: 9 additions & 25 deletions pallet/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod benchmarks {
//
// The total number of deposit items has reached `Config::MaxUnstakings`.
#[extrinsic_call]
_(RawOrigin::Signed(a), UNIT, UNIT, deposits);
_(RawOrigin::Signed(a), UNIT, deposits);
}

#[benchmark]
Expand All @@ -77,14 +77,13 @@ mod benchmarks {

let deposits = deposit_for::<T>(&a, x);

<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, UNIT, deposits.clone())
.unwrap();
<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap();

// Worst-case scenario:
//
// The total number of deposit items has reached `Config::MaxUnstakings`.
#[extrinsic_call]
_(RawOrigin::Signed(a), UNIT, UNIT, deposits);
_(RawOrigin::Signed(a), UNIT, deposits);
}

#[benchmark]
Expand All @@ -97,10 +96,8 @@ mod benchmarks {

let deposits = deposit_for::<T>(&a, x);

<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, UNIT, deposits.clone())
.unwrap();
<Pallet<T>>::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, UNIT, deposits.clone())
.unwrap();
<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap();
<Pallet<T>>::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap();

// Worst-case scenario:
//
Expand All @@ -119,9 +116,8 @@ mod benchmarks {

let deposits = deposit_for::<T>(&a, <T as Config>::MaxUnstakings::get());

<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, UNIT, deposits.clone())
.unwrap();
<Pallet<T>>::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, UNIT, deposits).unwrap();
<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits.clone()).unwrap();
<Pallet<T>>::unstake(RawOrigin::Signed(a.clone()).into(), UNIT, deposits).unwrap();

<frame_system::Pallet<T>>::set_block_number(
<frame_system::Pallet<T>>::block_number() + T::MinStakingDuration::get(),
Expand Down Expand Up @@ -158,13 +154,7 @@ mod benchmarks {
// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, UNIT + 1);

<Pallet<T>>::stake(
RawOrigin::Signed(a.clone()).into(),
UNIT,
Default::default(),
Default::default(),
)
.unwrap();
<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, Default::default()).unwrap();
<Pallet<T>>::collect(RawOrigin::Signed(a.clone()).into(), Default::default()).unwrap();

// Worst-case scenario:
Expand All @@ -181,13 +171,7 @@ mod benchmarks {
// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, UNIT + 1);

<Pallet<T>>::stake(
RawOrigin::Signed(a.clone()).into(),
UNIT,
Default::default(),
Default::default(),
)
.unwrap();
<Pallet<T>>::stake(RawOrigin::Signed(a.clone()).into(), UNIT, Default::default()).unwrap();
<Pallet<T>>::collect(RawOrigin::Signed(a.clone()).into(), Default::default()).unwrap();
<Pallet<T>>::nominate(RawOrigin::Signed(a.clone()).into(), a.clone()).unwrap();

Expand Down
Loading