Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace restructure + criterion benchmarking #7

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 1 addition & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
[package]
name = "kaspa"
version = "0.1.0"
description = "Kaspa"
edition = "2021"
authors = ["Kaspa Developers"]

[workspace]
members = [
"core",
"wallet",
"wallet-cli",
"consensus",
"kaspad",
"wasm",
]


[dependencies]
tide = "0.16.0"
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }
# flow-server = {path="../flow-server"}
23 changes: 23 additions & 0 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "consensus"
version = "0.1.0"
description = "Kaspa consensus lib"
edition = "2021"
authors = ["Kaspa developers"]
include = [
"src/**/*.rs",
]

[dependencies]
async-std = "1.11.0"
regex = "1"
hex = "0.4.3"
thiserror = "1.0.31"
kaspa-core = {path="../core"}

[dev-dependencies]
criterion = "0.3.6"

[[bench]]
name = "hash_benchmarks"
harness = false
18 changes: 18 additions & 0 deletions consensus/benches/hash_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::str::FromStr;

extern crate consensus;
use consensus::model::api::hash::Hash;

/// Placeholder for actual benchmarks
pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Hash::from_str", |b| {
let hash_str = "8e40af02265360d59f4ecf9ae9ebf8f00a3118408f5a9cdcbcc9c0f93642f3af";
b.iter(|| {
Hash::from_str(black_box(hash_str)).unwrap();
})
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
6 changes: 6 additions & 0 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Until the codebase stables up, we will have a lot of these -- ignore for now
// TODO: remove this
#![allow(dead_code, unused_variables)]

pub mod model;
pub mod processes;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use hex;
use std::convert::TryInto;
use std::fmt::{Debug, Formatter};
use std::mem::size_of;
use std::str::FromStr;
Expand Down Expand Up @@ -67,14 +66,6 @@ impl Hash {
pub fn is_default(&self) -> bool {
self.eq(&Self::DEFAULT)
}

#[allow(dead_code)]
pub fn from_str_slow(hash_str: &str) -> Result<Self, hex::FromHexError> {
match hex::decode(hash_str)?.try_into() {
Ok(bytes) => Ok(Hash(bytes)),
Err(_) => Err(hex::FromHexError::InvalidStringLength),
}
}
}

#[cfg(test)]
Expand Down Expand Up @@ -124,30 +115,3 @@ mod tests {
// println!("{}", hash.to_string());
}
}

