Skip to content

Commit

Permalink
Fix vesting processor (#144)
Browse files Browse the repository at this point in the history
* Fix vesting processor

Signed-off-by: Xavier Lau <[email protected]>

* Format

Signed-off-by: Xavier Lau <[email protected]>
  • Loading branch information
AurevoirXavier authored Dec 20, 2022
1 parent ced7f23 commit 7fd05bc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
10 changes: 10 additions & 0 deletions tool/state-processor/src/adjust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions tool/state-processor/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tool/state-processor/src/vesting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
21 changes: 11 additions & 10 deletions tool/state-processor/src/vesting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Map<VestingInfo>>::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
}
Expand Down

0 comments on commit 7fd05bc

Please sign in to comment.