Skip to content

Commit 89fee08

Browse files
author
timorl
committed
Merge branch 'main' into A0-1576-shelob
2 parents 302f1d5 + f8f541d commit 89fee08

File tree

7 files changed

+105
-138
lines changed

7 files changed

+105
-138
lines changed

docker/docker_entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ TELEMETRY_URL=${TELEMETRY_URL:-'wss://telemetry.polkadot.io/submit/'}
3131
TELEMETRY_VERBOSITY_LVL=${TELEMETRY_VERBOSITY_LVL:-'0'}
3232
UNIT_CREATION_DELAY=${UNIT_CREATION_DELAY:-300}
3333
DB_CACHE=${DB_CACHE:-1024}
34+
RUNTIME_CACHE_SIZE=${RUNTIME_CACHE_SIZE:-2}
3435
BACKUP_PATH=${BACKUP_PATH:-${BASE_PATH}/backup-stash}
3536

3637
if [[ "true" == "$PURGE_BEFORE_START" ]]; then
@@ -58,6 +59,7 @@ ARGS=(
5859
--unsafe-ws-external --unsafe-rpc-external
5960
--enable-log-reloading
6061
--db-cache "${DB_CACHE}"
62+
--runtime-cache-size "${RUNTIME_CACHE_SIZE}"
6163
)
6264

6365
if [[ -n "${BOOT_NODES:-}" ]]; then

pallets/aleph/src/migrations/v0_to_v1.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
#[cfg(feature = "try-runtime")]
2-
use frame_support::ensure;
31
use frame_support::{
42
log, storage_alias,
53
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
64
weights::Weight,
75
};
8-
#[cfg(feature = "try-runtime")]
9-
use pallets_support::ensure_storage_version;
10-
use pallets_support::StorageMigration;
116
use primitives::SessionIndex;
127
use sp_std::vec::Vec;
8+
#[cfg(feature = "try-runtime")]
9+
use {
10+
codec::{Decode, Encode},
11+
frame_support::ensure,
12+
pallets_support::ensure_storage_version,
13+
};
1314

1415
use crate::Config;
1516

@@ -24,9 +25,11 @@ type Validators<T> = StorageValue<Aleph, Accounts<T>>;
2425
/// Flattening double `Option<>` storage.
2526
pub struct Migration<T, P>(sp_std::marker::PhantomData<(T, P)>);
2627

27-
impl<T: Config, P: PalletInfoAccess> StorageMigration for Migration<T, P> {
28-
#[cfg(feature = "try-runtime")]
29-
const MIGRATION_STORAGE_PREFIX: &'static [u8] = b"PALLET_ALEPH::V0_TO_V1_MIGRATION";
28+
#[cfg(feature = "try-runtime")]
29+
#[derive(Decode, Encode)]
30+
struct MigrationChecksState<T: Config> {
31+
session: Option<Option<SessionIndex>>,
32+
validators: Option<Option<Accounts<T>>>,
3033
}
3134

3235
impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
@@ -87,39 +90,50 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
8790

8891
ensure_storage_version::<P>(0)?;
8992

90-
Self::store_temp("session", SessionForValidatorsChange::get());
91-
Self::store_temp("validators", Validators::<T>::get());
93+
let session = SessionForValidatorsChange::get();
94+
let validators = Validators::<T>::get();
9295

93-
Ok(Vec::new())
96+
Ok(MigrationChecksState::<T> {
97+
session,
98+
validators,
99+
}
100+
.encode())
94101
}
95102

96103
#[cfg(feature = "try-runtime")]
97-
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
104+
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
98105
ensure_storage_version::<P>(1)?;
99106

107+
let MigrationChecksState {
108+
session: old_session,
109+
validators: old_validators,
110+
} = <MigrationChecksState<T>>::decode(&mut &*state)
111+
.map_err(|_| "Failed to decode old state")?;
112+
100113
let new_session = SessionForValidatorsChange::get();
101-
let old_session = Self::read_temp::<Option<Option<SessionIndex>>>("session");
102114

103115
match old_session {
104116
Some(Some(session)) => ensure!(
105117
Some(session) == new_session,
106118
"Mismatch on `SessionForValidatorsChange`",
107119
),
108120
_ => ensure!(
109-
None == new_session,
121+
new_session.is_none(),
110122
"New `SessionForValidatorsChange` should be `None`"
111123
),
112124
};
113125

