We have specifically removed access to the Events
storage item in frame_system
because it could cause the user to read a huge amount of storage, and the events storage is only meant to be read offline.
/// 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()
}
You can see in the code this function is disabled unless you are running tests or benchmarks.
Some more context can be found in this PR: https://github.com/paritytech/substrate/pull/9619
Instead, we provide an "explicitly named" function called read_events_no_consensus
, which bypasses this protection from the user, and hopes that the user understands what they are doing.
/// 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()
}
This can be helpful for scenarios like an offchain worker reading into the events, which would be okay since this would not appear as a storage read in the PoV for a parachain.