Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit 32510e1

Browse files
authored
Fix WASM block producer panic (paritytech#11206)
* Box events Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Box events" This reverts commit 9fb1887. * Revert "Fix tests" This reverts commit 981c50f. * Use simpler approach Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update doc Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
1 parent 2b4818a commit 32510e1

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

frame/system/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,14 @@ pub mod pallet {
591591

592592
/// Events deposited for the current block.
593593
///
594-
/// NOTE: This storage item is explicitly unbounded since it is never intended to be read
595-
/// from within the runtime.
594+
/// NOTE: The item is unbound and should therefore never be read on chain.
595+
/// It could otherwise inflate the PoV size of a block.
596+
///
597+
/// Events have a large in-memory size. Box the events to not go out-of-memory
598+
/// just in case someone still reads them from within the runtime.
596599
#[pallet::storage]
597600
pub(super) type Events<T: Config> =
598-
StorageValue<_, Vec<EventRecord<T::Event, T::Hash>>, ValueQuery>;
601+
StorageValue<_, Vec<Box<EventRecord<T::Event, T::Hash>>>, ValueQuery>;
599602

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

1216-
Events::<T>::append(&event);
1219+
Events::<T>::append(event);
12171220

12181221
for topic in topics {
12191222
<EventTopics<T>>::append(topic, &(block_number, event_idx));
@@ -1380,14 +1383,16 @@ impl<T: Config> Pallet<T> {
13801383
/// items for any behavior like this.
13811384
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
13821385
pub fn events() -> Vec<EventRecord<T::Event, T::Hash>> {
1383-
Self::read_events_no_consensus()
1386+
// Dereferencing the events here is fine since we are not in the
1387+
// memory-restricted runtime.
1388+
Self::read_events_no_consensus().into_iter().map(|e| *e).collect()
13841389
}
13851390

13861391
/// Get the current events deposited by the runtime.
13871392
///
13881393
/// Should only be called if you know what you are doing and outside of the runtime block
13891394
/// execution else it can have a large impact on the PoV size of a block.
1390-
pub fn read_events_no_consensus() -> Vec<EventRecord<T::Event, T::Hash>> {
1395+
pub fn read_events_no_consensus() -> Vec<Box<EventRecord<T::Event, T::Hash>>> {
13911396
Events::<T>::get()
13921397
}
13931398

0 commit comments

Comments
 (0)