Skip to content

Commit

Permalink
Add memory-tracker feature to sp-trie to fix wasm panic (parityte…
Browse files Browse the repository at this point in the history
…ch#6745)

* Add memory tracker feature to sp-trie to fix wasm panic

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
expenses and bkchr authored Jul 30, 2020
1 parent 075b2d7 commit a5d6c90
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
7 changes: 4 additions & 3 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 bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ browser-utils = { package = "substrate-browser-utils", path = "../../../utils/br
node-executor = { version = "2.0.0-rc5", path = "../executor", features = [ "wasmtime" ] }
sc-cli = { version = "0.8.0-rc5", optional = true, path = "../../../client/cli", features = [ "wasmtime" ] }
sc-service = { version = "0.8.0-rc5", default-features = false, path = "../../../client/service", features = [ "wasmtime" ] }
sp-trie = { version = "2.0.0-rc5", default-features = false, path = "../../../primitives/trie", features = ["memory-tracker"] }

[dev-dependencies]
sc-keystore = { version = "2.0.0-rc5", path = "../../../client/keystore" }
Expand Down
1 change: 1 addition & 0 deletions primitives/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ std = [
"trie-root/std",
"sp-core/std",
]
memory-tracker = []
17 changes: 14 additions & 3 deletions primitives/trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ impl<H: Hasher> TrieConfiguration for Layout<H> {
}
}

#[cfg(not(feature = "memory-tracker"))]
type MemTracker = memory_db::NoopTracker<trie_db::DBValue>;
#[cfg(feature = "memory-tracker")]
type MemTracker = memory_db::MemCounter<trie_db::DBValue>;

/// TrieDB error over `TrieConfiguration` trait.
pub type TrieError<L> = trie_db::TrieError<TrieHash<L>, CError<L>>;
/// Reexport from `hash_db`, with genericity set for `Hasher` trait.
Expand All @@ -88,13 +93,19 @@ pub type HashDB<'a, H> = dyn hash_db::HashDB<H, trie_db::DBValue> + 'a;
/// Reexport from `hash_db`, with genericity set for `Hasher` trait.
/// This uses a `KeyFunction` for prefixing keys internally (avoiding
/// key conflict for non random keys).
pub type PrefixedMemoryDB<H> = memory_db::MemoryDB<H, memory_db::PrefixedKey<H>, trie_db::DBValue>;
pub type PrefixedMemoryDB<H> = memory_db::MemoryDB<
H, memory_db::PrefixedKey<H>, trie_db::DBValue, MemTracker
>;
/// Reexport from `hash_db`, with genericity set for `Hasher` trait.
/// This uses a noops `KeyFunction` (key addressing must be hashed or using
/// an encoding scheme that avoid key conflict).
pub type MemoryDB<H> = memory_db::MemoryDB<H, memory_db::HashKey<H>, trie_db::DBValue>;
pub type MemoryDB<H> = memory_db::MemoryDB<
H, memory_db::HashKey<H>, trie_db::DBValue, MemTracker,
>;
/// Reexport from `hash_db`, with genericity set for `Hasher` trait.
pub type GenericMemoryDB<H, KF> = memory_db::MemoryDB<H, KF, trie_db::DBValue>;
pub type GenericMemoryDB<H, KF> = memory_db::MemoryDB<
H, KF, trie_db::DBValue, MemTracker
>;

/// Persistent trie database read-access interface for the a given hasher.
pub type TrieDB<'a, L> = trie_db::TrieDB<'a, L>;
Expand Down

0 comments on commit a5d6c90

Please sign in to comment.