114126
let new_validators = Validators::<T>::get();
115-
let old_validators = Self::read_temp::<Option<Option<Accounts<T>>>>("validators");
116127

117128
match old_validators {
118129
Some(Some(validators)) => ensure!(
119130
Some(validators) == new_validators,
120131
"Mismatch on `Validators`",
121132
),
122-
_ => ensure!(None == new_validators, "New `Validators` should be `None`"),
133+
_ => ensure!(
134+
new_validators.is_none(),
135+
"New `Validators` should be `None`"
136+
),
123137
};
124138

125139
Ok(())

pallets/aleph/src/migrations/v1_to_v2.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
#[cfg(feature = "try-runtime")]
2-
use frame_support::ensure;
31
use frame_support::{
42
log, storage_alias,
53
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
64
weights::Weight,
75
};
86
#[cfg(feature = "try-runtime")]
9-
use pallets_support::ensure_storage_version;
10-
use pallets_support::StorageMigration;
11-
#[cfg(feature = "try-runtime")]
12-
use sp_std::vec::Vec;
7+
use {frame_support::ensure, pallets_support::ensure_storage_version, sp_std::vec::Vec};
138

149
use crate::Config;
1510

@@ -32,11 +27,6 @@ type Validators = StorageValue<Aleph, ()>;
3227
/// - Validators
3328
pub struct Migration<T, P>(sp_std::marker::PhantomData<(T, P)>);
3429

