From 00be2dd66e6a4fc140f728a982bea04b923de36f Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 25 Jul 2023 05:29:13 -0300 Subject: [PATCH 1/9] rework v9 migration --- .../src/migrations/v9.rs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs index d420af067..c31e0cfbb 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs @@ -6,6 +6,20 @@ use scale_info::prelude::string::String; use sp_core::Get; use sp_std::{marker::PhantomData, vec, vec::Vec}; +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() >= types::StorageVersion::V8); + + check_pallet_smart_contract::(); + + Ok(vec![]) + } +} + pub struct CleanStorageState(PhantomData); impl OnRuntimeUpgrade for CleanStorageState { @@ -22,16 +36,6 @@ impl OnRuntimeUpgrade for CleanStorageState { Weight::zero() } } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() == types::StorageVersion::V8 || PalletVersion::::get() == types::StorageVersion::V9); - - check_pallet_smart_contract::(); - - Ok(vec![]) - } } pub fn check_pallet_smart_contract() { From 1f4c3c5859b6b70f6476766d8d762ccba005e8c4 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 25 Jul 2023 05:30:26 -0300 Subject: [PATCH 2/9] firt version of v15 check storage state --- .../pallet-tfgrid/src/migrations/mod.rs | 2 +- .../pallet-tfgrid/src/migrations/v15.rs | 364 +++++++++++++++++- 2 files changed, 362 insertions(+), 4 deletions(-) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/mod.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/mod.rs index ee058f3c7..6823f05f2 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/mod.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/mod.rs @@ -4,4 +4,4 @@ pub mod v11; pub mod v12; pub mod v13; pub mod v14; -//pub mod v15; +pub mod v15; diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index 341523adf..c6f9678a9 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -1,12 +1,13 @@ use crate::*; use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; -use sp_std::marker::PhantomData; +use scale_info::prelude::string::String; +use sp_std::{marker::PhantomData, vec::Vec}; #[cfg(feature = "try-runtime")] -use parity_scale_codec::Decode; +use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] -use sp_std::vec::Vec; +use sp_std::vec; pub struct MigrateTwinsV15(PhantomData); @@ -85,3 +86,360 @@ pub fn migrate_twins() -> frame_support::weights::Weight { // Return the weight consumed by the migration. T::DbWeight::get().reads_writes(read_writes, read_writes + 1) } + +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() == types::StorageVersion::V15Struct); + + check_pallet_tfgrid::(); + + Ok(vec![]) + } +} + +pub fn check_pallet_tfgrid() { + info!("💥💥💥💥💥 CHECKING PALLET TFGRID STORAGE 💥💥💥💥💥"); + check_farms::(); + check_nodes_by_farm_id::(); + check_farm_id_by_name::(); + check_farm_payout_v2_address_by_farm_id::(); + check_nodes::(); + check_node_id_by_twin_id::(); + // check_entities::(); + // check_entity_id_by_account_id::(); + // check_entity_id_by_name::(); + check_twins::(); + check_twin_id_by_account_id::(); + check_twin_bounded_account_id::(); + check_pricing_policies::(); + check_pricing_policy_id_by_name::(); + check_farming_policies_map::(); + check_users_terms_and_conditions::(); +} + +// Farms +pub fn check_farms() { + debug!( + "🔎 TFGrid pallet {:?} checking Farms storage map START", + PalletVersion::::get() + ); + + let farm_id_range = 1..=FarmID::::get(); + + for (farm_id, farm) in Farms::::iter() { + if farm_id != farm.id { + debug!(" ⚠️ Farms[id: {}]: wrong id ({})", farm_id, farm.id); + } + if !farm_id_range.contains(&farm_id) { + debug!( + " ⚠️ Farms[id: {}]: id not in range {:?}", + farm_id, farm_id_range + ); + } + + // FarmIdByName + if !FarmIdByName::::contains_key(farm.name.clone().into()) { + debug!( + " ⚠️ Farm[id: {}]: farm (name: {}) not found", + farm_id, + String::from_utf8_lossy(&farm.name.into()) + ); + } + + // Twins + if !Twins::::contains_key(farm.twin_id) { + debug!( + " ⚠️ Farm[id: {}]: twin (twin_id: {}) not found", + farm_id, farm.twin_id + ); + } + + // PricingPolicies + if !PricingPolicies::::contains_key(farm.pricing_policy_id) { + debug!( + " ⚠️ Farm[id: {}]: pricing policy (pricing_policy_id: {}) not found", + farm_id, farm.pricing_policy_id + ); + } + + // FarmingPoliciesMap + if let Some(limits) = farm.farming_policy_limits { + if !FarmingPoliciesMap::::contains_key(limits.farming_policy_id) { + debug!( + " ⚠️ Farm[id: {}]: farming policy (farming_policy_id: {}) not found", + farm_id, limits.farming_policy_id + ); + } + } + } + + debug!( + "🏁 TFGrid pallet {:?} checking Farms storage map END", + PalletVersion::::get() + ); +} + +// NodesByFarmID +pub fn check_nodes_by_farm_id() { + debug!( + "🔎 TFGrid pallet {:?} checking NodesByFarmID storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking NodesByFarmID storage map END", + PalletVersion::::get() + ); +} + +// FarmIdByName +pub fn check_farm_id_by_name() { + debug!( + "🔎 TFGrid pallet {:?} checking FarmIdByName storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking FarmIdByName storage map END", + PalletVersion::::get() + ); +} + +// FarmPayoutV2AddressByFarmID +pub fn check_farm_payout_v2_address_by_farm_id() { + debug!( + "🔎 TFGrid pallet {:?} checking FarmPayoutV2AddressByFarmID storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking FarmPayoutV2AddressByFarmID storage map END", + PalletVersion::::get() + ); +} + +// Nodes +pub fn check_nodes() { + debug!( + "🔎 TFGrid pallet {:?} checking Nodes storage map START", + PalletVersion::::get() + ); + + let node_id_range = 1..=NodeID::::get(); + + for (node_id, node) in Nodes::::iter() { + if node_id != node.id { + debug!(" ⚠️ Nodes[id: {}]: wrong id ({})", node_id, node.id); + } + if !node_id_range.contains(&node_id) { + debug!( + " ⚠️ Nodes[id: {}]: id not in range {:?}", + node_id, node_id_range + ); + } + + // TODO + } + + debug!( + "🏁 TFGrid pallet {:?} checking Nodes storage map END", + PalletVersion::::get() + ); +} + +// NodeIdByTwinID +pub fn check_node_id_by_twin_id() { + debug!( + "🔎 TFGrid pallet {:?} checking NodeIdByTwinID storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking NodeIdByTwinID storage map END", + PalletVersion::::get() + ); +} + +// Entities +// pub type EntityIdByAccountID +// pub type EntityIdByName + +// Twins +pub fn check_twins() { + debug!( + "🔎 TFGrid pallet {:?} checking Twins storage map START", + PalletVersion::::get() + ); + + let twin_id_range = 1..=TwinID::::get(); + + for (twin_id, twin) in Twins::::iter() { + if twin_id != twin.id { + debug!(" ⚠️ Twins[id: {}]: wrong id ({})", twin_id, twin.id); + } + if !twin_id_range.contains(&twin_id) { + debug!( + " ⚠️ Twins[id: {}]: id not in range {:?}", + twin_id, twin_id_range + ); + } + + // TODO + } + + debug!( + "🏁 TFGrid pallet {:?} checking Twins storage map END", + PalletVersion::::get() + ); +} + +// TwinIdByAccountID +pub fn check_twin_id_by_account_id() { + debug!( + "🔎 TFGrid pallet {:?} checking TwinIdByAccountID storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking TwinIdByAccountID storage map END", + PalletVersion::::get() + ); +} + +// TwinBoundedAccountID +pub fn check_twin_bounded_account_id() { + debug!( + "🔎 TFGrid pallet {:?} checking TwinBoundedAccountID storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking TwinBoundedAccountID storage map END", + PalletVersion::::get() + ); +} + +// PricingPolicies +pub fn check_pricing_policies() { + debug!( + "🔎 TFGrid pallet {:?} checking PricingPolicies storage map START", + PalletVersion::::get() + ); + + let pricing_policy_id_range = 1..=PricingPolicyID::::get(); + + for (pricing_policy_id, pricing_policy) in PricingPolicies::::iter() { + if pricing_policy_id != pricing_policy.id { + debug!( + " ⚠️ PricingPolicies[id: {}]: wrong id ({})", + pricing_policy_id, pricing_policy.id + ); + } + if !pricing_policy_id_range.contains(&pricing_policy_id) { + debug!( + " ⚠️ PricingPolicies[id: {}]: id not in range {:?}", + pricing_policy_id, pricing_policy_id_range + ); + } + + // TODO + } + + debug!( + "🏁 TFGrid pallet {:?} checking PricingPolicies storage map END", + PalletVersion::::get() + ); +} + +// PricingPolicyIdByName +pub fn check_pricing_policy_id_by_name() { + debug!( + "🔎 TFGrid pallet {:?} checking PricingPolicyIdByName storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking Farms PricingPolicyIdByName map END", + PalletVersion::::get() + ); +} + +// FarmingPoliciesMap +pub fn check_farming_policies_map() { + debug!( + "🔎 TFGrid pallet {:?} checking FarmingPoliciesMap storage map START", + PalletVersion::::get() + ); + + let farming_policy_id_range = 1..=FarmingPolicyID::::get(); + + for (farming_policy_id, farming_policy) in FarmingPoliciesMap::::iter() { + if farming_policy_id != farming_policy.id { + debug!( + " ⚠️ FarmingPoliciesMap[id: {}]: wrong id ({})", + farming_policy_id, farming_policy.id + ); + } + if !farming_policy_id_range.contains(&farming_policy_id) { + debug!( + " ⚠️ FarmingPoliciesMap[id: {}]: id not in range {:?}", + farming_policy_id, farming_policy_id_range + ); + } + + // TODO + } + + debug!( + "🏁 TFGrid pallet {:?} checking FarmingPoliciesMap storage map END", + PalletVersion::::get() + ); +} + +// UsersTermsAndConditions +pub fn check_users_terms_and_conditions() { + debug!( + "🔎 TFGrid pallet {:?} checking UsersTermsAndConditions storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking UsersTermsAndConditions storage map END", + PalletVersion::::get() + ); +} + +// NodePower +pub fn check_node_power() { + debug!( + "🔎 TFGrid pallet {:?} checking NodePower storage map START", + PalletVersion::::get() + ); + + // TODO + + debug!( + "🏁 TFGrid pallet {:?} checking NodePower storage map END", + PalletVersion::::get() + ); +} From 3fa2bc2ccc3cfeeeccb7b922f5a439c3a1094ed2 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 25 Jul 2023 05:31:13 -0300 Subject: [PATCH 3/9] add v9 and v15 check storage state to runtime --- substrate-node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 5c9f5bc1d..c8273369c 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -766,8 +766,8 @@ pub type Executive = frame_executive::Executive< // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. type Migrations = ( - pallet_smart_contract::migrations::v10::ReworkBillingLoopInsertion, - pallet_smart_contract::migrations::v11::ExtendContractLock, + pallet_smart_contract::migrations::v9::CheckStorageState, + pallet_tfgrid::migrations::v15::CheckStorageState, ); // follows Substrate's non destructive way of eliminating otherwise required From 868b41561fc325eb77f7c24449b585343549f831 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 25 Jul 2023 10:50:52 -0300 Subject: [PATCH 4/9] checking farm / node / twin related storage --- .../pallet-tfgrid/src/migrations/v15.rs | 116 ++++++++++++++++-- 1 file changed, 108 insertions(+), 8 deletions(-) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index c6f9678a9..f4dab7c37 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -190,7 +190,20 @@ pub fn check_nodes_by_farm_id() { PalletVersion::::get() ); - // TODO + for (farm_id, nodes) in NodesByFarmID::::iter() { + if Farms::::get(farm_id).is_none() { + debug!(" ⚠️ NodesByFarmID[farm: {}]: farm not exists", farm_id); + } + + for node_id in nodes { + if Nodes::::get(node_id).is_none() { + debug!( + " ⚠️ NodesByFarmID[farm: {}]: node {} not exists", + farm_id, node_id + ); + } + } + } debug!( "🏁 TFGrid pallet {:?} checking NodesByFarmID storage map END", @@ -205,7 +218,24 @@ pub fn check_farm_id_by_name() { PalletVersion::::get() ); - // TODO + for (farm_name, farm_id) in FarmIdByName::::iter() { + if let Some(farm) = Farms::::get(farm_id) { + if farm_name != farm.name.clone().into() { + debug!( + " ⚠️ FarmIdByName[name: {}]: name ({:?}) on farm {} not matching", + String::from_utf8_lossy(&farm_name), + String::from_utf8_lossy(&farm.name.into()), + farm_id, + ); + } + } else { + debug!( + " ⚠️ FarmIdByName[name: {}]: farm {} not exists", + String::from_utf8_lossy(&farm_name), + farm_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking FarmIdByName storage map END", @@ -220,7 +250,14 @@ pub fn check_farm_payout_v2_address_by_farm_id() { PalletVersion::::get() ); - // TODO + for (farm_id, _stellar_address) in FarmPayoutV2AddressByFarmID::::iter() { + if Farms::::get(farm_id).is_none() { + debug!( + " ⚠️ FarmPayoutV2AddressByFarmID[farm id: {}]: farm not exists", + farm_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking FarmPayoutV2AddressByFarmID storage map END", @@ -248,7 +285,29 @@ pub fn check_nodes() { ); } - // TODO + // Farms + if !Farms::::contains_key(node.farm_id) { + debug!( + " ⚠️ Nodes[id: {}]: farm (farm_id: {}) not found", + node_id, node.farm_id + ); + } + + // Twins + if !Twins::::contains_key(node.twin_id) { + debug!( + " ⚠️ Nodes[id: {}]: twin (twin_id: {}) not found", + node_id, node.twin_id + ); + } + + // FarmingPoliciesMap + if !FarmingPoliciesMap::::contains_key(node.farming_policy_id) { + debug!( + " ⚠️ Node[id: {}]: farming policy (farming_policy_id: {}) not found", + node_id, node.farming_policy_id + ); + } } debug!( @@ -264,7 +323,21 @@ pub fn check_node_id_by_twin_id() { PalletVersion::::get() ); - // TODO + for (twin_id, node_id) in NodeIdByTwinID::::iter() { + if Twins::::get(twin_id).is_none() { + debug!( + " ⚠️ NodeIdByTwinID[twin_id: {}]: twin not exists", + twin_id + ); + } + + if Nodes::::get(node_id).is_none() { + debug!( + " ⚠️ NodeIdByTwinID[twin_id: {}]: node {} not exists", + twin_id, node_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking NodeIdByTwinID storage map END", @@ -296,7 +369,13 @@ pub fn check_twins() { ); } - // TODO + // TwinIdByAccountID + if !TwinIdByAccountID::::contains_key(&twin.account_id) { + debug!( + " ⚠️ Twins[id: {}]: account (account_id: {:?}) not found", + twin_id, twin.account_id + ); + } } debug!( @@ -312,7 +391,21 @@ pub fn check_twin_id_by_account_id() { PalletVersion::::get() ); - // TODO + for (account_id, twin_id) in TwinIdByAccountID::::iter() { + if let Some(twin) = Twins::::get(twin_id) { + if account_id != twin.account_id { + debug!( + " ⚠️ TwinIdByAccountID[account_id: {:?}]: account ({:?}) on twin {} not matching", + account_id, twin.account_id, twin_id, + ); + } + } else { + debug!( + " ⚠️ TwinIdByAccountID[account_id: {:?}]: twin {} not exists", + account_id, twin_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking TwinIdByAccountID storage map END", @@ -327,7 +420,14 @@ pub fn check_twin_bounded_account_id() { PalletVersion::::get() ); - // TODO + for (twin_id, _bounded_account_id) in TwinBoundedAccountID::::iter() { + if Twins::::get(twin_id).is_none() { + debug!( + " ⚠️ TwinBoundedAccountID[twin_id: {}]: twin not exists", + twin_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking TwinBoundedAccountID storage map END", From a50021a8f526728b1dbb26a262114b650de72083 Mon Sep 17 00:00:00 2001 From: renauter Date: Thu, 27 Jul 2023 06:49:07 -0300 Subject: [PATCH 5/9] checking t&c / policies / power --- .../pallet-tfgrid/src/migrations/v15.rs | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index f4dab7c37..44aa4d988 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -376,6 +376,14 @@ pub fn check_twins() { twin_id, twin.account_id ); } + + // UsersTermsAndConditions + if !UsersTermsAndConditions::::contains_key(&twin.account_id) { + debug!( + " ⚠️ Twins[id: {}]: users terms and conditions (account_id: {:?}) not found", + twin_id, twin.account_id + ); + } } debug!( @@ -458,7 +466,14 @@ pub fn check_pricing_policies() { ); } - // TODO + // PricingPolicyIdByName + if !PricingPolicyIdByName::::contains_key(&pricing_policy.name) { + debug!( + " ⚠️ PricingPolicies[id: {}]: : pricing policy (name: {}) not found", + pricing_policy_id, + String::from_utf8_lossy(&pricing_policy.name), + ); + } } debug!( @@ -474,7 +489,24 @@ pub fn check_pricing_policy_id_by_name() { PalletVersion::::get() ); - // TODO + for (pricing_policy_name, pricing_policy_id) in PricingPolicyIdByName::::iter() { + if let Some(pricing_policy) = PricingPolicies::::get(pricing_policy_id) { + if pricing_policy_name != pricing_policy.name { + debug!( + " ⚠️ PricingPolicyIdByName[name: {}]: name ({:?}) on pricing policy {} not matching", + String::from_utf8_lossy(&pricing_policy_name), + String::from_utf8_lossy(&pricing_policy.name), + pricing_policy_id, + ); + } + } else { + debug!( + " ⚠️ PricingPolicyIdByName[name: {}]: pricing policy {} not exists", + String::from_utf8_lossy(&pricing_policy_name), + pricing_policy_id + ); + } + } debug!( "🏁 TFGrid pallet {:?} checking Farms PricingPolicyIdByName map END", @@ -505,7 +537,7 @@ pub fn check_farming_policies_map() { ); } - // TODO + // Nothing to add here } debug!( @@ -521,7 +553,7 @@ pub fn check_users_terms_and_conditions() { PalletVersion::::get() ); - // TODO + // Nothing to do here debug!( "🏁 TFGrid pallet {:?} checking UsersTermsAndConditions storage map END", @@ -536,7 +568,11 @@ pub fn check_node_power() { PalletVersion::::get() ); - // TODO + for (twin_id, _node_power) in NodePower::::iter() { + if Twins::::get(twin_id).is_none() { + debug!(" ⚠️ NodePower[twin_id: {}]: twin not exists", twin_id); + } + } debug!( "🏁 TFGrid pallet {:?} checking NodePower storage map END", From e3b65b6577164a576e60c27f436644a7eb5875df Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 28 Jul 2023 12:35:59 +0200 Subject: [PATCH 6/9] trying to fix AccountId display with no success --- .../pallets/pallet-tfgrid/src/migrations/v15.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index 44aa4d988..ebdc0be2c 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -2,6 +2,7 @@ use crate::*; use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; use scale_info::prelude::string::String; +use sp_core::H256; use sp_std::{marker::PhantomData, vec::Vec}; #[cfg(feature = "try-runtime")] @@ -373,7 +374,7 @@ pub fn check_twins() { if !TwinIdByAccountID::::contains_key(&twin.account_id) { debug!( " ⚠️ Twins[id: {}]: account (account_id: {:?}) not found", - twin_id, twin.account_id + twin_id, &twin.account_id ); } @@ -381,7 +382,7 @@ pub fn check_twins() { if !UsersTermsAndConditions::::contains_key(&twin.account_id) { debug!( " ⚠️ Twins[id: {}]: users terms and conditions (account_id: {:?}) not found", - twin_id, twin.account_id + twin_id, &twin.account_id ); } } @@ -404,13 +405,13 @@ pub fn check_twin_id_by_account_id() { if account_id != twin.account_id { debug!( " ⚠️ TwinIdByAccountID[account_id: {:?}]: account ({:?}) on twin {} not matching", - account_id, twin.account_id, twin_id, + &account_id, &twin.account_id, twin_id, ); } } else { debug!( " ⚠️ TwinIdByAccountID[account_id: {:?}]: twin {} not exists", - account_id, twin_id + &account_id, twin_id ); } } From 48c63e7f9c4c4627770e580ea7c62585333840c8 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 7 Aug 2023 15:28:18 +0200 Subject: [PATCH 7/9] defining CheckStorageState for v10 v11 smart contract migrations --- .../src/migrations/v10.rs | 14 ++++++++ .../src/migrations/v11.rs | 32 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs index b067254f0..364dba06f 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs @@ -81,3 +81,17 @@ pub fn rework_billing_loop_insertion() -> frame_support::weights::Wei Weight::zero() } } + +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() == types::StorageVersion::V10); + + migrations::v9::check_pallet_smart_contract::(); + + Ok(vec![]) + } +} diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs index 9d7b5e9e2..549138dc3 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs @@ -45,7 +45,7 @@ impl OnRuntimeUpgrade for ExtendContractLock { debug!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V11); - check_contract_lock_v11::(); + check_contract_lock::(); debug!( "👥 Smart Contract pallet to {:?} passes POST migrate checks ✅", @@ -86,7 +86,35 @@ pub fn migrate_to_version_11() -> frame_support::weights::Weight { T::DbWeight::get().reads_writes(r, w) } -pub fn check_contract_lock_v11() { +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() == types::StorageVersion::V11); + + check_pallet_smart_contract::(); + + Ok(vec![]) + } +} + +pub fn check_pallet_smart_contract() { + info!("💥💥💥💥💥 CHECKING PALLET SMART CONTRACT STORAGE 💥💥💥💥💥"); + migrations::v9::check_contracts::(); + migrations::v9::check_contracts_to_bill_at::(); + migrations::v9::check_active_node_contracts::(); + migrations::v9::check_active_rent_contract_for_node::(); + migrations::v9::check_contract_id_by_node_id_and_hash::(); + migrations::v9::check_contract_id_by_name_registration::(); + check_contract_lock::(); + migrations::v9::check_solution_providers::(); + migrations::v9::check_contract_billing_information_by_id::(); + migrations::v9::check_node_contract_resources::(); +} + +fn check_contract_lock() { debug!( "🔎 Smart Contract pallet {:?} checking ContractLock storage map START", PalletVersion::::get() From 3b15b64076e9a2f27f327fa04fa18a1be3af91b9 Mon Sep 17 00:00:00 2001 From: renauter Date: Thu, 17 Aug 2023 10:45:30 +0200 Subject: [PATCH 8/9] add v16 check storage state --- .../pallet-tfgrid/src/migrations/v15.rs | 1 - .../pallet-tfgrid/src/migrations/v16.rs | 21 +++++++++++++++++++ substrate-node/runtime/src/lib.rs | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index ebdc0be2c..bd693145b 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -2,7 +2,6 @@ use crate::*; use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; use scale_info::prelude::string::String; -use sp_core::H256; use sp_std::{marker::PhantomData, vec::Vec}; #[cfg(feature = "try-runtime")] diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v16.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v16.rs index 8c51465d0..e69b41102 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v16.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v16.rs @@ -7,6 +7,9 @@ use log::info; use sp_core::Get; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use sp_std::{vec, vec::Vec}; + pub struct KillNodeGpuStatus(PhantomData); impl OnRuntimeUpgrade for KillNodeGpuStatus { @@ -43,3 +46,21 @@ impl OnRuntimeUpgrade for KillNodeGpuStatus { } } } + +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() == types::StorageVersion::V16Struct); + + check_pallet_tfgrid::(); + + Ok(vec![]) + } +} + +pub fn check_pallet_tfgrid() { + migrations::v15::check_pallet_tfgrid::(); +} diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 48c34cb2f..374e28c9d 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -772,9 +772,10 @@ pub type Executive = frame_executive::Executive< // `OnRuntimeUpgrade`. type Migrations = ( pallet_tfgrid::migrations::v16::KillNodeGpuStatus, - pallet_tfgrid::migrations::v15::CheckStorageState, + pallet_tfgrid::migrations::v16::CheckStorageState, pallet_smart_contract::migrations::v10::ReworkBillingLoopInsertion, pallet_smart_contract::migrations::v11::ExtendContractLock, + pallet_smart_contract::migrations::v11::CheckStorageState, migrations::remove_sudo::RemoveSudo, ); From b609e1751824e33a6fe40ef9aa95e9362d531d38 Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 17 Nov 2023 17:55:19 -0300 Subject: [PATCH 9/9] add pallet-tfgrid v17 check storage --- .../pallet-tfgrid/src/migrations/v17.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs index 7b21c5e62..789e8bc9f 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs @@ -9,6 +9,8 @@ use tfchain_support::types::{PublicIP, IP4}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; +#[cfg(feature = "try-runtime")] +use sp_std::vec; pub struct FixFarmPublicIps(PhantomData); @@ -121,3 +123,50 @@ fn public_ips_to_string(public_ips: BoundedVec>) -> Stri } s } + +pub struct CheckStorageState(PhantomData); + +impl OnRuntimeUpgrade for CheckStorageState { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + info!("current pallet version: {:?}", PalletVersion::::get()); + assert!(PalletVersion::::get() == types::StorageVersion::V17Struct); + + check_pallet_tfgrid::(); + + Ok(vec![]) + } +} + +pub fn check_pallet_tfgrid() { + migrations::v16::check_pallet_tfgrid::(); + check_farms_public_ips::(); +} + +// Check farms public ips +pub fn check_farms_public_ips() { + debug!( + "🔎 TFGrid pallet {:?} checking Farms storage map (public ips) START", + PalletVersion::::get() + ); + + for (farm_id, farm) in Farms::::iter() { + for pubip in farm.public_ips { + let ip4 = IP4 { + ip: pubip.ip.clone(), + gw: pubip.gateway.clone(), + }; + if ip4.is_valid().is_err() { + debug!( + " ⚠️ Farms[id: {}]: invalid public ip ({:?})", + farm_id, ip4 + ); + } + } + } + + debug!( + "🏁 TFGrid pallet {:?} checking Farms storage map (public ips) END", + PalletVersion::::get() + ); +}