Introduce event segment to store multiple events under one key #7836
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
See the previous discussion starting from this comment in the thread.
Currently, all the events of the current block are stored in a single list
StorageValue<Vec<EventRecord>>
which brings problems:This PR introduces event segment to split the list into multiple smaller segments, each storing multiple events (but should still be much smaller than the single list) under one key in
frame-system
.Integration
When
EventSegmentSize
is set to zero, event segment is disabled and the event is stored atEvents
as it is right now.When
EventSegmentSize > 0
, the event segment is used to store event, be aware to:migrate_from_events_to_event_segments
storage migration to clear event fromEvents
during runtime upgrade.i
, generate storage proof of an item under keyi / EventSegmentSize
inEventSegments
map.EventCount
and the first(EventCount / EventSegmentSize) + 1
items in theEventSegments
map, because other items in the map are from events of the previous block.Review Notes
The event segment consists of:
EventSegmentSize: Get<u32>
, it is the max number of events stored in each segment.Events
as it is right now.StorageValue<Vec<EventRecord>>
, a smaller segment brings more items to the Trie and may impact performance.EventSegments: StorageMap<u32, Vec<EventRecord>>
, replaceEvents: StorageValue<Vec<EventRecord>>
to store event, starting from index0
in the map each segment can fitEventSegmentSize
events, once the segment is full, the following event will be stored at the next segment in index1
, etc.UnclearedEventCount: StorageValue<u32>
, the total number of uncleared events from the previous blocks.EventCount
number of events in the map are deposited by the current block.