Remove ballast from genesis block #1671
Merged
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.
We had a piece of data in the header, which worked acceptably well when segments were tiny. When we increased recorded history segment to 128MiB, suddenly we started getting issues with RPC that can't return the data, when returned JS will be slow to decode and moving ballast to extrinsics requires even more hacks since object mapping fails to allocate enough memory in WASM for such a big extrinsic.
In the end I decided to leverage the fact that in SCALE encoding size of following data (except in special cases) is known beforehand. So by appending some extra data after encoded data we can store whatever we want without affecting decoding. This is exact what I did here, adding essentially invisible pseudo-random data to the end of the encoding of genesis block.
The first commit is necessary, but it was also useful regardless, hence separate commit.
@dariolina I do not recall if we mention somewhere how we do this, but if we do, then we need to update older description to reflect this change. Ended up being quite elegant actually.
Code contributor checklist: