Skip to content

Commit

Permalink
Remove part of vesting
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <xavier@inv.cafe>
  • Loading branch information
aurexav committed Jul 21, 2023
1 parent a960b77 commit 37db0a2
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 103 deletions.
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.

4 changes: 0 additions & 4 deletions pallet/account-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ frame-system = { workspace = true }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-identity = { workspace = true }
pallet-vesting = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
Expand Down Expand Up @@ -54,7 +53,6 @@ std = [
"pallet-assets/std",
"pallet-balances/std",
"pallet-identity/std",
"pallet-vesting/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand All @@ -75,5 +73,3 @@ try-runtime = [
# substrate
"frame-support/try-runtime",
]

no-vesting = []
8 changes: 0 additions & 8 deletions pallet/account-migration/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ mod benchmarks {
extra: Default::default(),
},
);
#[cfg(not(feature = "no-vesting"))]
<Vestings<T>>::insert(
from,
vec![
VestingInfo::new(1, Default::default(), Default::default());
<T as pallet_vesting::Config>::MAX_VESTING_SCHEDULES as usize
],
);
<Identities<T>>::insert(
from,
Registration {
Expand Down
38 changes: 0 additions & 38 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ use darwinia_deposit::Deposit;
use darwinia_staking::Ledger;
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, BlockNumber, Index};
// substrate
#[cfg(not(feature = "no-vesting"))]
use frame_support::traits::{LockableCurrency, WithdrawReasons};
use frame_support::{
migration,
pallet_prelude::*,
Expand All @@ -71,7 +69,6 @@ use frame_support::{
use frame_system::{pallet_prelude::*, AccountInfo, RawOrigin};
use pallet_balances::AccountData;
use pallet_identity::{Judgement, Registration};
use pallet_vesting::VestingInfo;
use sp_core::{
ed25519::{Public as Ep, Signature as Es},
sr25519::{Public as Sp, Signature as Ss},
Expand Down Expand Up @@ -103,16 +100,6 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

/// Enable vesting for account migration.
#[cfg(not(feature = "no-vesting"))]
pub trait OptionalVesting:
pallet_vesting::Config<Currency = pallet_balances::Pallet<Self>>
{
}
/// Disable vesting for account migration.
#[cfg(feature = "no-vesting")]
pub trait OptionalVesting {}

#[pallet::config]
pub trait Config:
frame_system::Config<
Expand All @@ -126,7 +113,6 @@ pub mod pallet {
+ pallet_identity::Config<Currency = pallet_balances::Pallet<Self>>
+ darwinia_deposit::Config
+ darwinia_staking::Config
+ OptionalVesting
{
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -172,15 +158,6 @@ pub mod pallet {
#[pallet::getter(fn kton_account_of)]
pub type KtonAccounts<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, AssetAccount>;

/// [`pallet_vesting::Vesting`] data.
///
/// <https://github.dev/paritytech/substrate/blob/19162e43be45817b44c7d48e50d03f074f60fbf4/frame/vesting/src/lib.rs#L188>
#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn vesting_of)]
pub type Vestings<T: Config> =
StorageMap<_, Blake2_128Concat, AccountId32, Vec<VestingInfo<Balance, BlockNumber>>>;

/// [`darwinia_deposit::Deposits`] data.
#[pallet::storage]
#[pallet::unbounded]
Expand Down Expand Up @@ -460,21 +437,6 @@ pub mod pallet {
);
}
}
#[cfg(not(feature = "no-vesting"))]
if let Some(v) = <Vestings<T>>::take(from) {
let locked = v.iter().map(|v| v.locked()).sum();

<pallet_vesting::Vesting<T>>::insert(
to,
BoundedVec::try_from(v).map_err(|_| <Error<T>>::ExceedMaxVestings)?,
);

// https://github.dev/paritytech/substrate/blob/19162e43be45817b44c7d48e50d03f074f60fbf4/frame/vesting/src/lib.rs#L248
let reasons = WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE;

// https://github.dev/paritytech/substrate/blob/19162e43be45817b44c7d48e50d03f074f60fbf4/frame/vesting/src/lib.rs#L86
<pallet_balances::Pallet<T>>::set_lock(*b"vesting ", to, locked, reasons);
}
if let Some(mut i) = <Identities<T>>::take(from) {
i.deposit = 0;
i.judgements.iter_mut().for_each(|(_, j)| {
Expand Down
12 changes: 0 additions & 12 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,6 @@ frame_support::parameter_types! {
frame_support::traits::WithdrawReasons::TRANSFER | frame_support::traits::WithdrawReasons::RESERVE
);
}
impl pallet_vesting::Config for Runtime {
type BlockNumberToBalance = sp_runtime::traits::ConvertInto;
type Currency = Balances;
type MinVestedTransfer = ();
type RuntimeEvent = RuntimeEvent;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type WeightInfo = ();

const MAX_VESTING_SCHEDULES: u32 = 1;
}

impl darwinia_deposit::Config for Runtime {
type Kton = Dummy;
Expand Down Expand Up @@ -211,7 +201,6 @@ impl pallet_identity::Config for Runtime {
type WeightInfo = ();
}

impl darwinia_account_migration::OptionalVesting for Runtime {}
impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand All @@ -227,7 +216,6 @@ frame_support::construct_runtime! {
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Assets: pallet_assets,
Vesting: pallet_vesting,
Deposit: darwinia_deposit,
Staking: darwinia_staking,
Identity: pallet_identity,
Expand Down
2 changes: 2 additions & 0 deletions pallet/deposit/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ impl pallet_assets::Config for Runtime {
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = frame_support::traits::AsEnsureOriginWithArg<
frame_system::EnsureSignedBy<frame_support::traits::IsInVec<()>, u32>,
Expand Down
34 changes: 0 additions & 34 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ macro_rules! impl_account_migration_tests {
Destroying,
}

// This struct is private in `pallet-vesting`.
#[derive(Encode)]
struct VestingInfo {
locked: u128,
per_block: u128,
starting_block: u32,
}

fn alice() -> (Pair, AccountId32) {
let pair = Keyring::Alice.pair();
let public_key = AccountId32::new(pair.public().0);
Expand Down Expand Up @@ -281,32 +273,6 @@ macro_rules! impl_account_migration_tests {
});
}

#[test]
fn vesting_should_work() {
let (from, from_pk) = alice();
let to = H160::from_low_u64_be(255).into();

ExtBuilder::default().build().execute_with(|| {
preset_state_of(&from);

migration::put_storage_value(
b"AccountMigration",
b"Vestings",
&Blake2_128Concat::hash(from_pk.as_ref()),
vec![
VestingInfo { locked: 100, per_block: 5, starting_block: 0 },
VestingInfo { locked: 100, per_block: 5, starting_block: 0 },
],
);
assert!(Vesting::vesting(to).is_none());
assert!(Balances::locks(to).is_empty());

assert_ok!(migrate(from, to));
assert_eq!(Vesting::vesting(to).unwrap().len(), 2);
assert_eq!(Balances::locks(to).len(), 1);
});
}

#[test]
fn staking_should_work() {
let (from, from_pk) = alice();
Expand Down
1 change: 0 additions & 1 deletion runtime/crab/src/pallets/account_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// darwinia
use crate::*;

impl darwinia_account_migration::OptionalVesting for Runtime {}
impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::darwinia_account_migration::WeightInfo<Self>;
Expand Down
1 change: 0 additions & 1 deletion runtime/darwinia/src/pallets/account_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// darwinia
use crate::*;

impl darwinia_account_migration::OptionalVesting for Runtime {}
impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::darwinia_account_migration::WeightInfo<Self>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parachain-info = { workspace = true }
cumulus-pallet-session-benchmarking = { workspace = true, optional = true }

# darwinia
darwinia-account-migration = { workspace = true, features = ["no-vesting"] }
darwinia-account-migration = { workspace = true }
darwinia-common-runtime = { workspace = true }
darwinia-deposit = { workspace = true }
darwinia-ecdsa-authority = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion runtime/pangolin/src/pallets/account_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// darwinia
use crate::*;

impl darwinia_account_migration::OptionalVesting for Runtime {}
impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::darwinia_account_migration::WeightInfo<Self>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/pangoro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parachain-info = { workspace = true }
cumulus-pallet-session-benchmarking = { workspace = true, optional = true }

# darwinia
darwinia-account-migration = { workspace = true, features = ["no-vesting"] }
darwinia-account-migration = { workspace = true }
darwinia-common-runtime = { workspace = true }
darwinia-deposit = { workspace = true }
darwinia-ecdsa-authority = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion runtime/pangoro/src/pallets/account_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// darwinia
use crate::*;

impl darwinia_account_migration::OptionalVesting for Runtime {}
impl darwinia_account_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::darwinia_account_migration::WeightInfo<Self>;
Expand Down

0 comments on commit 37db0a2

Please sign in to comment.