Companion for new Trie cache (#5897)

* Switch to Substrate branch

* Make everything compile

* Revert "Switch to Substrate branch"

This reverts commit cbbab7431a07cfd645428a9f4c130362a8e7588b.

* Remove stuff

* More fixes

* Fix branch

* Update Substrate

* FMT
This commit is contained in:
Bastian Köcher
2022-08-18 23:35:56 +02:00
committed by GitHub
parent 2e72ae46ec
commit c3404d109d
7 changed files with 243 additions and 236 deletions
+226 -205
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -10,5 +10,5 @@ polkadot-node-primitives = { package = "polkadot-node-primitives", path = "../no
novelpoly = { package = "reed-solomon-novelpoly", version = "1.0.0" }
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["std", "derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
thiserror = "1.0.31"
+15 -12
View File
@@ -28,11 +28,11 @@ use parity_scale_codec::{Decode, Encode};
use polkadot_node_primitives::{AvailableData, Proof};
use polkadot_primitives::v2::{BlakeTwo256, Hash as H256, HashT};
use sp_core::Blake2Hasher;
use thiserror::Error;
use trie::{
trie_types::{TrieDB, TrieDBMutV0 as TrieDBMut},
MemoryDB, Trie, TrieMut, EMPTY_PREFIX,
use sp_trie::{
trie_types::{TrieDBBuilder, TrieDBMutBuilderV0 as TrieDBMutBuilder},
LayoutV0, MemoryDB, Trie, TrieMut, EMPTY_PREFIX,
};
use thiserror::Error;
use novelpoly::{CodeParams, WrappedShard};
@@ -224,13 +224,16 @@ impl<'a, I: AsRef<[u8]>> Iterator for Branches<'a, I> {
type Item = (Proof, &'a [u8]);
fn next(&mut self) -> Option<Self::Item> {
use trie::Recorder;
use sp_trie::Recorder;
let trie = TrieDB::new(&self.trie_storage, &self.root)
.expect("`Branches` is only created with a valid memorydb that contains all nodes for the trie with given root; qed");
let mut recorder = Recorder::<LayoutV0<Blake2Hasher>>::new();
let res = {
let trie = TrieDBBuilder::new(&self.trie_storage, &self.root)
.with_recorder(&mut recorder)
.build();
let mut recorder = Recorder::new();
let res = (self.current_pos as u32).using_encoded(|s| trie.get_with(s, &mut recorder));
(self.current_pos as u32).using_encoded(|s| trie.get(s))
};
match res.expect("all nodes in trie present; qed") {
Some(_) => {
@@ -257,7 +260,7 @@ where
// construct trie mapping each chunk's index to its hash.
{
let mut trie = TrieDBMut::new(&mut trie_storage, &mut root);
let mut trie = TrieDBMutBuilder::new(&mut trie_storage, &mut root).build();
for (i, chunk) in chunks.as_ref().iter().enumerate() {
(i as u32).using_encoded(|encoded_index| {
let chunk_hash = BlakeTwo256::hash(chunk.as_ref());
@@ -275,10 +278,10 @@ where
pub fn branch_hash(root: &H256, branch_nodes: &Proof, index: usize) -> Result<H256, Error> {
let mut trie_storage: MemoryDB<Blake2Hasher> = MemoryDB::default();
for node in branch_nodes.iter() {
(&mut trie_storage as &mut trie::HashDB<_>).insert(EMPTY_PREFIX, node);
(&mut trie_storage as &mut sp_trie::HashDB<_>).insert(EMPTY_PREFIX, node);
}
let trie = TrieDB::new(&trie_storage, &root).map_err(|_| Error::InvalidBranchProof)?;
let trie = TrieDBBuilder::new(&trie_storage, &root).build();
let res = (index as u32).using_encoded(|key| {
trie.get_with(key, |raw_hash: &[u8]| H256::decode(&mut &raw_hash[..]))
});
+1 -2
View File
@@ -176,8 +176,7 @@ pub fn node_config(
keystore: KeystoreConfig::InMemory,
keystore_remote: Default::default(),
database: DatabaseSource::RocksDb { path: root.join("db"), cache_size: 128 },
state_cache_size: 16777216,
state_cache_child_ratio: None,
trie_cache_maximum_size: Some(64 * 1024 * 1024),
state_pruning: Default::default(),
blocks_pruning: BlocksPruning::All,
chain_spec: Box::new(spec),
-1
View File
@@ -57,7 +57,6 @@ frame-support-test = { git = "https://github.com/paritytech/substrate", branch =
pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie-db = "0.23.1"
serde_json = "1.0.81"
libsecp256k1 = "0.7.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../primitives/test-helpers" }
-1
View File
@@ -96,7 +96,6 @@ hex-literal = "0.3.4"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie-db = "0.23.1"
serde_json = "1.0.81"
separator = "0.4.1"
remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" }
-14
View File
@@ -717,20 +717,6 @@ impl pallet_beefy_mmr::Config for Runtime {
type BeefyDataProvider = ParasProvider;
}
parameter_types! {
/// This is a pretty unscientific cap.
///
/// Note that once this is hit the pallet will essentially throttle incoming requests down to one
/// call per block.
pub const MaxRequests: u32 = 4 * HOURS as u32;
/// Number of headers to keep.
///
/// Assuming the worst case of every header being finalized, we will keep headers at least for a
/// week.
pub const HeadersToKeep: u32 = 7 * DAYS as u32;
}
parameter_types! {
pub const EndingPeriod: BlockNumber = 1 * HOURS;
pub const SampleLength: BlockNumber = 1;