mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
im-online removal cleanup: remove off-chain storage (#2290)
This is a follow-up for `im-online` pallet removal that is cleaning up its off-chain storage. Must be merged no earlier than #2265 is enacted. Related: #1964 --------- Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -1824,6 +1824,12 @@ sp_api::impl_runtime_apis! {
|
||||
|
||||
impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
use sp_runtime::{traits::Header, DigestItem};
|
||||
|
||||
if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) {
|
||||
pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32);
|
||||
}
|
||||
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1794,6 +1794,12 @@ sp_api::impl_runtime_apis! {
|
||||
|
||||
impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
use sp_runtime::{traits::Header, DigestItem};
|
||||
|
||||
if header.digest().logs().iter().any(|di| di == &DigestItem::RuntimeEnvironmentUpdated) {
|
||||
pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32);
|
||||
}
|
||||
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
title: im-online pallet offcain storage cleanup
|
||||
|
||||
doc:
|
||||
- audience: Runtime Dev
|
||||
description: |
|
||||
Adds a function `clear_offchain_storage` to `pallet-im-online`. This function can be used
|
||||
after the pallet was removed to clear its offchain storage.
|
||||
|
||||
crates:
|
||||
- name: pallet-im-online
|
||||
@@ -116,6 +116,21 @@ pub mod v1 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the pallet's offchain storage.
|
||||
///
|
||||
/// Must be put in `OffchainWorkerApi::offchain_worker` after
|
||||
/// the pallet was removed.
|
||||
pub fn clear_offchain_storage(validator_set_size: u32) {
|
||||
(0..validator_set_size).for_each(|idx| {
|
||||
let key = {
|
||||
let mut key = DB_PREFIX.to_vec();
|
||||
key.extend(idx.encode());
|
||||
key
|
||||
};
|
||||
sp_runtime::offchain::storage::StorageValueRef::persistent(&key).clear();
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "try-runtime", test))]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user