Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit ae46db6

Browse files
shawntabrizibkchr
authored andcommitted
Use single map and remove_all for EventTopics (#4566)
1 parent ff509da commit ae46db6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

frame/system/src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -405,18 +405,14 @@ decl_storage! {
405405
/// Mapping between a topic (represented by T::Hash) and a vector of indexes
406406
/// of events in the `<Events<T>>` list.
407407
///
408-
/// The first key serves no purpose. This field is declared as double_map just
409-
/// for convenience of using `remove_prefix`.
410-
///
411408
/// All topic vectors have deterministic storage locations depending on the topic. This
412409
/// allows light-clients to leverage the changes trie storage tracking mechanism and
413410
/// in case of changes fetch the list of events of interest.
414411
///
415412
/// The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
416413
/// the `EventIndex` then in case if the topic has the same contents on the next block
417414
/// no notification will be triggered thus the event might be lost.
418-
EventTopics get(fn event_topics): double_map hasher(blake2_256) (), blake2_256(T::Hash)
419-
=> Vec<(T::BlockNumber, EventIndex)>;
415+
EventTopics get(fn event_topics): map T::Hash => Vec<(T::BlockNumber, EventIndex)>;
420416
}
421417
add_extra_genesis {
422418
config(changes_trie_config): Option<ChangesTrieConfiguration>;
@@ -583,7 +579,7 @@ impl<T: Trait> Module<T> {
583579
let block_no = Self::block_number();
584580
for topic in topics {
585581
// The same applies here.
586-
if <EventTopics<T>>::append(&(), topic, &[(block_no, event_idx)]).is_err() {
582+
if <EventTopics<T>>::append(topic, &[(block_no, event_idx)]).is_err() {
587583
return;
588584
}
589585
}
@@ -647,7 +643,7 @@ impl<T: Trait> Module<T> {
647643
<ExtrinsicsRoot<T>>::put(txs_root);
648644
<Events<T>>::kill();
649645
EventCount::kill();
650-
<EventTopics<T>>::remove_prefix(&());
646+
<EventTopics<T>>::remove_all();
651647
}
652648

653649
/// Remove temporary "environment" entries in storage.
@@ -1302,15 +1298,15 @@ mod tests {
13021298
// Check that the topic-events mapping reflects the deposited topics.
13031299
// Note that these are indexes of the events.
13041300
assert_eq!(
1305-
System::event_topics(&(), &topics[0]),
1301+
System::event_topics(&topics[0]),
13061302
vec![(BLOCK_NUMBER, 0), (BLOCK_NUMBER, 1)],
13071303
);
13081304
assert_eq!(
1309-
System::event_topics(&(), &topics[1]),
1305+
System::event_topics(&topics[1]),
13101306
vec![(BLOCK_NUMBER, 0), (BLOCK_NUMBER, 2)],
13111307
);
13121308
assert_eq!(
1313-
System::event_topics(&(), &topics[2]),
1309+
System::event_topics(&topics[2]),
13141310
vec![(BLOCK_NUMBER, 0)],
13151311
);
13161312
});

0 commit comments

Comments
 (0)