Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
Prev Previous commit
Next Next commit
PassBy not implemented error
  • Loading branch information
shawntabrizi committed Aug 17, 2020
commit f7ff3b29649cd621ecab01e49a7c8b349ce7ada2
1 change: 1 addition & 0 deletions Cargo.lock

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

13 changes: 8 additions & 5 deletions client/db/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use std::collections::HashMap;

use hash_db::{Prefix, Hasher};
use sp_trie::{MemoryDB, prefixed_key};
use sp_core::{storage::ChildInfo, hexdisplay::HexDisplay};
use sp_core::{
storage::{ChildInfo, TrackedStorageKey},
hexdisplay::HexDisplay
};
use sp_runtime::traits::{Block as BlockT, HashFor};
use sp_runtime::Storage;
use sp_state_machine::{DBValue, backend::Backend as StateBackend, StorageCollection};
Expand Down Expand Up @@ -93,9 +96,9 @@ pub struct BenchmarkingState<B: BlockT> {
genesis: HashMap<Vec<u8>, (Vec<u8>, i32)>,
record: Cell<Vec<Vec<u8>>>,
shared_cache: SharedCache<B>, // shared cache is always empty
key_tracker: RefCell<HashMap<Vec<u8>, KeyTracker>>,
key_tracker: RefCell<HashMap<Vec<u8>, TrackedStorageKey>>,
read_write_tracker: RefCell<ReadWriteTracker>,
whitelist: RefCell<Vec<Vec<u8>>>,
whitelist: RefCell<Vec<TrackedStorageKey>>,
}

impl<B: BlockT> BenchmarkingState<B> {
Expand Down Expand Up @@ -426,11 +429,11 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
self.wipe_tracker()
}

fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
self.whitelist.borrow_mut().to_vec()
}

