Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,21 +1618,21 @@ impl<T: Config> Pallet<T> {
.ok_or(Error::<T>::FailedToExtractRuntimeVersion)?;

cfg_if::cfg_if! {
if #[cfg(all(feature = "runtime-benchmarks", not(test)))] {
if #[cfg(all(feature = "runtime-benchmarks", not(test)))] {
// Let's ensure the compiler doesn't optimize our fetching of the runtime version away.
core::hint::black_box((new_version, current_version));
Ok(())
} else {
if new_version.spec_name != current_version.spec_name {
return Err(Error::<T>::InvalidSpecName.into())
}
} else {
if new_version.spec_name != current_version.spec_name {
return Err(Error::<T>::InvalidSpecName.into())
}

if new_version.spec_version <= current_version.spec_version {
return Err(Error::<T>::SpecVersionNeedsToIncrease.into())
}
if new_version.spec_version <= current_version.spec_version {
return Err(Error::<T>::SpecVersionNeedsToIncrease.into())
}

Ok(())
}
Ok(())
}
}
}
}
Expand All @@ -1643,7 +1643,7 @@ pub fn unique(entropy: impl Encode) -> [u8; 32] {
let mut last = [0u8; 32];
sp_io::storage::read(well_known_keys::INTRABLOCK_ENTROPY, &mut last[..], 0);
let next = (b"frame_system::unique", entropy, last).using_encoded(blake2_256);
sp_io::storage::set(well_known_keys::INTRABLOCK_ENTROPY, &next.encode());
sp_io::storage::set(well_known_keys::INTRABLOCK_ENTROPY, &next);
next
}

Expand Down
4 changes: 4 additions & 0 deletions frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ fn unique_datum_works() {
assert!(sp_io::storage::exists(well_known_keys::INTRABLOCK_ENTROPY));

let h1 = unique(b"");
assert_eq!(32, sp_io::storage::read(well_known_keys::INTRABLOCK_ENTROPY, &mut [], 0).unwrap());
let h2 = unique(b"");
assert_eq!(32, sp_io::storage::read(well_known_keys::INTRABLOCK_ENTROPY, &mut [], 0).unwrap());
assert_ne!(h1, h2);

let h3 = unique(b"Hello");
assert_eq!(32, sp_io::storage::read(well_known_keys::INTRABLOCK_ENTROPY, &mut [], 0).unwrap());
assert_ne!(h2, h3);

let h4 = unique(b"Hello");
assert_eq!(32, sp_io::storage::read(well_known_keys::INTRABLOCK_ENTROPY, &mut [], 0).unwrap());
assert_ne!(h3, h4);

System::finalize();
Expand Down