Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
6 changes: 6 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,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::<Runtime>()
}

Executive::offchain_worker(header)
}
}
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_2290.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: im-online pallet offcain storage cleanup

doc:
- audience: Runtime Dev
description: |
This is a follow-up of #2265. It blindly removes all the offchain storage values added to
the database by now retired im-online pallet. In absence of such values, does nothing.

crates:
- name: pallet-im-online
- name: rococo-runtime
1 change: 1 addition & 0 deletions substrate/frame/im-online/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ frame-benchmarking = { path = "../benchmarking", default-features = false, optio
frame-support = { path = "../support", default-features = false }
frame-system = { path = "../system", default-features = false }
pallet-authorship = { path = "../authorship", default-features = false }
pallet-session = { path = "../session", default-features = false }
sp-application-crypto = { path = "../../primitives/application-crypto", default-features = false, features = ["serde"] }
sp-core = { path = "../../primitives/core", default-features = false, features = ["serde"] }
sp-io = { path = "../../primitives/io", default-features = false }
Expand Down
12 changes: 12 additions & 0 deletions substrate/frame/im-online/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ pub mod v1 {
}
}

pub fn clear_offchain_storage<T: pallet_session::Config>() {
let validator_set_size = pallet_session::Pallet::<T>::validators().len() as 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::*;
Expand Down