Make System Events Private from the Runtime (#9619)

* make events private

* "i know what i am doing"

* feedback
This commit is contained in:
Shawn Tabrizi
2021-08-26 09:55:41 -04:00
committed by GitHub
parent 77489c3107
commit 2c91f3a464
2 changed files with 26 additions and 3 deletions
+23 -2
View File
@@ -612,9 +612,12 @@ pub mod pallet {
pub(super) type Digest<T: Config> = StorageValue<_, DigestOf<T>, ValueQuery>;
/// Events deposited for the current block.
///
/// NOTE: This storage item is explicitly unbounded since it is never intended to be read
/// from within the runtime.
#[pallet::storage]
#[pallet::getter(fn events)]
pub type Events<T: Config> = StorageValue<_, Vec<EventRecord<T::Event, T::Hash>>, ValueQuery>;
pub(super) type Events<T: Config> =
StorageValue<_, Vec<EventRecord<T::Event, T::Hash>>, ValueQuery>;
/// The number of events in the `Events<T>` list.
#[pallet::storage]
@@ -1448,6 +1451,24 @@ impl<T: Config> Pallet<T> {
})
}
/// Get the current events deposited by the runtime.
///
/// NOTE: This should only be used in tests. Reading events from the runtime can have a large
/// impact on the PoV size of a block. Users should use alternative and well bounded storage
/// items for any behavior like this.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn events() -> Vec<EventRecord<T::Event, T::Hash>> {
Self::read_events_no_consensus()
}
/// Get the current events deposited by the runtime.
///
/// Should only be called if you know what you are doing and outside of the runtime block
/// execution else it can have a large impact on the PoV size of a block.
pub fn read_events_no_consensus() -> Vec<EventRecord<T::Event, T::Hash>> {
Events::<T>::get()
}
/// Set the block number to something in particular. Can be used as an alternative to
/// `initialize` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]