Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ governor = { version = "0.6.0" }
gum = { path = "polkadot/node/gum", default-features = false, package = "tracing-gum" }
gum-proc-macro = { path = "polkadot/node/gum/proc-macro", default-features = false, package = "tracing-gum-proc-macro" }
handlebars = { version = "5.1.0" }
hashbrown = "0.15.3"
hash-db = { version = "0.16.0", default-features = false }
hash256-std-hasher = { version = "0.15.2", default-features = false }
hex = { version = "0.4.3", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions cumulus/pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
bytes = { workspace = true }
codec = { features = ["derive"], workspace = true }
environmental = { workspace = true }
hashbrown = { workspace = true }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloc::{
boxed::Box,
collections::btree_map::{BTreeMap, Entry},
};
use alloc::boxed::Box;

use core::cell::{RefCell, RefMut};
use hashbrown::{hash_map::Entry, HashMap};
use sp_state_machine::TrieCacheProvider;
use sp_trie::NodeCodec;
use trie_db::{node::NodeOwned, Hasher};
Expand All @@ -28,8 +27,8 @@ use trie_db::{node::NodeOwned, Hasher};
/// of values. To be used in `validate_block` to serve values and nodes that
/// have already been loaded and decoded from the storage proof.
pub(crate) struct TrieCache<'a, H: Hasher> {
node_cache: RefMut<'a, BTreeMap<H::Out, NodeOwned<H::Out>>>,
value_cache: Option<RefMut<'a, BTreeMap<Box<[u8]>, trie_db::CachedValue<H::Out>>>>,
node_cache: RefMut<'a, HashMap<H::Out, NodeOwned<H::Out>>>,
value_cache: Option<RefMut<'a, HashMap<Box<[u8]>, trie_db::CachedValue<H::Out>>>>,
}

impl<'a, H: Hasher> trie_db::TrieCache<NodeCodec<H>> for TrieCache<'a, H> {
Expand Down Expand Up @@ -66,14 +65,14 @@ impl<'a, H: Hasher> trie_db::TrieCache<NodeCodec<H>> for TrieCache<'a, H> {

/// Provider of [`TrieCache`] instances.
pub(crate) struct CacheProvider<H: Hasher> {
node_cache: RefCell<BTreeMap<H::Out, NodeOwned<H::Out>>>,
node_cache: RefCell<HashMap<H::Out, NodeOwned<H::Out>>>,
/// Cache: `storage_root` => `storage_key` => `value`.
///
/// One `block` can for example use multiple tries (child tries) and we need to distinguish the
/// cached (`storage_key`, `value`) between them. For this we are using the `storage_root` to
/// distinguish them (even if the storage root is the same for two child tries, it just means
/// that both are exactly the same trie and there would happen no collision).
value_cache: RefCell<BTreeMap<H::Out, BTreeMap<Box<[u8]>, trie_db::CachedValue<H::Out>>>>,
value_cache: RefCell<HashMap<H::Out, HashMap<Box<[u8]>, trie_db::CachedValue<H::Out>>>>,
}

impl<H: Hasher> CacheProvider<H> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

use codec::Encode;

use alloc::{
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
rc::Rc,
};
use alloc::rc::Rc;

use core::cell::{RefCell, RefMut};
use hashbrown::{HashMap, HashSet};
use sp_trie::{NodeCodec, ProofSizeProvider, StorageProof};
use trie_db::{Hasher, RecordedForKey, TrieAccess};

Expand All @@ -35,9 +34,9 @@ use trie_db::{Hasher, RecordedForKey, TrieAccess};
/// The internal size counting logic should align
/// with ['sp_trie::recorder::Recorder'].
pub(crate) struct SizeOnlyRecorder<'a, H: Hasher> {
seen_nodes: RefMut<'a, BTreeSet<H::Out>>,
seen_nodes: RefMut<'a, HashSet<H::Out>>,
encoded_size: RefMut<'a, usize>,
recorded_keys: RefMut<'a, BTreeMap<Rc<[u8]>, RecordedForKey>>,
recorded_keys: RefMut<'a, HashMap<Rc<[u8]>, RecordedForKey>>,
}

impl<'a, H: trie_db::Hasher> trie_db::TrieRecorder<H::Out> for SizeOnlyRecorder<'a, H> {
Expand Down Expand Up @@ -91,9 +90,9 @@ impl<'a, H: trie_db::Hasher> trie_db::TrieRecorder<H::Out> for SizeOnlyRecorder<

#[derive(Clone)]
pub(crate) struct SizeOnlyRecorderProvider<H: Hasher> {
seen_nodes: Rc<RefCell<BTreeSet<H::Out>>>,
seen_nodes: Rc<RefCell<HashSet<H::Out>>>,
encoded_size: Rc<RefCell<usize>>,
recorded_keys: Rc<RefCell<BTreeMap<Rc<[u8]>, RecordedForKey>>>,
recorded_keys: Rc<RefCell<HashMap<Rc<[u8]>, RecordedForKey>>>,
}

impl<H: Hasher> Default for SizeOnlyRecorderProvider<H> {
Expand Down
Loading