-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor scoring PoWs and deprecate old hash functions (#826)
* Store hash functions for POW internally * Formatting and usage in `miner` * Clarify intent * Start deprecating Bee's `CurlP` wrapper * Get `iota-crypto` directly from git repo * Patch `bee-ternary` to local version * Switch `CurlP` in benchmarks * Deprecation notices * Formatting * More Formatting * Include benchmark to compare legacy/new * Provide `PoWScorer::default` * Reorganize imports * Formatting * Add changelog entries * Allow deprecation * Update changelog * Small change to changelog * Bump `iota-crypto` version * Deprecated `Kerl` * Toying around with counting allocations * Add script the count number of allocations * Switch `UnrolledCurlP81` for performance reasons * Formatting * Deprecate all the things * Draft releases for `bee-crypto` and `bee-pow` * Deprecate `Sponge` and `SpongeKind` * Formatting * Update bee-pow/Cargo.toml Co-authored-by: Thibault Martinez <thibault.martinez.30@gmail.com> * Put allocation example into `bee-pow` * Revert "Put allocation example into `bee-pow`" This reverts commit b7e9036. * Update changelogs * Get rid of conflict * Use correct version of `iota-crypto` * Bump `iota-crypto` version * Deprecate more things * Get rid of warnings * Make PR nicer to review 😄 * More cleanup * More clean up * More cleanup * Reduce commit size * Final fixes * Bump version of `iota-crypto` * Review comments * Date * Thanks @Alex6323 Co-authored-by: Thibault Martinez <thibault.martinez.30@gmail.com>
- Loading branch information
1 parent
5e3c86e
commit 9ce096c
Showing
38 changed files
with
251 additions
and
63 deletions.
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2020-2021 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! This script aims at counting the number of allocations that are performed when we score the Proof of Work of a | ||
//! message by wrapping `GlobalAlloc`. Ideally, this method should not allocate at all, which would lead to a better | ||
//! performance. | ||
//! | ||
//! The code was adapted from: https://kanejaku.org/posts/2021/01/2021-01-27/ (CC-BY 4.0) | ||
|
||
use bee_common::packable::Packable; | ||
use bee_message::prelude::*; | ||
use bee_pow::{ | ||
providers::{miner::MinerBuilder, NonceProviderBuilder}, | ||
score::PoWScorer, | ||
}; | ||
use bee_test::rand::parents::rand_parents; | ||
|
||
use std::{ | ||
alloc::{GlobalAlloc, Layout, System}, | ||
sync::atomic::{AtomicUsize, Ordering::SeqCst}, | ||
}; | ||
|
||
struct CheckAlloc; | ||
|
||
static ALLOCATED: AtomicUsize = AtomicUsize::new(0); | ||
|
||
unsafe impl GlobalAlloc for CheckAlloc { | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
ALLOCATED.fetch_add(1, SeqCst); | ||
System.alloc(layout) | ||
} | ||
|
||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { | ||
System.dealloc(ptr, layout); | ||
} | ||
} | ||
|
||
#[global_allocator] | ||
static A: CheckAlloc = CheckAlloc; | ||
|
||
fn main() { | ||
let message = MessageBuilder::new() | ||
.with_network_id(0) | ||
.with_parents(rand_parents()) | ||
.with_nonce_provider(MinerBuilder::new().with_num_workers(num_cpus::get()).finish(), 10000f64) | ||
.finish() | ||
.unwrap(); | ||
|
||
let message_bytes = message.pack_new(); | ||
|
||
let before_count = ALLOCATED.load(SeqCst); | ||
let _score = PoWScorer::new().score(&message_bytes); | ||
let after_count = ALLOCATED.load(SeqCst); | ||
|
||
println!("Number of allocations: {}", after_count - before_count); | ||
} |
This file contains 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 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.