Skip to content
Unverified Commit c3c4f910 authored by Bastian Köcher's avatar Bastian Köcher
Browse files

sp-state-machine: Read value from backend when writing the first time

This is a first step into fixing https://github.com/paritytech/polkadot-sdk/issues/6020.
The underlying problem for parachains is that when calling `storage_root`, values that
are written, will need to be looked up in the trie. This is required to insert the value
or to remove it. The problem is that this lookup in `storage_root` increases the storage
proof size, but storage reclaim for example can not track these lookups. This means that
with storage reclaim it is possible to include more transactions than what the block should
be allowed to include.
This pull request reads a key from the backend the first time it is written. This results in
taking into account what `storage_root` is doing at the end of a block. However, this may
still skips reading one extra `node` (depending on the trie structure). Skipping only one `node`
is far less problematic than skipping the entire lookup. A future pull request will improve this further
to take the entire operation of `storage_root` into account.

For chains that are not recording a storage proof, they will still do this extra backend read. However,
this read will end up in the cache. At the end of the block the key will be read again as part of
`storage_root`, but served from the cache. So, there is no downside of this.
parent c0df223e
Pipeline #502785 waiting for manual action with stages
in 1 hour and 1 second