fn set_whitelist(&self, new: Vec<Vec<u8>>) {
fn set_whitelist(&self, new: Vec<TrackedStorageKey>) {
*self.whitelist.borrow_mut() = new;
}

Expand Down
1 change: 1 addition & 0 deletions frame/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sp-runtime-interface = { version = "2.0.0-rc5", path = "../../primitives/runtime
sp-runtime = { version = "2.0.0-rc5", path = "../../primitives/runtime", default-features = false }
sp-std = { version = "2.0.0-rc5", path = "../../primitives/std", default-features = false }
sp-io = { version = "2.0.0-rc5", path = "../../primitives/io", default-features = false }
sp-storage = { version = "2.0.0-rc5", path = "../../primitives/storage", default-features = false }
frame-support = { version = "2.0.0-rc5", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-rc5", default-features = false, path = "../system" }

Expand Down
7 changes: 4 additions & 3 deletions frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use codec::{Encode, Decode};
use sp_std::{vec::Vec, prelude::Box};
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeString;
use sp_storage::TrackedStorageKey;

/// An alphabet of possible parameters to use for benchmarking.
#[derive(Encode, Decode, Clone, Copy, PartialEq, Debug)]
Expand Down Expand Up @@ -112,17 +113,17 @@ pub trait Benchmarking {
}

/// Get the DB whitelist.
fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
self.get_whitelist()
}

/// Set the DB whitelist.
fn set_whitelist(&mut self, new: Vec<Vec<u8>>) {
fn set_whitelist(&mut self, new: Vec<TrackedStorageKey>) {
self.set_whitelist(new)
}

// Add a new item to the DB whitelist.
fn add_whitelist(&mut self, add: Vec<u8>) {
fn add_whitelist(&mut self, add: TrackedStorageKey) {
let mut whitelist = self.get_whitelist();
if !whitelist.contains(&add) {
whitelist.push(add);
Expand Down
6 changes: 3 additions & 3 deletions primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use std::any::{Any, TypeId};

use sp_storage::ChildInfo;
use sp_storage::{ChildInfo, TrackedStorageKey};

pub use scope_limited::{set_and_run_with_externalities, with_externalities};
pub use extensions::{Extension, Extensions, ExtensionStore};
Expand Down Expand Up @@ -253,14 +253,14 @@ pub trait Externalities: ExtensionStore {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
///
/// Gets the current DB tracking whitelist.
fn get_whitelist(&self) -> Vec<Vec<u8>>;
fn get_whitelist(&self) -> Vec<TrackedStorageKey>;

/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// Benchmarking related functionality and shouldn't be used anywhere else!
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
///
/// Adds new storage keys to the DB tracking whitelist.
fn set_whitelist(&mut self, new: Vec<Vec<u8>>);
fn set_whitelist(&mut self, new: Vec<TrackedStorageKey>);
}

/// Extension for the [`Externalities`] trait.
Expand Down
9 changes: 6 additions & 3 deletions primitives/state-machine/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

use hash_db::Hasher;
use codec::{Decode, Encode};
use sp_core::{traits::RuntimeCode, storage::{ChildInfo, well_known_keys}};
use sp_core::{
traits::RuntimeCode,
storage::{ChildInfo, well_known_keys, TrackedStorageKey}
};
use crate::{
trie_backend::TrieBackend,
trie_backend_essence::TrieBackendStorage,
Expand Down Expand Up @@ -227,12 +230,12 @@ pub trait Backend<H: Hasher>: std::fmt::Debug {
}

/// Get the whitelist for tracking db reads/writes
fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
Default::default()
}

/// Update the whitelist for tracking db reads/writes
fn set_whitelist(&self, _: Vec<Vec<u8>>) {}
fn set_whitelist(&self, _: Vec<TrackedStorageKey>) {}
}

impl<'a, T: Backend<H>, H: Hasher> Backend<H> for &'a T {
Expand Down
6 changes: 3 additions & 3 deletions primitives/state-machine/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_trie::trie_types::Layout;
use sp_core::{
storage::{
well_known_keys::is_child_storage_key, Storage,
ChildInfo, StorageChild,
ChildInfo, StorageChild, TrackedStorageKey,
},
traits::Externalities, Blake2Hasher,
};
Expand Down Expand Up @@ -325,11 +325,11 @@ impl Externalities for BasicExternalities {
unimplemented!("reset_read_write_count is not supported in Basic")
}

fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
unimplemented!("get_whitelist is not supported in Basic")
}

fn set_whitelist(&mut self, _: Vec<Vec<u8>>) {
fn set_whitelist(&mut self, _: Vec<TrackedStorageKey>) {
unimplemented!("set_whitelist is not supported in Basic")
}
}
Expand Down
6 changes: 3 additions & 3 deletions primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
use hash_db::Hasher;
use sp_core::{
offchain::storage::OffchainOverlayedChanges,
storage::{well_known_keys::is_child_storage_key, ChildInfo},
storage::{well_known_keys::is_child_storage_key, ChildInfo, TrackedStorageKey},
traits::Externalities, hexdisplay::HexDisplay,
};
use sp_trie::{trie_types::Layout, empty_child_trie_root};
Expand Down Expand Up @@ -609,11 +609,11 @@ where
self.backend.reset_read_write_count()
}

fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
self.backend.get_whitelist()
}

fn set_whitelist(&mut self, new: Vec<Vec<u8>>) {
fn set_whitelist(&mut self, new: Vec<TrackedStorageKey>) {
self.backend.set_whitelist(new)
}
}
Expand Down
6 changes: 3 additions & 3 deletions primitives/state-machine/src/read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{
use crate::{Backend, StorageKey, StorageValue};
use hash_db::Hasher;
use sp_core::{
storage::ChildInfo,
storage::{ChildInfo, TrackedStorageKey},
traits::Externalities, Blake2Hasher,
};
use codec::Encode;
Expand Down Expand Up @@ -194,11 +194,11 @@ impl<'a, H: Hasher, B: 'a + Backend<H>> Externalities for ReadOnlyExternalities<
unimplemented!("reset_read_write_count is not supported in ReadOnlyExternalities")
}

fn get_whitelist(&self) -> Vec<Vec<u8>> {
fn get_whitelist(&self) -> Vec<TrackedStorageKey> {
unimplemented!("get_whitelist is not supported in ReadOnlyExternalities")
}

fn set_whitelist(&mut self, _: Vec<Vec<u8>>) {
fn set_whitelist(&mut self, _: Vec<TrackedStorageKey>) {
unimplemented!("set_whitelist is not supported in ReadOnlyExternalities")
}
}
Expand Down
9 changes: 9 additions & 0 deletions primitives/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ pub struct StorageKey(
pub Vec<u8>,
);

/// Storage key with read/write tracking information.
#[derive(PartialEq, Eq, RuntimeDebug, Clone)]
#[cfg_attr(feature = "std", derive(Hash, PartialOrd, Ord))]
pub struct TrackedStorageKey {
pub key: Vec<u8>,
pub has_been_read: bool,
pub has_been_written: bool,
}

/// Storage key of a child trie, it contains the prefix to the key.
#[derive(PartialEq, Eq, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, PartialOrd, Ord, Clone))]
Expand Down