Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

im-online removal cleanup: remove off-chain storage #2290

Merged
merged 17 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -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) {
ordian marked this conversation as resolved.
Show resolved Hide resolved
pallet_im_online::migration::clear_offchain_storage(Session::validators().len() as u32);
}

Executive::offchain_worker(header)
}
}
Expand Down
6 changes: 6 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_2290.prdoc
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 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,19 @@ pub mod v1 {
}
}

/// Clears the pallet's offchain storage. Should be used in `OffchainWorkerApi`
/// implementation in runtime after the pallet was removed.
bkchr marked this conversation as resolved.
Show resolved Hide resolved
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::*;
Expand Down
Loading