Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions srml/contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ fn instantiate_and_call_and_deposit_event() {
vec![],
);

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand Down Expand Up @@ -416,6 +417,7 @@ fn dispatch_call() {

// Let's keep this assert even though it's redundant. If you ever need to update the
// wasm source this test will fail and will show you the actual hash.
System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand Down Expand Up @@ -443,6 +445,7 @@ fn dispatch_call() {
vec![],
));

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand Down
4 changes: 4 additions & 0 deletions srml/council/src/motions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ mod tests {
assert_eq!(CouncilMotions::proposal_of(&hash), Some(proposal));
assert_eq!(CouncilMotions::voting(&hash), Some((0, 3, vec![1], Vec::<u64>::new())));

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand Down Expand Up @@ -284,6 +285,7 @@ mod tests {
assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, Vec::<u64>::new(), vec![1])));
assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false), "duplicate vote ignored");

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand All @@ -306,6 +308,7 @@ mod tests {
assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, false));

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand All @@ -332,6 +335,7 @@ mod tests {
assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone())));
assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, true));

System::flush_events();
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
Expand Down
28 changes: 25 additions & 3 deletions srml/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ decl_module! {
pub fn deposit_event(event: T::Event) {
let extrinsic_index = Self::extrinsic_index();
let phase = extrinsic_index.map_or(Phase::Finalization, |c| Phase::ApplyExtrinsic(c));
let mut events = Self::events();
events.push(EventRecord { phase, event });
<Events<T>>::put(events);

EventsCacheCount::<T>::mutate(|index| {
EventsCache::<T>::insert(*index, EventRecord { phase, event });
*index += 1;
});
}
}
}
Expand Down Expand Up @@ -306,6 +308,10 @@ decl_storage! {
Digest get(digest): T::Digest;
/// Events deposited for the current block.
Events get(events): Vec<EventRecord<T::Event>>;
/// Events map cache for the current block. related to issue 2223 https://github.com/paritytech/substrate/issues/2223
EventsCache: map u32 => Option<EventRecord<T::Event>>;
/// Events map cache index
EventsCacheCount: u32 = 0;
}
add_extra_genesis {
config(changes_trie_config): Option<ChangesTrieConfiguration>;
Expand Down Expand Up @@ -389,6 +395,8 @@ impl<T: Trait> Module<T> {
<ExtrinsicsRoot<T>>::put(txs_root);
<RandomSeed<T>>::put(Self::calculate_random());
<Events<T>>::kill();

<EventsCacheCount<T>>::kill();
}

/// Remove temporary "environment" entries in storage.
Expand All @@ -413,10 +421,24 @@ impl<T: Trait> Module<T> {
}

// <Events<T>> stays to be inspected by the client.
// flush all event cache into `Events`, related to issue 2223 https://github.com/paritytech/substrate/issues/2223
Self::flush_events();

<T::Header as traits::Header>::new(number, extrinsics_root, storage_root, parent_hash, digest)
}

pub fn flush_events() {
let mut events = Self::events();
for i in 0..EventsCacheCount::<T>::get() {
if let Some(e) = EventsCache::<T>::get(i) {
events.push(e);
}
EventsCache::<T>::remove(i);
}
EventsCacheCount::<T>::kill();
<Events<T>>::put(events);
}

/// Deposits a log and ensures it matches the blocks log data.
pub fn deposit_log(item: <T::Digest as traits::Digest>::Item) {
let mut l = <Digest<T>>::get();
Expand Down