#[cfg(all(test, feature = "bench"))]
mod benches {
extern crate test;
use self::test::{black_box, Bencher};
use super::*;

#[bench]
pub fn bench_from_str_slow(bh: &mut Bencher) {
bh.iter(|| {
for _ in 0..1000 {
let hash_str = "8e40af02265360d59f4ecf9ae9ebf8f00a3118408f5a9cdcbcc9c0f93642f3af";
black_box(Hash::from_str_slow(hash_str).unwrap());
}
});
}

#[bench]
pub fn bench_from_str_fast(bh: &mut Bencher) {
bh.iter(|| {
for _ in 0..1000 {
let hash_str = "8e40af02265360d59f4ecf9ae9ebf8f00a3118408f5a9cdcbcc9c0f93642f3af";
black_box(Hash::from_str(hash_str).unwrap());
}
});
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use super::errors::StoreError;
use crate::domain::consensus::{model::api::hash::Hash, processes::reachability::interval::Interval};
use crate::{model::api::hash::Hash, processes::reachability::interval::Interval};

type HashArray = Rc<Vec<Hash>>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::domain::consensus::model::{
use crate::model::{
api::hash::Hash,
stores::{errors::StoreResult, reachability::ReachabilityStore},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::domain::consensus::model::{api::hash::Hash, stores::reachability::ReachabilityStore};
use crate::model::{api::hash::Hash, stores::reachability::ReachabilityStore};

pub fn init(store: &mut dyn ReachabilityStore) -> Result<()> {
todo!()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod reindex;

use thiserror::Error;

use crate::domain::consensus::model::stores::errors::StoreError;
use crate::model::stores::errors::StoreError;

#[derive(Error, Debug)]
pub enum ReachabilityError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{HashMap, VecDeque};

use super::*;
use crate::domain::consensus::model::{api::hash::Hash, stores::reachability::ReachabilityStore};
use crate::model::{api::hash::Hash, stores::reachability::ReachabilityStore};

const DEFAULT_REINDEX_DEPTH: u64 = 200;
const DEFAULT_REINDEX_SLACK: u64 = 1 << 12;
Expand Down Expand Up @@ -66,7 +66,6 @@ impl<'a> ReindexOperationContext<'a> {
/// and populates self.subtree_sizes with the results.
/// It is equivalent to the following recursive implementation:
///
/// ```
/// fn count_subtrees(&mut self, block: Hash) -> Result<u64> {
/// let mut subtree_size = 0u64;
/// for child in self.store.get_children(block)?.iter().cloned() {
Expand All @@ -75,7 +74,6 @@ impl<'a> ReindexOperationContext<'a> {
/// self.subtree_sizes.insert(block, subtree_size + 1);
/// Ok(subtree_size + 1)
/// }
/// ```
///
/// However, we are expecting (linearly) deep trees, and so a
/// recursive stack-based approach is inefficient and will hit
Expand Down Expand Up @@ -174,9 +172,7 @@ impl<'a> ReindexOperationContext<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::domain::consensus::{
model::stores::reachability::MemoryReachabilityStore, processes::reachability::interval::Interval,
};
use crate::{model::stores::reachability::MemoryReachabilityStore, processes::reachability::interval::Interval};

struct StoreBuilder<'a> {
store: &'a mut dyn ReachabilityStore,
Expand Down
16 changes: 16 additions & 0 deletions consensus/tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extern crate consensus;

use consensus::model::api::hash::Hash;
use consensus::processes::reachability::interval;
use std::str::FromStr;

/// Placeholder for actual integration tests
#[test]
fn integration_test() {
let interval = interval::Interval::maximal();
println!("{:?}", interval);

let hash_str = "8e40af02265360d59f4ecf9ae9ebf8f00a3118408f5a9cdcbcc9c0f93642f3af";
let hash = Hash::from_str(hash_str).unwrap();
println!("{:?}", hash);
}
6 changes: 3 additions & 3 deletions kaspad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[package]
name = "kaspad"
version = "0.1.0"
description = "Kaspa full node daemon"
edition = "2021"
authors = ["Kaspa developers"]
include = [
"src/**/*.rs",
]
Expand All @@ -12,6 +14,4 @@ regex = "1"
hex = "0.4.3"
thiserror = "1.0.31"
kaspa-core = {path="../core"}

[features]
bench = []
consensus = {path="../consensus"}
2 changes: 0 additions & 2 deletions kaspad/src/domain/consensus/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion kaspad/src/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod consensus;

21 changes: 3 additions & 18 deletions kaspad/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#![cfg_attr(all(test, feature = "bench"), feature(test))]
// Until the codebase stables up, we will have a lot of these -- ignore for now
// TODO: remove this
#![allow(dead_code, unused_variables)]

extern crate consensus;
extern crate core;

use std::str::FromStr;
use std::sync::atomic::AtomicU64;
use std::sync::Arc;

Expand All @@ -14,9 +9,6 @@ use kaspa_core::*;

mod domain;

use domain::consensus::model::api::hash::Hash;
use domain::consensus::processes::reachability::interval;

const SERVICE_THREADS: usize = 1;
// if sleep time is < 0, sleep is skipped
const EMITTER_SLEEP_TIME_MSEC: i64 = -1;
Expand All @@ -25,13 +17,6 @@ const EMITTER_SLEEP_TIME_MSEC: i64 = -1;
pub fn main() {
trace!("Kaspad starting...");

let interval = interval::Interval::maximal();
println!("{:?}", interval);

let hash_str = "8e40af02265360d59f4ecf9ae9ebf8f00a3118408f5a9cdcbcc9c0f93642f3af";
let hash = Hash::from_str(hash_str).unwrap();
println!("{:?}", hash);

let core = Arc::new(Core::new());
let signals = Arc::new(signals::Signals::new(core.clone()));
signals.init();
Expand All @@ -45,13 +30,13 @@ pub fn main() {
// monitor thread dumping message counters
let monitor = Arc::new(monitor::Monitor::new(send_count.clone(), recv_count.clone()));

let consumer = Arc::new(test_consumer::TestConsumer::new("consumer", recv_count.clone()));
let consumer = Arc::new(test_consumer::TestConsumer::new("consumer", recv_count));
let service = Arc::new(test_service::TestService::new("service", SERVICE_THREADS, consumer.sender().clone()));
let emitter = Arc::new(test_emitter::TestEmitter::new(
"emitter",
EMITTER_SLEEP_TIME_MSEC,
service.sender().clone(),
send_count.clone(),
send_count,
));

// signals.bind(&core);
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs

This file was deleted.

21 changes: 0 additions & 21 deletions wallet-cli/Cargo.toml

This file was deleted.

24 changes: 0 additions & 24 deletions wallet-cli/src/main.rs

This file was deleted.