validate-block: Fix TrieCache implementation (#2214)

The trie cache implementation was ignoring the `storage_root` when
setting up the value cache. The problem with this is that the value
cache works using `storage_keys` and these keys are not unique across
different tries. A block can actually have different tries (main trie
and multiple child tries). This pull request fixes the issue by not
ignoring the `storage_root` and returning an unique `value_cache` per
`storage_root`. It also adds a test for the seen bug and improves
documentation that this doesn't happen again.
This commit is contained in:
Bastian Köcher authored and GitHub committed 2023-11-08 14:33:19 +01:00
1 parent 9673fbfa32
commit 1bc0885829
8 files changed
+95 -14

No files matched your search

@@ -52,7 +52,10 @@ pub trait TrieCacheProvider<H: Hasher> {
/// Return a [`trie_db::TrieDB`] compatible cache.
///
/// The `storage_root` parameter should be the storage root of the used trie.
/// The `storage_root` parameter *must* be the storage root of the trie this cache is used for.
///
/// NOTE: Implementors should use the `storage_root` to differentiate between storage keys that
/// may belong to different tries.
fn as_trie_db_cache(&self, storage_root: H::Out) -> Self::Cache<'_>;
/// Returns a cache that can be used with a [`trie_db::TrieDBMut`].