diff --git a/tool/state-processor/src/adjust.rs b/tool/state-processor/src/adjust.rs index 59b9485ce..5b3c8d724 100644 --- a/tool/state-processor/src/adjust.rs +++ b/tool/state-processor/src/adjust.rs @@ -33,6 +33,16 @@ impl Adjust for BalanceLock { } } +impl Adjust for VestingInfo { + fn adjust(&mut self) { + self.locked.adjust(); + self.per_block *= 2; + self.per_block.adjust(); + self.starting_block = + self.starting_block.checked_sub(*NOW.read().unwrap()).unwrap_or_default(); + } +} + impl Adjust for StakingLedger { fn adjust(&mut self) { self.active.adjust(); diff --git a/tool/state-processor/src/type_registry.rs b/tool/state-processor/src/type_registry.rs index 750da96d3..b5e1c877d 100644 --- a/tool/state-processor/src/type_registry.rs +++ b/tool/state-processor/src/type_registry.rs @@ -33,6 +33,13 @@ pub enum Reasons { All = 2, } +#[derive(Debug, Encode, Decode)] +pub struct VestingInfo { + pub locked: u128, + pub per_block: u128, + pub starting_block: u32, +} + #[derive(Debug, Encode, Decode)] pub struct Deposit { pub id: u8, diff --git a/tool/state-processor/src/vesting/README.md b/tool/state-processor/src/vesting/README.md index 7088a5e46..66df48663 100644 --- a/tool/state-processor/src/vesting/README.md +++ b/tool/state-processor/src/vesting/README.md @@ -2,4 +2,5 @@ > There are only 3 vesting records on Crab and 1 vesting record on Darwinia. - take solo `Vesting::Vesting` +- adjust solo `VestingInfo`s - set `AccountMigration::Vestings` diff --git a/tool/state-processor/src/vesting/mod.rs b/tool/state-processor/src/vesting/mod.rs index 015953ea1..5a49b8dd6 100644 --- a/tool/state-processor/src/vesting/mod.rs +++ b/tool/state-processor/src/vesting/mod.rs @@ -5,19 +5,20 @@ impl Processor { pub fn process_vesting(&mut self) -> &mut Self { // Storage items. // https://github.dev/darwinia-network/substrate/blob/darwinia-v0.12.5/frame/vesting/src/lib.rs#L188 - let mut vestings = Map::default(); + let mut vestings = >::default(); - // TODO: adjust decimals - // TODO: adjust block number log::info!("take solo `Vesting::Vesting`"); - self.solo_state.take_raw_map( - &item_key(b"Vesting", b"Vesting"), - &mut vestings, - |key, from| replace_first_match(key, from, &item_key(b"AccountMigration", b"Vestings")), - ); + self.solo_state.take_map(b"Vesting", b"Vesting", &mut vestings, get_hashed_key); - log::info!("set `Vesting::Vesting`"); - self.shell_state.insert_raw_key_map(vestings); + log::info!("adjust solo `VestingInfo`s"); + vestings.iter_mut().for_each(|(_, v)| v.adjust()); + + log::info!("set `AccountMigration::Vestings`"); + { + let ik = item_key(b"AccountMigration", b"Vestings"); + + self.shell_state.insert_map(vestings, |h| format!("{ik}{h}")); + } self }