35-
impl<T: Config, P: PalletInfoAccess> StorageMigration for Migration<T, P> {
36-
#[cfg(feature = "try-runtime")]
37-
const MIGRATION_STORAGE_PREFIX: &'static [u8] = b"PALLET_ALEPH::V1_TO_V2_MIGRATION";
38-
}
39-
4030
impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
4131
fn on_runtime_upgrade() -> Weight {
4232
let mut writes = 0;

pallets/elections/src/migrations/v0_to_v1.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#[cfg(feature = "try-runtime")]
2-
use frame_support::ensure;
31
use frame_support::{
42
log, storage_alias,
53
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
64
weights::Weight,
75
};
8-
#[cfg(feature = "try-runtime")]
9-
use pallets_support::ensure_storage_version;
10-
use pallets_support::StorageMigration;
116
use sp_std::vec::Vec;
7+
#[cfg(feature = "try-runtime")]
8+
use {
9+
codec::{Decode, Encode},
10+
frame_support::ensure,
11+
pallets_support::ensure_storage_version,
12+
};
1213

1314
use crate::{
1415
compute_validator_scaled_total_rewards,
@@ -39,11 +40,6 @@ type ErasMembers<T> = StorageValue<Elections, (Validators<T>, Validators<T>)>;
3940
/// - `ErasMembers` contain tuple of (content of `Members`, empty vector).
4041
pub struct Migration<T, P>(sp_std::marker::PhantomData<(T, P)>);
4142

42-
impl<T: Config, P: PalletInfoAccess> StorageMigration for Migration<T, P> {
43-
#[cfg(feature = "try-runtime")]
44-
const MIGRATION_STORAGE_PREFIX: &'static [u8] = b"PALLET_ELECTIONS::V0_TO_V1_MIGRATION";
45-
}
46-
4743
impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
4844
fn on_runtime_upgrade() -> Weight {
4945
log::info!(target: "pallet_elections", "Running migration from STORAGE_VERSION 0 to 1 for pallet elections");
@@ -85,15 +81,12 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
8581
#[cfg(feature = "try-runtime")]
8682
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
8783
ensure_storage_version::<P>(0)?;
88-
89-
let members = Members::<T>::get().ok_or("No `Members` storage")?;
90-
Self::store_temp("members", members);
91-
92-
Ok(Vec::new())
84+
let members: Validators<T> = Members::<T>::get().ok_or("No `Members` storage")?;
85+
Ok(members.encode())
9386
}
9487

9588
#[cfg(feature = "try-runtime")]
96-
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
89+
fn post_upgrade(old_members: Vec<u8>) -> Result<(), &'static str> {
9790
ensure_storage_version::<P>(1)?;
9891

9992
let mps = MembersPerSession::get().ok_or("No `MembersPerSession` in the storage")?;
@@ -103,7 +96,8 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
10396
NonReservedMembers::<T>::get().ok_or("No `NonReservedMembers` in the storage")?;
10497
let eras_members = ErasMembers::<T>::get().ok_or("No `ErasMembers` in the storage")?;
10598

106-
let old_members = Self::read_temp::<Validators<T>>("members");
99+
let old_members = <Validators<T>>::decode(&mut &*old_members)
100+
.map_err(|_| "Failed to decode old members set")?;
107101

108102
ensure!(
109103
reserved_members == old_members,

pallets/elections/src/migrations/v1_to_v2.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#[cfg(feature = "try-runtime")]
2-
use frame_support::ensure;
31
use frame_support::{
42
log, storage_alias,
53
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
64
weights::Weight,
75
};
86
#[cfg(feature = "try-runtime")]
9-
use pallets_support::ensure_storage_version;
10-
use pallets_support::StorageMigration;
11-
#[cfg(feature = "try-runtime")]
12-
use sp_std::vec::Vec;
7+
use {
8+
codec::{Decode, Encode},
9+
frame_support::ensure,
10+
pallets_support::ensure_storage_version,
11+
sp_std::vec::Vec,
12+
};
1313

1414
use crate::{migrations::Validators, Config, EraValidators};
1515

@@ -42,9 +42,13 @@ type CurrentEraValidators<T> =
4242
/// - `ErasMembers` `(reserved, non_reserved)` -> `CurrentEraValidators` `ErasValidators { reserved, non_reserved}`
4343
pub struct Migration<T, P>(sp_std::marker::PhantomData<(T, P)>);
4444

45-
impl<T: Config, P: PalletInfoAccess> StorageMigration for Migration<T, P> {
46-
#[cfg(feature = "try-runtime")]
47-
const MIGRATION_STORAGE_PREFIX: &'static [u8] = b"PALLET_ELECTIONS::V1_TO_V2_MIGRATION";
45+
#[cfg(feature = "try-runtime")]
46+
#[derive(Decode, Encode)]
47+
struct MigrationChecksState<T: Config> {
48+
members_per_session: u32,
49+
reserved_members: Validators<T>,
50+
non_reserved_members: Validators<T>,
51+
eras_members: (Validators<T>, Validators<T>),
4852
}
4953

5054
impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
@@ -89,24 +93,23 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
8993

9094
let members_per_session =
9195
MembersPerSession::get().ok_or("No `MembersPerSession` in the storage")?;
92-
Self::store_temp("members_per_session", members_per_session);
93-
9496
let reserved_members =
9597
ReservedMembers::<T>::get().ok_or("No `ReservedMembers` in the storage")?;
96-
Self::store_temp("reserved_members", reserved_members);
97-
9898
let non_reserved_members =
9999
NonReservedMembers::<T>::get().ok_or("No `NonReservedMembers` in the storage")?;
100-
Self::store_temp("non_reserved_members", non_reserved_members);
101-
102100
let eras_members = ErasMembers::<T>::get().ok_or("No `ErasMembers` in the storage")?;
103-
Self::store_temp("eras_members", eras_members);
104101

105-
Ok(Vec::new())
102+
Ok(MigrationChecksState::<T> {
103+
members_per_session,
104+
reserved_members,
105+
non_reserved_members,
106+
eras_members,
107+
}
108+
.encode())
106109
}
107110

108111
#[cfg(feature = "try-runtime")]
109-
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
112+
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
110113
ensure_storage_version::<P>(2)?;
111114

112115
let committee_size = CommitteeSize::get().ok_or("No `CommitteeSize` in the storage")?;
@@ -117,10 +120,13 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
117120
let current_era_validators =
118121
CurrentEraValidators::<T>::get().ok_or("No `CurrentEraValidators` in the storage")?;
119122

120-
let members_per_session = Self::read_temp::<u32>("members_per_session");
121-
let reserved_members = Self::read_temp::<Validators<T>>("reserved_members");
122-
let non_reserved_members = Self::read_temp::<Validators<T>>("non_reserved_members");
123-
let eras_members = Self::read_temp::<(Validators<T>, Validators<T>)>("eras_members");
123+
let MigrationChecksState {
124+
members_per_session,
125+
reserved_members,
126+
non_reserved_members,
127+
eras_members,
128+
} = <MigrationChecksState<T>>::decode(&mut &*state)
129+
.map_err(|_| "Failed to decode old state")?;
124130

125131
ensure!(
126132
committee_size == members_per_session,

pallets/elections/src/migrations/v2_to_v3.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#[cfg(feature = "try-runtime")]
2-
use frame_support::ensure;
31
use frame_support::{
42
log, storage_alias,
53
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
64
weights::Weight,
75
};
8-
#[cfg(feature = "try-runtime")]
9-
use pallets_support::ensure_storage_version;
10-
use pallets_support::StorageMigration;
116
use primitives::CommitteeSeats;
127
#[cfg(feature = "try-runtime")]
13-
use sp_std::vec::Vec;
8+
use {
9+
codec::{Decode, Encode},
10+
frame_support::ensure,
11+
pallets_support::ensure_storage_version,
12+
sp_std::vec::Vec,
13+
};
1414

1515
use crate::{migrations::Validators, Config, EraValidators};
1616

@@ -31,9 +31,11 @@ type NextEraCommitteeSize = StorageValue<Elections, CommitteeSeats>;
3131
/// `CommitteeSeats`.
3232
pub struct Migration<T, P>(sp_std::marker::PhantomData<(T, P)>);
3333

34-
impl<T: Config, P: PalletInfoAccess> StorageMigration for Migration<T, P> {
35-
#[cfg(feature = "try-runtime")]
36-
const MIGRATION_STORAGE_PREFIX: &'static [u8] = b"PALLET_ELECTIONS::V2_TO_V3_MIGRATION";
34+
#[cfg(feature = "try-runtime")]
35+
#[derive(Decode, Encode)]
36+
struct MigrationChecksState {
37+
committee_size: Option<u32>,
38+
next_era_committee_size: Option<u32>,
3739
}
3840

3941
impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
@@ -108,16 +110,17 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
108110
ensure_storage_version::<P>(2)?;
109111

110112
let committee_size = CommitteeSize::get();
111-
Self::store_temp("committee_size", committee_size);
112-
113113
let next_era_committee_size = NextEraCommitteeSize::get();
114-
Self::store_temp("next_era_committee_size", next_era_committee_size);
115114

116-
Ok(Vec::new())
115+
Ok(MigrationChecksState {
116+
committee_size,
117+
next_era_committee_size,
118+
}
119+
.encode())
117120
}
118121

119122
#[cfg(feature = "try-runtime")]
120-
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
123+
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
121124
ensure_storage_version::<P>(3)?;
122125

123126
let new_committee_size = CommitteeSize::get().ok_or("No `CommitteeSize` in the storage")?;
@@ -129,10 +132,11 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
129132
let next_era_reserved_validators = NextEraReservedValidators::<T>::get()
130133
.ok_or("No `NextEraReservedValidators` in the storage")?;
131134

132-
let old_committee_size =
133-
Self::read_temp::<Option<u32>>("committee_size").unwrap_or_default();
134-
let old_next_era_committee_size =
135-
Self::read_temp::<Option<u32>>("next_era_committee_size").unwrap_or_default();
135+
let MigrationChecksState {
136+
committee_size: old_committee_size,
137+
next_era_committee_size: old_next_era_committee_size,
138+
} = <MigrationChecksState>::decode(&mut &*state)
139+
.map_err(|_| "Failed to decode old state")?;
136140

137141
let currently_reserved = current_era_validators.reserved.len();
138142
ensure!(
@@ -141,7 +145,9 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
141145
);
142146
ensure!(
143147
new_committee_size.non_reserved_seats
144-
== old_committee_size.saturating_sub(currently_reserved as u32),
148+
== old_committee_size
149+
.unwrap_or_default()
150+
.saturating_sub(currently_reserved as u32),
145151
"Mismatch between `CurrentEraValidators` and `CommitteeSize`"
146152
);
147153

@@ -152,7 +158,9 @@ impl<T: Config, P: PalletInfoAccess> OnRuntimeUpgrade for Migration<T, P> {
152158
);
153159
ensure!(
154160
new_next_era_committee_size.non_reserved_seats
155-
== old_next_era_committee_size.saturating_sub(next_reserved as u32),
161+
== old_next_era_committee_size
162+
.unwrap_or_default()
163+
.saturating_sub(next_reserved as u32),
156164
"Mismatch between `NextEraReservedValidators` and `NextEraCommitteeSize`"
157165
);
158166

0 commit comments

Comments
 (0)