contracts: Move Schedule from Storage to Config (#8773)

* Move `Schedule` from Storage to Config

* Updated CHANGELOG

* Fix nits from review

* Fix migration

* Print the debug buffer as tracing message

* Use `debug` instead of `trace` and update README

* Add additional assert to test

* Rename `schedule_version` to `instruction_weights_version`

* Fixed typo

* Added more comments to wat fixtures

* Add clarification for the `debug_message` field
This commit is contained in:
Alexander Theißen
2021-05-13 21:56:11 +02:00
committed by GitHub
parent 3c0270fe57
commit 1ac95b6ba6
23 changed files with 1465 additions and 1056 deletions
+11 -12
View File
@@ -15,24 +15,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::{Config, Weight, CurrentSchedule, Pallet, Schedule};
use frame_support::traits::{GetPalletVersion, PalletVersion, Get};
use crate::{Config, Weight, Pallet};
use frame_support::{
storage::migration,
traits::{GetPalletVersion, PalletVersion, PalletInfoAccess, Get},
};
pub fn migrate<T: Config>() -> Weight {
let mut weight: Weight = 0;
match <Pallet<T>>::storage_version() {
// Replace the schedule with the new default and increment its version.
Some(version) if version == PalletVersion::new(3, 0, 0) => {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
let _ = <CurrentSchedule<T>>::translate::<u32, _>(|version| {
version.map(|version| Schedule {
version: version.saturating_add(1),
// Default limits were not decreased. Therefore it is OK to overwrite
// the schedule with the new defaults.
.. Default::default()
})
});
weight = weight.saturating_add(T::DbWeight::get().writes(1));
migration::remove_storage_prefix(
<Pallet<T>>::name().as_bytes(),
b"CurrentSchedule",
b"",
);
}
_ => (),
}