From 40d7eaabb7371b6fe2eda615ee7837d0b266a2be Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 3 Feb 2023 10:02:05 +0800 Subject: [PATCH] Clean empty ledger (#253) Signed-off-by: Xavier Lau --- tool/state-processor/src/staking/README.md | 1 + tool/state-processor/src/staking/mod.rs | 16 +++++++++++----- tool/state-processor/src/type_registry.rs | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tool/state-processor/src/staking/README.md b/tool/state-processor/src/staking/README.md index 4726c829d..946224a01 100644 --- a/tool/state-processor/src/staking/README.md +++ b/tool/state-processor/src/staking/README.md @@ -1,4 +1,5 @@ ### Process steps - take solo `Staking::Ledger`, `Staking::RingPool`, `Staking::KtonPool` and `Staking::LivingTime` +- clean empty ledger - adjust decimals and block number, convert ledger, adjust unstaking duration then set `AccountMigration::Ledgers` and `AccountMigration::Deposits` - set `Staking::RingPool` and `Staking::KtonPool` diff --git a/tool/state-processor/src/staking/mod.rs b/tool/state-processor/src/staking/mod.rs index 3cb20472f..7edde7175 100644 --- a/tool/state-processor/src/staking/mod.rs +++ b/tool/state-processor/src/staking/mod.rs @@ -24,7 +24,16 @@ impl Processor { let staking_ik = item_key(b"AccountMigration", b"Ledgers"); let deposit_ik = item_key(b"AccountMigration", b"Deposits"); - ledgers.into_iter().for_each(|(_, mut v)| { + for (_, mut v) in ledgers { + if v.is_empty() { + log::info!( + "clean empty ledger for Account({})", + array_bytes::bytes2hex("0x", v.stash) + ); + + continue; + } + v.adjust(); let hash_k = blake2_128_concat_to_string(v.stash); @@ -64,9 +73,6 @@ impl Processor { ring_pool += v.active; kton_pool += v.active_kton; - // Some accounts were killed. - // But their staking data didn't get deleted. - // TODO: https://github.com/darwinia-network/darwinia-2.0/issues/6 self.shell_state.inc_consumers_by(&array_bytes::bytes2hex("", v.stash), consumers); self.shell_state.insert_raw_key_value( staking_k, @@ -89,7 +95,7 @@ impl Processor { unstaking_deposits: Default::default(), }, ); - }); + } } ring_pool_storage.adjust(); diff --git a/tool/state-processor/src/type_registry.rs b/tool/state-processor/src/type_registry.rs index 57c7e0898..b0517ebb2 100644 --- a/tool/state-processor/src/type_registry.rs +++ b/tool/state-processor/src/type_registry.rs @@ -139,6 +139,14 @@ pub struct StakingLedger { pub kton_staking_lock: StakingLock, pub claimed_rewards: Vec, } +impl StakingLedger { + pub fn is_empty(&self) -> bool { + self.active == 0 + && self.active_deposit_ring == 0 + && self.active_kton == 0 + && self.deposit_items.is_empty() + } +} #[derive(Default, Debug, Encode, Decode)] pub struct TimeDepositItem { #[codec(compact)]