mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -24,36 +24,22 @@
|
||||
//! DO NOT depend on user input). Thus transaction generation should be
|
||||
//! based on randomized data.
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
};
|
||||
use futures::Future;
|
||||
use std::{borrow::Cow, collections::HashMap, pin::Pin, sync::Arc};
|
||||
|
||||
use node_primitives::Block;
|
||||
use node_testing::bench::{BenchDb, Profile, BlockType, KeyTypes, DatabaseType};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::NumberFor,
|
||||
OpaqueExtrinsic,
|
||||
};
|
||||
use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile};
|
||||
use sc_transaction_pool_api::{
|
||||
ImportNotificationStream,
|
||||
PoolFuture,
|
||||
PoolStatus,
|
||||
TransactionFor,
|
||||
TransactionSource,
|
||||
TransactionStatusStreamFor,
|
||||
TxHash,
|
||||
ImportNotificationStream, PoolFuture, PoolStatus, TransactionFor, TransactionSource,
|
||||
TransactionStatusStreamFor, TxHash,
|
||||
};
|
||||
use sp_consensus::{Environment, Proposer};
|
||||
use sp_inherents::InherentDataProvider;
|
||||
use sp_runtime::{generic::BlockId, traits::NumberFor, OpaqueExtrinsic};
|
||||
|
||||
use crate::{
|
||||
common::SizeType,
|
||||
core::{self, Path, Mode},
|
||||
core::{self, Mode, Path},
|
||||
};
|
||||
|
||||
pub struct ConstructionBenchmarkDescription {
|
||||
@@ -72,7 +58,6 @@ pub struct ConstructionBenchmark {
|
||||
|
||||
impl core::BenchmarkDescription for ConstructionBenchmarkDescription {
|
||||
fn path(&self) -> Path {
|
||||
|
||||
let mut path = Path::new(&["node", "proposer"]);
|
||||
|
||||
match self.profile {
|
||||
@@ -104,11 +89,7 @@ impl core::BenchmarkDescription for ConstructionBenchmarkDescription {
|
||||
fn setup(self: Box<Self>) -> Box<dyn core::Benchmark> {
|
||||
let mut extrinsics: Vec<Arc<PoolTransaction>> = Vec::new();
|
||||
|
||||
let mut bench_db = BenchDb::with_key_types(
|
||||
self.database_type,
|
||||
50_000,
|
||||
self.key_types
|
||||
);
|
||||
let mut bench_db = BenchDb::with_key_types(self.database_type, 50_000, self.key_types);
|
||||
|
||||
let client = bench_db.client();
|
||||
|
||||
@@ -127,11 +108,9 @@ impl core::BenchmarkDescription for ConstructionBenchmarkDescription {
|
||||
fn name(&self) -> Cow<'static, str> {
|
||||
format!(
|
||||
"Block construction ({:?}/{}, {:?}, {:?} backend)",
|
||||
self.block_type,
|
||||
self.size,
|
||||
self.profile,
|
||||
self.database_type,
|
||||
).into()
|
||||
self.block_type, self.size, self.profile, self.database_type,
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +118,9 @@ impl core::Benchmark for ConstructionBenchmark {
|
||||
fn run(&mut self, mode: Mode) -> std::time::Duration {
|
||||
let context = self.database.create_context(self.profile);
|
||||
|
||||
let _ = context.client.runtime_version_at(&BlockId::Number(0))
|
||||
let _ = context
|
||||
.client
|
||||
.runtime_version_at(&BlockId::Number(0))
|
||||
.expect("Failed to get runtime version")
|
||||
.spec_version;
|
||||
|
||||
@@ -158,20 +139,25 @@ impl core::Benchmark for ConstructionBenchmark {
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
let proposer = futures::executor::block_on(proposer_factory.init(
|
||||
&context.client.header(&BlockId::number(0))
|
||||
.expect("Database error querying block #0")
|
||||
.expect("Block #0 should exist"),
|
||||
)).expect("Proposer initialization failed");
|
||||
|
||||
let _block = futures::executor::block_on(
|
||||
proposer.propose(
|
||||
timestamp_provider.create_inherent_data().expect("Create inherent data failed"),
|
||||
Default::default(),
|
||||
std::time::Duration::from_secs(20),
|
||||
None,
|
||||
let proposer = futures::executor::block_on(
|
||||
proposer_factory.init(
|
||||
&context
|
||||
.client
|
||||
.header(&BlockId::number(0))
|
||||
.expect("Database error querying block #0")
|
||||
.expect("Block #0 should exist"),
|
||||
),
|
||||
).map(|r| r.block).expect("Proposing failed");
|
||||
)
|
||||
.expect("Proposer initialization failed");
|
||||
|
||||
let _block = futures::executor::block_on(proposer.propose(
|
||||
timestamp_provider.create_inherent_data().expect("Create inherent data failed"),
|
||||
Default::default(),
|
||||
std::time::Duration::from_secs(20),
|
||||
None,
|
||||
))
|
||||
.map(|r| r.block)
|
||||
.expect("Proposing failed");
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
@@ -191,10 +177,7 @@ pub struct PoolTransaction {
|
||||
|
||||
impl From<OpaqueExtrinsic> for PoolTransaction {
|
||||
fn from(e: OpaqueExtrinsic) -> Self {
|
||||
PoolTransaction {
|
||||
data: e,
|
||||
hash: node_primitives::Hash::zero(),
|
||||
}
|
||||
PoolTransaction { data: e, hash: node_primitives::Hash::zero() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,15 +193,25 @@ impl sc_transaction_pool_api::InPoolTransaction for PoolTransaction {
|
||||
&self.hash
|
||||
}
|
||||
|
||||
fn priority(&self) -> &u64 { unimplemented!() }
|
||||
fn priority(&self) -> &u64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn longevity(&self) -> &u64 { unimplemented!() }
|
||||
fn longevity(&self) -> &u64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn requires(&self) -> &[Vec<u8>] { unimplemented!() }
|
||||
fn requires(&self) -> &[Vec<u8>] {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn provides(&self) -> &[Vec<u8>] { unimplemented!() }
|
||||
fn provides(&self) -> &[Vec<u8>] {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn is_propagable(&self) -> bool { unimplemented!() }
|
||||
fn is_propagable(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -236,7 +229,7 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {
|
||||
_at: &BlockId<Self::Block>,
|
||||
_source: TransactionSource,
|
||||
_xts: Vec<TransactionFor<Self>>,
|
||||
) -> PoolFuture<Vec<Result<node_primitives::Hash, Self::Error>>, Self::Error> {
|
||||
) -> PoolFuture<Vec<Result<node_primitives::Hash, Self::Error>>, Self::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -259,14 +252,21 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn ready_at(&self, _at: NumberFor<Self::Block>)
|
||||
-> Pin<Box<dyn Future<Output=Box<dyn Iterator<Item=Arc<Self::InPoolTransaction>> + Send>> + Send>>
|
||||
{
|
||||
let iter: Box<dyn Iterator<Item=Arc<PoolTransaction>> + Send> = Box::new(self.0.clone().into_iter());
|
||||
fn ready_at(
|
||||
&self,
|
||||
_at: NumberFor<Self::Block>,
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = Box<dyn Iterator<Item = Arc<Self::InPoolTransaction>> + Send>>
|
||||
+ Send,
|
||||
>,
|
||||
> {
|
||||
let iter: Box<dyn Iterator<Item = Arc<PoolTransaction>> + Send> =
|
||||
Box::new(self.0.clone().into_iter());
|
||||
Box::pin(futures::future::ready(iter))
|
||||
}
|
||||
|
||||
fn ready(&self) -> Box<dyn Iterator<Item=Arc<Self::InPoolTransaction>> + Send> {
|
||||
fn ready(&self) -> Box<dyn Iterator<Item = Arc<Self::InPoolTransaction>> + Send> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{fmt, borrow::{Cow, ToOwned}};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
borrow::{Cow, ToOwned},
|
||||
fmt,
|
||||
};
|
||||
|
||||
pub struct Path(Vec<String>);
|
||||
|
||||
@@ -33,7 +36,11 @@ impl Path {
|
||||
}
|
||||
|
||||
pub fn full(&self) -> String {
|
||||
self.0.iter().fold(String::new(), |mut val, next| { val.push_str("::"); val.push_str(next); val })
|
||||
self.0.iter().fold(String::new(), |mut val, next| {
|
||||
val.push_str("::");
|
||||
val.push_str(next);
|
||||
val
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has(&self, path: &str) -> bool {
|
||||
@@ -115,10 +122,7 @@ impl fmt::Display for BenchmarkOutput {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_benchmark(
|
||||
benchmark: Box<dyn BenchmarkDescription>,
|
||||
mode: Mode,
|
||||
) -> BenchmarkOutput {
|
||||
pub fn run_benchmark(benchmark: Box<dyn BenchmarkDescription>, mode: Mode) -> BenchmarkOutput {
|
||||
let name = benchmark.name().to_owned();
|
||||
let mut benchmark = benchmark.setup();
|
||||
|
||||
@@ -133,11 +137,7 @@ pub fn run_benchmark(
|
||||
let raw_average = (durations.iter().sum::<u128>() / (durations.len() as u128)) as u64;
|
||||
let average = (durations.iter().skip(10).take(30).sum::<u128>() / 30) as u64;
|
||||
|
||||
BenchmarkOutput {
|
||||
name: name.into(),
|
||||
raw_average,
|
||||
average,
|
||||
}
|
||||
BenchmarkOutput { name: name.into(), raw_average, average }
|
||||
}
|
||||
|
||||
macro_rules! matrix(
|
||||
|
||||
@@ -30,14 +30,15 @@ use crate::simple_trie::SimpleTrie;
|
||||
/// return root.
|
||||
pub fn generate_trie(
|
||||
db: Arc<dyn KeyValueDB>,
|
||||
key_values: impl IntoIterator<Item=(Vec<u8>, Vec<u8>)>,
|
||||
key_values: impl IntoIterator<Item = (Vec<u8>, Vec<u8>)>,
|
||||
) -> Hash {
|
||||
let mut root = Hash::default();
|
||||
|
||||
let (db, overlay) = {
|
||||
let mut overlay = HashMap::new();
|
||||
overlay.insert(
|
||||
hex::decode("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").expect("null key is valid"),
|
||||
hex::decode("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314")
|
||||
.expect("null key is valid"),
|
||||
Some(vec![0]),
|
||||
);
|
||||
let mut trie = SimpleTrie { db, overlay: &mut overlay };
|
||||
@@ -50,7 +51,7 @@ pub fn generate_trie(
|
||||
|
||||
trie_db.commit();
|
||||
}
|
||||
( trie.db, overlay )
|
||||
(trie.db, overlay)
|
||||
};
|
||||
|
||||
let mut transaction = db.transaction();
|
||||
|
||||
@@ -32,15 +32,15 @@
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use node_testing::bench::{BenchDb, Profile, BlockType, KeyTypes, DatabaseType};
|
||||
use node_primitives::Block;
|
||||
use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile};
|
||||
use sc_client_api::backend::Backend;
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_state_machine::InspectState;
|
||||
|
||||
use crate::{
|
||||
common::SizeType,
|
||||
core::{self, Path, Mode},
|
||||
core::{self, Mode, Path},
|
||||
};
|
||||
|
||||
pub struct ImportBenchmarkDescription {
|
||||
@@ -60,7 +60,6 @@ pub struct ImportBenchmark {
|
||||
|
||||
impl core::BenchmarkDescription for ImportBenchmarkDescription {
|
||||
fn path(&self) -> Path {
|
||||
|
||||
let mut path = Path::new(&["node", "import"]);
|
||||
|
||||
match self.profile {
|
||||
@@ -91,11 +90,7 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription {
|
||||
|
||||
fn setup(self: Box<Self>) -> Box<dyn core::Benchmark> {
|
||||
let profile = self.profile;
|
||||
let mut bench_db = BenchDb::with_key_types(
|
||||
self.database_type,
|
||||
50_000,
|
||||
self.key_types
|
||||
);
|
||||
let mut bench_db = BenchDb::with_key_types(self.database_type, 50_000, self.key_types);
|
||||
let block = bench_db.generate_block(self.block_type.to_content(self.size.transactions()));
|
||||
Box::new(ImportBenchmark {
|
||||
database: bench_db,
|
||||
@@ -108,11 +103,9 @@ impl core::BenchmarkDescription for ImportBenchmarkDescription {
|
||||
fn name(&self) -> Cow<'static, str> {
|
||||
format!(
|
||||
"Block import ({:?}/{}, {:?}, {:?} backend)",
|
||||
self.block_type,
|
||||
self.size,
|
||||
self.profile,
|
||||
self.database_type,
|
||||
).into()
|
||||
self.block_type, self.size, self.profile, self.database_type,
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +113,9 @@ impl core::Benchmark for ImportBenchmark {
|
||||
fn run(&mut self, mode: Mode) -> std::time::Duration {
|
||||
let mut context = self.database.create_context(self.profile);
|
||||
|
||||
let _ = context.client.runtime_version_at(&BlockId::Number(0))
|
||||
let _ = context
|
||||
.client
|
||||
.runtime_version_at(&BlockId::Number(0))
|
||||
.expect("Failed to get runtime version")
|
||||
.spec_version;
|
||||
|
||||
@@ -133,7 +128,8 @@ impl core::Benchmark for ImportBenchmark {
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
// Sanity checks.
|
||||
context.client
|
||||
context
|
||||
.client
|
||||
.state_at(&BlockId::number(1))
|
||||
.expect("state_at failed for block#1")
|
||||
.inspect_state(|| {
|
||||
@@ -155,19 +151,17 @@ impl core::Benchmark for ImportBenchmark {
|
||||
BlockType::Noop => {
|
||||
assert_eq!(
|
||||
node_runtime::System::events().len(),
|
||||
|
||||
// should be 2 per signed extrinsic + 1 per unsigned
|
||||
// we have 1 unsigned and the rest are signed in the block
|
||||
// those 2 events per signed are:
|
||||
// - deposit event for charging transaction fee
|
||||
// - extrinsic success
|
||||
(self.block.extrinsics.len() - 1) * 2 + 1,
|
||||
(self.block.extrinsics.len() - 1) * 2 + 1,
|
||||
);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if mode == Mode::Profile {
|
||||
std::thread::park_timeout(std::time::Duration::from_secs(1));
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
|
||||
mod common;
|
||||
mod construct;
|
||||
#[macro_use] mod core;
|
||||
mod import;
|
||||
#[macro_use]
|
||||
mod core;
|
||||
mod generator;
|
||||
mod import;
|
||||
mod simple_trie;
|
||||
mod state_sizes;
|
||||
mod tempdb;
|
||||
@@ -29,15 +30,15 @@ mod txpool;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
use node_testing::bench::{Profile, KeyTypes, BlockType, DatabaseType as BenchDataBaseType};
|
||||
use node_testing::bench::{BlockType, DatabaseType as BenchDataBaseType, KeyTypes, Profile};
|
||||
|
||||
use crate::{
|
||||
common::SizeType,
|
||||
core::{run_benchmark, Mode as BenchmarkMode},
|
||||
tempdb::DatabaseType,
|
||||
import::ImportBenchmarkDescription,
|
||||
trie::{TrieReadBenchmarkDescription, TrieWriteBenchmarkDescription, DatabaseSize},
|
||||
construct::ConstructionBenchmarkDescription,
|
||||
core::{run_benchmark, Mode as BenchmarkMode},
|
||||
import::ImportBenchmarkDescription,
|
||||
tempdb::DatabaseType,
|
||||
trie::{DatabaseSize, TrieReadBenchmarkDescription, TrieWriteBenchmarkDescription},
|
||||
txpool::PoolBenchmarkDescription,
|
||||
};
|
||||
|
||||
@@ -92,14 +93,25 @@ fn main() {
|
||||
SizeType::Large,
|
||||
SizeType::Full,
|
||||
SizeType::Custom(opt.transactions.unwrap_or(0)),
|
||||
].iter() {
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
for block_type in [
|
||||
BlockType::RandomTransfersKeepAlive,
|
||||
BlockType::RandomTransfersReaping,
|
||||
BlockType::Noop,
|
||||
].iter() {
|
||||
for database_type in [BenchDataBaseType::RocksDb, BenchDataBaseType::ParityDb].iter() {
|
||||
import_benchmarks.push((profile, size.clone(), block_type.clone(), database_type));
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
for database_type in
|
||||
[BenchDataBaseType::RocksDb, BenchDataBaseType::ParityDb].iter()
|
||||
{
|
||||
import_benchmarks.push((
|
||||
profile,
|
||||
size.clone(),
|
||||
block_type.clone(),
|
||||
database_type,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +175,7 @@ fn main() {
|
||||
println!("{}: {}", benchmark.name(), benchmark.path().full())
|
||||
}
|
||||
}
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
let mut results = Vec::new();
|
||||
@@ -183,7 +195,8 @@ fn main() {
|
||||
}
|
||||
|
||||
if opt.json {
|
||||
let json_result: String = serde_json::to_string(&results).expect("Failed to construct json");
|
||||
let json_result: String =
|
||||
serde_json::to_string(&results).expect("Failed to construct json");
|
||||
println!("{}", json_result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use hash_db::{AsHashDB, HashDB, Hasher as _, Prefix};
|
||||
use kvdb::KeyValueDB;
|
||||
use node_primitives::Hash;
|
||||
use sp_trie::DBValue;
|
||||
use hash_db::{HashDB, AsHashDB, Prefix, Hasher as _};
|
||||
|
||||
pub type Hasher = sp_core::Blake2Hasher;
|
||||
|
||||
@@ -32,7 +32,9 @@ pub struct SimpleTrie<'a> {
|
||||
}
|
||||
|
||||
impl<'a> AsHashDB<Hasher, DBValue> for SimpleTrie<'a> {
|
||||
fn as_hash_db(&self) -> &dyn hash_db::HashDB<Hasher, DBValue> { &*self }
|
||||
fn as_hash_db(&self) -> &dyn hash_db::HashDB<Hasher, DBValue> {
|
||||
&*self
|
||||
}
|
||||
|
||||
fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (dyn HashDB<Hasher, DBValue> + 'b) {
|
||||
&mut *self
|
||||
@@ -43,7 +45,7 @@ impl<'a> HashDB<Hasher, DBValue> for SimpleTrie<'a> {
|
||||
fn get(&self, key: &Hash, prefix: Prefix) -> Option<DBValue> {
|
||||
let key = sp_trie::prefixed_key::<Hasher>(key, prefix);
|
||||
if let Some(value) = self.overlay.get(&key) {
|
||||
return value.clone();
|
||||
return value.clone()
|
||||
}
|
||||
self.db.get(0, &key).expect("Database backend error")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// Kusama value size distribution
|
||||
pub const KUSAMA_STATE_DISTRIBUTION: &'static[(u32, u32)] = &[
|
||||
pub const KUSAMA_STATE_DISTRIBUTION: &'static [(u32, u32)] = &[
|
||||
(32, 35),
|
||||
(33, 20035),
|
||||
(34, 5369),
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use kvdb::{DBTransaction, KeyValueDB};
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
use std::{io, path::PathBuf, sync::Arc};
|
||||
use kvdb::{KeyValueDB, DBTransaction};
|
||||
use kvdb_rocksdb::{DatabaseConfig, Database};
|
||||
|
||||
#[derive(Debug, Clone, Copy, derive_more::Display)]
|
||||
pub enum DatabaseType {
|
||||
@@ -44,13 +44,14 @@ impl KeyValueDB for ParityDbWrapper {
|
||||
|
||||
/// Write a transaction of changes to the buffer.
|
||||
fn write(&self, transaction: DBTransaction) -> io::Result<()> {
|
||||
self.0.commit(
|
||||
transaction.ops.iter().map(|op| match op {
|
||||
kvdb::DBOp::Insert { col, key, value } => (*col as u8, &key[key.len() - 32..], Some(value.to_vec())),
|
||||
self.0
|
||||
.commit(transaction.ops.iter().map(|op| match op {
|
||||
kvdb::DBOp::Insert { col, key, value } =>
|
||||
(*col as u8, &key[key.len() - 32..], Some(value.to_vec())),
|
||||
kvdb::DBOp::Delete { col, key } => (*col as u8, &key[key.len() - 32..], None),
|
||||
kvdb::DBOp::DeletePrefix { col: _, prefix: _ } => unimplemented!()
|
||||
})
|
||||
).expect("db error");
|
||||
kvdb::DBOp::DeletePrefix { col: _, prefix: _ } => unimplemented!(),
|
||||
}))
|
||||
.expect("db error");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -90,21 +91,19 @@ impl TempDatabase {
|
||||
match db_type {
|
||||
DatabaseType::RocksDb => {
|
||||
let db_cfg = DatabaseConfig::with_columns(1);
|
||||
let db = Database::open(&db_cfg, &self.0.path().to_string_lossy()).expect("Database backend error");
|
||||
let db = Database::open(&db_cfg, &self.0.path().to_string_lossy())
|
||||
.expect("Database backend error");
|
||||
Arc::new(db)
|
||||
},
|
||||
DatabaseType::ParityDb => {
|
||||
Arc::new(ParityDbWrapper({
|
||||
let mut options = parity_db::Options::with_columns(self.0.path(), 1);
|
||||
let mut column_options = &mut options.columns[0];
|
||||
column_options.ref_counted = true;
|
||||
column_options.preimage = true;
|
||||
column_options.uniform = true;
|
||||
parity_db::Db::open(&options).expect("db open error")
|
||||
}))
|
||||
}
|
||||
DatabaseType::ParityDb => Arc::new(ParityDbWrapper({
|
||||
let mut options = parity_db::Options::with_columns(self.0.path(), 1);
|
||||
let mut column_options = &mut options.columns[0];
|
||||
column_options.ref_counted = true;
|
||||
column_options.preimage = true;
|
||||
column_options.uniform = true;
|
||||
parity_db::Db::open(&options).expect("db open error")
|
||||
})),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,15 +120,10 @@ impl Clone for TempDatabase {
|
||||
);
|
||||
let self_db_files = std::fs::read_dir(self_dir)
|
||||
.expect("failed to list file in seed dir")
|
||||
.map(|f_result|
|
||||
f_result.expect("failed to read file in seed db")
|
||||
.path()
|
||||
).collect::<Vec<PathBuf>>();
|
||||
fs_extra::copy_items(
|
||||
&self_db_files,
|
||||
new_dir.path(),
|
||||
&fs_extra::dir::CopyOptions::new(),
|
||||
).expect("Copy of seed database is ok");
|
||||
.map(|f_result| f_result.expect("failed to read file in seed db").path())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
fs_extra::copy_items(&self_db_files, new_dir.path(), &fs_extra::dir::CopyOptions::new())
|
||||
.expect("Copy of seed database is ok");
|
||||
|
||||
TempDatabase(new_dir)
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
//! Trie benchmark (integrated).
|
||||
|
||||
use std::{borrow::Cow, collections::HashMap, sync::Arc};
|
||||
use hash_db::Prefix;
|
||||
use kvdb::KeyValueDB;
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
use hash_db::Prefix;
|
||||
use sp_state_machine::Backend as _;
|
||||
use sp_trie::{trie_types::TrieDBMut, TrieMut as _};
|
||||
use std::{borrow::Cow, collections::HashMap, sync::Arc};
|
||||
|
||||
use node_primitives::Hash;
|
||||
|
||||
@@ -32,7 +32,7 @@ use crate::{
|
||||
core::{self, Mode, Path},
|
||||
generator::generate_trie,
|
||||
simple_trie::SimpleTrie,
|
||||
tempdb::{TempDatabase, DatabaseType},
|
||||
tempdb::{DatabaseType, TempDatabase},
|
||||
};
|
||||
|
||||
pub const SAMPLE_SIZE: usize = 100;
|
||||
@@ -142,10 +142,7 @@ impl core::BenchmarkDescription for TrieReadBenchmarkDescription {
|
||||
assert_eq!(warmup_keys.len(), SAMPLE_SIZE);
|
||||
assert_eq!(query_keys.len(), SAMPLE_SIZE);
|
||||
|
||||
let root = generate_trie(
|
||||
database.open(self.database_type),
|
||||
key_values,
|
||||
);
|
||||
let root = generate_trie(database.open(self.database_type), key_values);
|
||||
|
||||
Box::new(TrieReadBenchmark {
|
||||
database,
|
||||
@@ -162,7 +159,8 @@ impl core::BenchmarkDescription for TrieReadBenchmarkDescription {
|
||||
self.database_size,
|
||||
pretty_print(self.database_size.keys()),
|
||||
self.database_type,
|
||||
).into()
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,12 +180,10 @@ impl core::Benchmark for TrieReadBenchmark {
|
||||
let storage: Arc<dyn sp_state_machine::Storage<sp_core::Blake2Hasher>> =
|
||||
Arc::new(Storage(db.open(self.database_type)));
|
||||
|
||||
let trie_backend = sp_state_machine::TrieBackend::new(
|
||||
storage,
|
||||
self.root,
|
||||
);
|
||||
let trie_backend = sp_state_machine::TrieBackend::new(storage, self.root);
|
||||
for (warmup_key, warmup_value) in self.warmup_keys.iter() {
|
||||
let value = trie_backend.storage(&warmup_key[..])
|
||||
let value = trie_backend
|
||||
.storage(&warmup_key[..])
|
||||
.expect("Failed to get key: db error")
|
||||
.expect("Warmup key should exist");
|
||||
|
||||
@@ -218,7 +214,6 @@ pub struct TrieWriteBenchmarkDescription {
|
||||
pub database_type: DatabaseType,
|
||||
}
|
||||
|
||||
|
||||
impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
fn path(&self) -> Path {
|
||||
let mut path = Path::new(&["trie", "write"]);
|
||||
@@ -253,10 +248,7 @@ impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
|
||||
assert_eq!(warmup_keys.len(), SAMPLE_SIZE);
|
||||
|
||||
let root = generate_trie(
|
||||
database.open(self.database_type),
|
||||
key_values,
|
||||
);
|
||||
let root = generate_trie(database.open(self.database_type), key_values);
|
||||
|
||||
Box::new(TrieWriteBenchmark {
|
||||
database,
|
||||
@@ -272,7 +264,8 @@ impl core::BenchmarkDescription for TrieWriteBenchmarkDescription {
|
||||
self.database_size,
|
||||
pretty_print(self.database_size.keys()),
|
||||
self.database_type,
|
||||
).into()
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,15 +285,13 @@ impl core::Benchmark for TrieWriteBenchmark {
|
||||
let mut new_root = self.root.clone();
|
||||
|
||||
let mut overlay = HashMap::new();
|
||||
let mut trie = SimpleTrie {
|
||||
db: kvdb.clone(),
|
||||
overlay: &mut overlay,
|
||||
};
|
||||
let mut trie_db_mut = TrieDBMut::from_existing(&mut trie, &mut new_root)
|
||||
.expect("Failed to create TrieDBMut");
|
||||
let mut trie = SimpleTrie { db: kvdb.clone(), overlay: &mut overlay };
|
||||
let mut trie_db_mut =
|
||||
TrieDBMut::from_existing(&mut trie, &mut new_root).expect("Failed to create TrieDBMut");
|
||||
|
||||
for (warmup_key, warmup_value) in self.warmup_keys.iter() {
|
||||
let value = trie_db_mut.get(&warmup_key[..])
|
||||
let value = trie_db_mut
|
||||
.get(&warmup_key[..])
|
||||
.expect("Failed to get key: db error")
|
||||
.expect("Warmup key should exist");
|
||||
|
||||
@@ -367,7 +358,9 @@ impl SizePool {
|
||||
|
||||
fn value<R: Rng>(&self, rng: &mut R) -> Vec<u8> {
|
||||
let sr = (rng.next_u64() % self.total as u64) as u32;
|
||||
let mut range = self.distribution.range((std::ops::Bound::Included(sr), std::ops::Bound::Unbounded));
|
||||
let mut range = self
|
||||
.distribution
|
||||
.range((std::ops::Bound::Included(sr), std::ops::Bound::Unbounded));
|
||||
let size = *range.next().unwrap().1 as usize;
|
||||
random_vec(rng, size)
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use node_testing::bench::{BenchDb, Profile, BlockType, KeyTypes, DatabaseType};
|
||||
use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile};
|
||||
|
||||
use sc_transaction_pool::BasicPool;
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sc_transaction_pool_api::{TransactionPool, TransactionSource};
|
||||
use sp_runtime::generic::BlockId;
|
||||
|
||||
use crate::core::{self, Path, Mode};
|
||||
use crate::core::{self, Mode, Path};
|
||||
|
||||
pub struct PoolBenchmarkDescription {
|
||||
pub database_type: DatabaseType,
|
||||
@@ -46,11 +46,7 @@ impl core::BenchmarkDescription for PoolBenchmarkDescription {
|
||||
|
||||
fn setup(self: Box<Self>) -> Box<dyn core::Benchmark> {
|
||||
Box::new(PoolBenchmark {
|
||||
database: BenchDb::with_key_types(
|
||||
self.database_type,
|
||||
50_000,
|
||||
KeyTypes::Sr25519,
|
||||
),
|
||||
database: BenchDb::with_key_types(self.database_type, 50_000, KeyTypes::Sr25519),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,7 +59,9 @@ impl core::Benchmark for PoolBenchmark {
|
||||
fn run(&mut self, mode: Mode) -> std::time::Duration {
|
||||
let context = self.database.create_context(Profile::Wasm);
|
||||
|
||||
let _ = context.client.runtime_version_at(&BlockId::Number(0))
|
||||
let _ = context
|
||||
.client
|
||||
.runtime_version_at(&BlockId::Number(0))
|
||||
.expect("Failed to get runtime version")
|
||||
.spec_version;
|
||||
|
||||
@@ -80,22 +78,20 @@ impl core::Benchmark for PoolBenchmark {
|
||||
context.client.clone(),
|
||||
);
|
||||
|
||||
let generated_transactions = self.database.block_content(
|
||||
BlockType::RandomTransfersKeepAlive.to_content(Some(100)),
|
||||
&context.client,
|
||||
).into_iter().collect::<Vec<_>>();
|
||||
let generated_transactions = self
|
||||
.database
|
||||
.block_content(
|
||||
BlockType::RandomTransfersKeepAlive.to_content(Some(100)),
|
||||
&context.client,
|
||||
)
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
let submissions = generated_transactions.into_iter().map(|tx| {
|
||||
txpool.submit_one(
|
||||
&BlockId::Number(0),
|
||||
TransactionSource::External,
|
||||
tx,
|
||||
)
|
||||
});
|
||||
futures::executor::block_on(
|
||||
futures::future::join_all(submissions)
|
||||
);
|
||||
let submissions = generated_transactions
|
||||
.into_iter()
|
||||
.map(|tx| txpool.submit_one(&BlockId::Number(0), TransactionSource::External, tx));
|
||||
futures::executor::block_on(futures::future::join_all(submissions));
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
if mode == Mode::Profile {
|
||||
|
||||
Reference in New Issue
Block a user