Skip to content

Commit

Permalink
done (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
4meta5 authored Jun 30, 2021
1 parent ab09b8e commit 3f6576b
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,6 @@ pub mod pallet {
pub total: Balance,
}

#[derive(Encode, Decode, RuntimeDebug)]
/// DEPRECATED: This is the old storage schema. It is retained for purposes of storage migration
/// and should be removed in the future.
pub struct Collator<AccountId, Balance> {
pub id: AccountId,
pub bond: Balance,
pub nominators: OrderedSet<Bond<AccountId, Balance>>,
pub total: Balance,
pub state: CollatorStatus,
}

#[derive(Encode, Decode, RuntimeDebug)]
/// Collator state with commission fee, bonded stake, and nominations
pub struct Collator2<AccountId, Balance> {
Expand Down Expand Up @@ -439,31 +428,6 @@ pub mod pallet {
}
}

impl<A: Clone + Ord, B: Ord + Copy> From<Collator<A, B>> for Collator2<A, B> {
fn from(other: Collator<A, B>) -> Collator2<A, B> {
// nominator set from Collator was bounded to max size of top_nominators
let mut top_nominators = other.nominators.0.clone();
// order greatest to least
top_nominators.sort_unstable_by(|a, b| b.amount.cmp(&a.amount));
Collator2 {
id: other.id,
bond: other.bond,
nominators: other
.nominators
.0
.iter()
.map(|Bond { owner, .. }| owner.clone())
.collect::<Vec<A>>()
.into(),
top_nominators,
bottom_nominators: Vec::new(),
total_counted: other.total,
total_backing: other.total,
state: other.state,
}
}
}

impl<A: Clone, B: Copy> From<Collator2<A, B>> for CollatorSnapshot<A, B> {
fn from(other: Collator2<A, B>) -> CollatorSnapshot<A, B> {
CollatorSnapshot {
Expand Down Expand Up @@ -764,33 +728,6 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
// migrate from Collator -> Collator2
for (acc, collator_state) in CollatorState::<T>::drain() {
let state: Collator2<T::AccountId, BalanceOf<T>> = collator_state.into();
<CollatorState2<T>>::insert(acc, state);
}

// correct any incorrectly set `Total`
let old_total = Total::<T>::get();
let mut new_total: BalanceOf<T> = 0u32.into();

for collator_state in CollatorState2::<T>::iter_values() {
new_total += collator_state.total_backing;
}

Total::<T>::put(new_total);

log::trace!(
target: "staking",
"Finished migrating storage.\nOld Total : {:?}\nNew Total : {:?}",
old_total,
new_total,
);

300_000_000_000 // Three fifths of the max block weight
}

fn on_initialize(n: T::BlockNumber) -> Weight {
let mut round = <Round<T>>::get();
if round.should_update(n) {
Expand Down Expand Up @@ -852,18 +789,6 @@ pub mod pallet {
OptionQuery,
>;

#[pallet::storage]
#[pallet::getter(fn collator_state)]
/// DEPRECATED: This is the old storage item. It is retained for purposes of storage migration
/// and should be removed in the future.
type CollatorState<T: Config> = StorageMap<
_,
Twox64Concat,
T::AccountId,
Collator<T::AccountId, BalanceOf<T>>,
OptionQuery,
>;

#[pallet::storage]
#[pallet::getter(fn collator_state2)]
/// Get collator state associated with an account if account is collating else None
Expand Down

0 comments on commit 3f6576b

Please sign in to comment.