From 8ae16886f5fa6d895dc9163013149115fb3119ff Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 11 Sep 2024 11:33:12 +0300 Subject: [PATCH] Translate block number to relay block number --- substrate/frame/broker/src/migration.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index e467177a5bac2..babaa3d489998 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -262,19 +262,29 @@ mod v4 { // using a u32::MAX as sentinel value in case TryFrom fails. // Ref: https://github.com/paritytech/polkadot-sdk/pull/3331#discussion_r1499014975 + let current_block: RelayBlockNumberOf = + match TryFrom::try_from(frame_system::Pallet::::block_number()) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + let current_relay_number = crate::Pallet::::relay_height(); + let offset = current_relay_number - current_block; + + let translate_old_block_number_to_relay_height = + |old_block_number: RelayBlockNumberOf| offset + old_block_number * 2u32.into(); if let Some(config_record) = v3::Configuration::::take() { log::info!(target: LOG_TARGET, "migrating Configuration record"); let updated_interlude_length: RelayBlockNumberOf = match TryFrom::try_from(config_record.interlude_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; let updated_leadin_length: RelayBlockNumberOf = match TryFrom::try_from(config_record.leadin_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; @@ -297,13 +307,13 @@ mod v4 { let updated_sale_start: RelayBlockNumberOf = match TryFrom::try_from(sale_info.sale_start) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; let updated_leadin_length: RelayBlockNumberOf = match TryFrom::try_from(sale_info.leadin_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), };