mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
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:
@@ -49,6 +49,30 @@ pub mod pallet {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A dispatchable that first reads two values from two different child tries, asserts they
|
||||
/// are the expected values (if the values exist in the state) and then writes two different
|
||||
/// values to these child tries.
|
||||
#[pallet::weight(0)]
|
||||
pub fn read_and_write_child_tries(_: OriginFor<T>) -> DispatchResult {
|
||||
let key = &b"hello"[..];
|
||||
let first_trie = &b"first"[..];
|
||||
let second_trie = &b"second"[..];
|
||||
let first_value = "world1".encode();
|
||||
let second_value = "world2".encode();
|
||||
|
||||
if let Some(res) = sp_io::default_child_storage::get(first_trie, key) {
|
||||
assert_eq!(first_value, res);
|
||||
}
|
||||
if let Some(res) = sp_io::default_child_storage::get(second_trie, key) {
|
||||
assert_eq!(second_value, res);
|
||||
}
|
||||
|
||||
sp_io::default_child_storage::set(first_trie, key, &first_value);
|
||||
sp_io::default_child_storage::set(second_trie, key, &second_value);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
|
||||
Reference in New Issue
Block a user