Skip to content

Commit

Permalink
Call local_storage_set only in offline context
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Aug 13, 2024
1 parent 6b17188 commit 9fab84a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion substrate/frame/merkle-mountain-range/src/mmr/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl OffchainStorage {

#[cfg(feature = "runtime-benchmarks")]
fn set(key: &[u8], value: &[u8]) {
sp_io::offchain::local_storage_set(StorageKind::PERSISTENT, key, value);
if sp_io::offchain::is_offchain_db_ext_available() {
sp_io::offchain::local_storage_set(StorageKind::PERSISTENT, key, value);
} else {
sp_io::offchain_index::set(key, value);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions substrate/primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,11 @@ sp_externalities::decl_extension! {
/// These functions are being made available to the runtime and are called by the runtime.
#[runtime_interface]
pub trait Offchain {
/// Checks if the offchain database extension is available.
fn is_offchain_db_ext_available(&mut self) -> bool {
self.extension::<OffchainDbExt>().is_some()
}

/// Returns if the local node is a potential validator.
///
/// Even if this function returns `true`, it does not mean that any keys are configured
Expand Down

0 comments on commit 9fab84a

Please sign in to comment.