diff --git a/substrate/frame/election-provider-multi-phase/src/lib.rs b/substrate/frame/election-provider-multi-phase/src/lib.rs index 4aef03a343..96f54c4c03 100644 --- a/substrate/frame/election-provider-multi-phase/src/lib.rs +++ b/substrate/frame/election-provider-multi-phase/src/lib.rs @@ -1236,7 +1236,9 @@ impl Pallet { } // After election finalization, clear OCW solution storage. - if >::events() + // + // We can read the events here because offchain worker doesn't affect PoV. + if >::read_events_no_consensus() .into_iter() .filter_map(|event_record| { let local_event = ::Event::from(event_record.event); diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index a8bf253c39..7b6ec9856d 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -612,9 +612,12 @@ pub mod pallet { pub(super) type Digest = StorageValue<_, DigestOf, 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 = StorageValue<_, Vec>, ValueQuery>; + pub(super) type Events = + StorageValue<_, Vec>, ValueQuery>; /// The number of events in the `Events` list. #[pallet::storage] @@ -1448,6 +1451,24 @@ impl Pallet { }) } + /// 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> { + 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> { + Events::::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))]