Skip to content

Commit 7948a53

Browse files
chore: intermediate release for dev/qa (specVersion: 109) #432
1 parent 55b682f commit 7948a53

File tree

5 files changed

+90
-6
lines changed

5 files changed

+90
-6
lines changed

substrate-node/pallets/pallet-tfgrid/src/grid_migration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub mod deprecated {
8989
}
9090
}
9191

92-
pub mod v7 {
92+
pub mod v9 {
9393
use super::*;
9494
use crate::Config;
9595

@@ -112,7 +112,7 @@ pub mod v7 {
112112

113113
#[cfg(feature = "try-runtime")]
114114
fn post_upgrade() -> Result<(), &'static str> {
115-
assert!(PalletVersion::<T>::get() == types::StorageVersion::V8Struct);
115+
assert!(PalletVersion::<T>::get() == types::StorageVersion::V9Struct);
116116

117117
info!(
118118
"👥 TFGrid pallet migration to {:?} passes POST migrate checks ✅",
@@ -297,7 +297,7 @@ pub fn migrate_farms<T: Config>() -> frame_support::weights::Weight {
297297
);
298298

299299
// Update pallet storage version
300-
PalletVersion::<T>::set(types::StorageVersion::V8Struct);
300+
PalletVersion::<T>::set(types::StorageVersion::V9Struct);
301301
info!(" <<< Storage version upgraded");
302302

303303
// Return the weight consumed by the migration.

substrate-node/pallets/pallet-tfgrid/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod types;
3434
pub mod farm;
3535
pub mod grid_migration;
3636
pub mod interface;
37+
pub mod nodes_migration_v3;
3738
pub mod pub_config;
3839
pub mod pub_ip;
3940
pub mod twin;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use super::Config;
2+
use super::*;
3+
use frame_support::{traits::Get, weights::Weight};
4+
use log::info;
5+
use sp_std::collections::btree_map::BTreeMap;
6+
7+
pub mod v9patch {
8+
use super::*;
9+
use crate::Config;
10+
11+
use frame_support::{pallet_prelude::Weight, traits::OnRuntimeUpgrade};
12+
use sp_std::marker::PhantomData;
13+
pub struct FixFarmNodeIndexMap<T: Config>(PhantomData<T>);
14+
15+
impl<T: Config> OnRuntimeUpgrade for FixFarmNodeIndexMap<T> {
16+
#[cfg(feature = "try-runtime")]
17+
fn pre_upgrade() -> Result<(), &'static str> {
18+
assert!(PalletVersion::<T>::get() == types::StorageVersion::V8Struct);
19+
20+
info!("👥 TFGrid pallet to v4 passes PRE migrate checks ✅",);
21+
Ok(())
22+
}
23+
24+
fn on_runtime_upgrade() -> Weight {
25+
if PalletVersion::<T>::get() == types::StorageVersion::V8Struct {
26+
add_farm_nodes_index::<T>()
27+
} else {
28+
info!(" >>> Unused migration");
29+
return 0;
30+
}
31+
}
32+
33+
#[cfg(feature = "try-runtime")]
34+
fn post_upgrade() -> Result<(), &'static str> {
35+
assert!(PalletVersion::<T>::get() == types::StorageVersion::V9Struct);
36+
37+
info!(
38+
"👥 TFGrid pallet migration to {:?} passes POST migrate checks ✅",
39+
Pallet::<T>::pallet_version()
40+
);
41+
42+
Ok(())
43+
}
44+
}
45+
}
46+
47+
pub fn add_farm_nodes_index<T: Config>() -> frame_support::weights::Weight {
48+
info!(" >>> Migrating nodes storage...");
49+
50+
NodesByFarmID::<T>::remove_all(None);
51+
52+
let mut reads = 0;
53+
let mut writes = 0;
54+
55+
let mut farms_with_nodes: BTreeMap<u32, Vec<u32>> = BTreeMap::new();
56+
for (_, node) in Nodes::<T>::iter() {
57+
// Add index of farm - list (nodes)
58+
farms_with_nodes
59+
.entry(node.farm_id)
60+
.or_insert(vec![])
61+
.push(node.id);
62+
63+
reads += 1;
64+
}
65+
66+
for (farm_id, nodes) in farms_with_nodes.iter() {
67+
info!(
68+
"inserting nodes: {:?} with farm id: {:?}",
69+
nodes.clone(),
70+
farm_id
71+
);
72+
NodesByFarmID::<T>::insert(farm_id, nodes);
73+
writes += 1;
74+
}
75+
76+
// Update pallet storage version
77+
PalletVersion::<T>::set(types::StorageVersion::V9Struct);
78+
info!(" <<< Storage version upgraded");
79+
80+
// Return the weight consumed by the migration.
81+
T::DbWeight::get().reads_writes(reads as Weight + 1, writes as Weight + 1)
82+
}

substrate-node/pallets/pallet-tfgrid/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum StorageVersion {
1515
V6Struct,
1616
V7Struct,
1717
V8Struct,
18+
V9Struct,
1819
}
1920

2021
impl Default for StorageVersion {

substrate-node/runtime/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
140140
spec_name: create_runtime_str!("substrate-threefold"),
141141
impl_name: create_runtime_str!("substrate-threefold"),
142142
authoring_version: 1,
143-
spec_version: 109,
143+
spec_version: 110,
144144
impl_version: 1,
145145
apis: RUNTIME_API_VERSIONS,
146146
transaction_version: 2,
@@ -757,9 +757,9 @@ pub type Executive = frame_executive::Executive<
757757
Runtime,
758758
AllPalletsWithSystem,
759759
(
760-
migrations::CustomOnRuntimeUpgrades,
761760
pallet_smart_contract::contract_migration::v5::ContractMigrationV5<Runtime>,
762-
pallet_tfgrid::grid_migration::v7::GridMigration<Runtime>,
761+
pallet_tfgrid::grid_migration::v9::GridMigration<Runtime>,
762+
pallet_tfgrid::nodes_migration_v3::v9patch::FixFarmNodeIndexMap<Runtime>,
763763
),
764764
>;
765765

0 commit comments

Comments
 (0)