This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Dynamic Benchmarking DB Whitelist #6815
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
778587c
Add `get_whitelist` api
shawntabrizi 3f837b7
add whitelisted caller
shawntabrizi 8008372
Whitelist caller
shawntabrizi 0a16000
remove caller 0
shawntabrizi 15ac408
initial piping of origin (not actual value yet)
shawntabrizi 3a9793d
remove attempt to pass origin around
shawntabrizi 774e247
Add whitelist for `DidUpdate` storage on `pallet_timestamp`
shawntabrizi 0ba3008
fix traits
shawntabrizi 259694d
only add to whitelist if !contains
shawntabrizi f7ff3b2
PassBy not implemented error
shawntabrizi 659e4f4
Whitelist read/writes explicitly per key
shawntabrizi 108fffa
Merge branch 'master' into shawntabrizi-dynamic-whitelist
shawntabrizi 6357750
update docs
shawntabrizi c4d5d03
reduce trait constraint
shawntabrizi 7c69c55
copy pasta
shawntabrizi 6b8d5ed
Apply suggestions from code review
shawntabrizi fcc8a8c
rename functions @apopiak
shawntabrizi cda3225
missed some renaming
shawntabrizi f203fa1
enable doc tests
shawntabrizi fce5f63
Update docs
shawntabrizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}; | ||
|
@@ -95,7 +98,7 @@ pub struct BenchmarkingState<B: BlockT> { | |
shared_cache: SharedCache<B>, // shared cache is always empty | ||
key_tracker: RefCell<HashMap<Vec<u8>, KeyTracker>>, | ||
read_write_tracker: RefCell<ReadWriteTracker>, | ||
whitelist: RefCell<Vec<Vec<u8>>>, | ||
whitelist: RefCell<Vec<TrackedStorageKey>>, | ||
} | ||
|
||
impl<B: BlockT> BenchmarkingState<B> { | ||
|
@@ -155,15 +158,14 @@ impl<B: BlockT> BenchmarkingState<B> { | |
fn add_whitelist_to_tracker(&self) { | ||
let mut key_tracker = self.key_tracker.borrow_mut(); | ||
|
||
let whitelisted = KeyTracker { | ||
has_been_read: true, | ||
has_been_written: true, | ||
}; | ||
|
||
let whitelist = self.whitelist.borrow(); | ||
|
||
whitelist.iter().for_each(|key| { | ||
key_tracker.insert(key.to_vec(), whitelisted); | ||
let whitelisted = KeyTracker { | ||
has_been_read: key.has_been_read, | ||
has_been_written: key.has_been_written, | ||
}; | ||
key_tracker.insert(key.key.clone(), whitelisted); | ||
}); | ||
} | ||
|
||
|
@@ -181,18 +183,21 @@ impl<B: BlockT> BenchmarkingState<B> { | |
|
||
let maybe_tracker = key_tracker.get(key); | ||
|
||
let has_been_read = KeyTracker { | ||
has_been_read: true, | ||
has_been_written: false, | ||
}; | ||
|
||
match maybe_tracker { | ||
None => { | ||
let has_been_read = KeyTracker { | ||
has_been_read: true, | ||
has_been_written: false, | ||
}; | ||
key_tracker.insert(key.to_vec(), has_been_read); | ||
read_write_tracker.add_read(); | ||
}, | ||
Some(tracker) => { | ||
if !tracker.has_been_read { | ||
let has_been_read = KeyTracker { | ||
has_been_read: true, | ||
has_been_written: tracker.has_been_written, | ||
}; | ||
Comment on lines
+197
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic needed to be updated to support the scenario where we want to count a read, but ignore a write. (i.e. timestamp pallet) |
||
key_tracker.insert(key.to_vec(), has_been_read); | ||
read_write_tracker.add_read(); | ||
} else { | ||
|
@@ -426,7 +431,11 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> { | |
self.wipe_tracker() | ||
} | ||
|
||
fn set_whitelist(&self, new: Vec<Vec<u8>>) { | ||
fn get_whitelist(&self) -> Vec<TrackedStorageKey> { | ||
self.whitelist.borrow().to_vec() | ||
} | ||
|
||
fn set_whitelist(&self, new: Vec<TrackedStorageKey>) { | ||
*self.whitelist.borrow_mut() = new; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.