Skip to content

Commit

Permalink
Clean empty ledger (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <[email protected]>
  • Loading branch information
AurevoirXavier authored Feb 3, 2023
1 parent 9fc1dad commit 40d7eaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions tool/state-processor/src/staking/README.md
Original file line number Diff line number Diff line change
@@ -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`
16 changes: 11 additions & 5 deletions tool/state-processor/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ impl<S> Processor<S> {
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);
Expand Down Expand Up @@ -64,9 +73,6 @@ impl<S> Processor<S> {
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,
Expand All @@ -89,7 +95,7 @@ impl<S> Processor<S> {
unstaking_deposits: Default::default(),
},
);
});
}
}

ring_pool_storage.adjust();
Expand Down
8 changes: 8 additions & 0 deletions tool/state-processor/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ pub struct StakingLedger {
pub kton_staking_lock: StakingLock,
pub claimed_rewards: Vec<u32>,
}
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)]
Expand Down

0 comments on commit 40d7eaa

Please sign in to comment.