From 153e06f6b5cb3421e7302434deb8467d818603b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Thu, 30 May 2024 10:52:51 +0200 Subject: [PATCH] small ref --- .../src/migrations/v13_stake_tracker/mod.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/substrate/frame/staking/src/migrations/v13_stake_tracker/mod.rs b/substrate/frame/staking/src/migrations/v13_stake_tracker/mod.rs index 50619e758f97..2ebe9361170a 100644 --- a/substrate/frame/staking/src/migrations/v13_stake_tracker/mod.rs +++ b/substrate/frame/staking/src/migrations/v13_stake_tracker/mod.rs @@ -87,8 +87,8 @@ impl, W: weights::WeightInfo> SteppedMigration // do as much progress as possible per step. while meter.try_consume(required).is_ok() { let new_cursor = match cursor { - None | Some((None, Processing::Nominators)) => { - // start processing nominators, start from the first. + None => { + // start processing first nominator. if let Some((nominator, nominations)) = Nominators::::iter().next() { Self::process_nominator(&nominator, nominations)?; Some((Some(nominator), Processing::Nominators)) @@ -96,30 +96,30 @@ impl, W: weights::WeightInfo> SteppedMigration Some((None, Processing::Validators)) } }, - Some((Some(ref last_nom), Processing::Nominators)) => { - // proceed with nominators. - let mut iter = - Nominators::::iter_from(Nominators::::hashed_key_for(last_nom)); + Some((maybe_nominator, Processing::Nominators)) => { + let mut iter = if let Some(last_nominator) = maybe_nominator { + Nominators::::iter_from(Nominators::::hashed_key_for(last_nominator)) + } else { + Nominators::::iter() + }; if let Some((nominator, nominations)) = iter.next() { Self::process_nominator(&nominator, nominations)?; Some((Some(nominator), Processing::Nominators)) } else { + // no more nominators to process, go to next phase. Some((None, Processing::Validators)) } }, - Some((None, Processing::Validators)) => { - // nominators have been all processed, start processing validators. - if let Some((validator, _)) = Validators::::iter().next() { - Self::process_validator(&validator); - Some((Some(validator), Processing::Validators)) + Some((maybe_validator, Processing::Validators)) => { + // process validator. + let mut iter = if let Some(last_validator) = maybe_validator { + Validators::::iter_from(Validators::::hashed_key_for(last_validator)) } else { - Some((None, Processing::Done)) - } - }, - Some((Some(ref last_val), Processing::Validators)) => { - let mut iter = - Validators::::iter_from(Validators::::hashed_key_for(last_val)); + Validators::::iter() + }; + + // nominators have been all processed, start processing validators. if let Some((validator, _)) = iter.next() { Self::process_validator(&validator); Some((Some(validator), Processing::Validators))