srml: consensus: kill storage (#2098)

* srml: consensus: kill storage items

* srml: consensus: add test for set and kill storage

* runtime: bump spec_version update wasm blobs
This commit is contained in:
André Silva
2019-03-25 23:39:23 +00:00
committed by GitHub
parent e2f5e40876
commit cee2166e4f
5 changed files with 35 additions and 2 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 43,
impl_version: 43,
spec_version: 44,
impl_version: 44,
apis: RUNTIME_API_VERSIONS,
};
+8
View File
@@ -51,6 +51,7 @@ impl<S: codec::Codec + Default> StorageVec for AuthorityStorageVec<S> {
const PREFIX: &'static [u8] = well_known_keys::AUTHORITY_PREFIX;
}
pub type Key = Vec<u8>;
pub type KeyValue = (Vec<u8>, Vec<u8>);
/// Handling offline validator reports in a generic way.
@@ -216,6 +217,13 @@ decl_module! {
}
}
/// Kill some items from storage.
fn kill_storage(keys: Vec<Key>) {
for key in &keys {
storage::unhashed::kill(&key);
}
}
fn on_finalise() {
if let Some(original_authorities) = <OriginalAuthorities<T>>::take() {
let current_authorities = AuthorityStorageVec::<T::SessionKey>::items();
+25
View File
@@ -83,3 +83,28 @@ fn offline_report_can_be_excluded() {
assert!(Consensus::create_inherent(&data).is_some());
});
}
#[test]
fn set_and_kill_storage_work() {
use srml_support::storage;
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
let item = (vec![42u8], vec![42u8]);
Consensus::set_storage(vec![item.clone()]).unwrap();
assert_eq!(
storage::unhashed::get_raw(&item.0),
Some(item.1),
);
Consensus::kill_storage(vec![item.0.clone()]).unwrap();
assert_eq!(
storage::unhashed::get_raw(&item.0),
None,
);
});
}