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

Fix WASM block producer panic #11206

Merged
merged 7 commits into from
Apr 13, 2022
Merged
Changes from 5 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
17 changes: 11 additions & 6 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,14 @@ pub mod pallet {

/// 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.
/// NOTE: The item is unbound and should therefore never be read from storage.
/// It could otherwise inflate the PoV size of a block.
///
/// Events have a large in-memory size. Box the events to not go out-of-memory
/// just in case someone still reads them from within the runtime.
#[pallet::storage]
pub(super) type Events<T: Config> =
StorageValue<_, Vec<EventRecord<T::Event, T::Hash>>, ValueQuery>;
StorageValue<_, Vec<Box<EventRecord<T::Event, T::Hash>>>, ValueQuery>;

/// The number of events in the `Events<T>` list.
#[pallet::storage]
Expand Down Expand Up @@ -1213,7 +1216,7 @@ impl<T: Config> Pallet<T> {
old_event_count
};

Events::<T>::append(&event);
Events::<T>::append(event);

for topic in topics {
<EventTopics<T>>::append(topic, &(block_number, event_idx));
Expand Down Expand Up @@ -1380,14 +1383,16 @@ impl<T: Config> Pallet<T> {
/// 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()
// Dereferencing the events here is fine since we are not in the
// memory-restricted runtime.
Self::read_events_no_consensus().into_iter().map(|e| *e).collect()
}

/// 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>> {
pub fn read_events_no_consensus() -> Vec<Box<EventRecord<T::Event, T::Hash>>> {
Events::<T>::get()
}

Expand Down