Skip to content

Commit 40d7eaa

Browse files
authored
Clean empty ledger (#253)
Signed-off-by: Xavier Lau <xavier@inv.cafe>
1 parent 9fc1dad commit 40d7eaa

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### Process steps
22
- take solo `Staking::Ledger`, `Staking::RingPool`, `Staking::KtonPool` and `Staking::LivingTime`
3+
- clean empty ledger
34
- adjust decimals and block number, convert ledger, adjust unstaking duration then set `AccountMigration::Ledgers` and `AccountMigration::Deposits`
45
- set `Staking::RingPool` and `Staking::KtonPool`

tool/state-processor/src/staking/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ impl<S> Processor<S> {
2424
let staking_ik = item_key(b"AccountMigration", b"Ledgers");
2525
let deposit_ik = item_key(b"AccountMigration", b"Deposits");
2626

27-
ledgers.into_iter().for_each(|(_, mut v)| {
27+
for (_, mut v) in ledgers {
28+
if v.is_empty() {
29+
log::info!(
30+
"clean empty ledger for Account({})",
31+
array_bytes::bytes2hex("0x", v.stash)
32+
);
33+
34+
continue;
35+
}
36+
2837
v.adjust();
2938

3039
let hash_k = blake2_128_concat_to_string(v.stash);
@@ -64,9 +73,6 @@ impl<S> Processor<S> {
6473
ring_pool += v.active;
6574
kton_pool += v.active_kton;
6675

67-
// Some accounts were killed.
68-
// But their staking data didn't get deleted.
69-
// TODO: https://github.com/darwinia-network/darwinia-2.0/issues/6
7076
self.shell_state.inc_consumers_by(&array_bytes::bytes2hex("", v.stash), consumers);
7177
self.shell_state.insert_raw_key_value(
7278
staking_k,
@@ -89,7 +95,7 @@ impl<S> Processor<S> {
8995
unstaking_deposits: Default::default(),
9096
},
9197
);
92-
});
98+
}
9399
}
94100

95101
ring_pool_storage.adjust();

tool/state-processor/src/type_registry.rs

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ pub struct StakingLedger {
139139
pub kton_staking_lock: StakingLock,
140140
pub claimed_rewards: Vec<u32>,
141141
}
142+
impl StakingLedger {
143+
pub fn is_empty(&self) -> bool {
144+
self.active == 0
145+
&& self.active_deposit_ring == 0
146+
&& self.active_kton == 0
147+
&& self.deposit_items.is_empty()
148+
}
149+
}
142150
#[derive(Default, Debug, Encode, Decode)]
143151
pub struct TimeDepositItem {
144152
#[codec(compact)]

0 commit comments

Comments
 (0)