rm redundant get_difficulty calls
This commit is contained in:
parent
1b65c603bd
commit
9c837bf6a8
4 changed files with 17 additions and 6 deletions
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,8 +1,18 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.2.1
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- performance improvement: internally `get_difficulty` was being called
|
||||||
|
multiple times while generating `PoW`, now it calls only once.
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Difficulty factor is now an unsigned 32 bit number
|
||||||
|
|
||||||
## 0.1
|
## 0.1
|
||||||
|
|
||||||
|
### Added:
|
||||||
- PoW constructor
|
- PoW constructor
|
||||||
- unique salt
|
- unique salt
|
||||||
|
|
||||||
## 0.2
|
|
||||||
- Difficulty factor is now an unsigned 32 bit number
|
|
||||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -138,7 +138,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pow_sha256"
|
name = "pow_sha256"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pow_sha256"
|
name = "pow_sha256"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = [ "Aravinth Manivannan <realaravinth@bastsense.net>", "Robert Kornacki <robk@syre.io>"]
|
authors = [ "Aravinth Manivannan <realaravinth@bastsense.net>", "Robert Kornacki <robk@syre.io>"]
|
||||||
description = """
|
description = """
|
||||||
SHA256 PoW on any serializable datatype used in mCaptcha
|
SHA256 PoW on any serializable datatype used in mCaptcha
|
||||||
|
|
|
@ -69,7 +69,8 @@ impl Config {
|
||||||
let prefix_sha = Sha256::new().chain(&self.salt).chain(prefix);
|
let prefix_sha = Sha256::new().chain(&self.salt).chain(prefix);
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
let mut result = 0;
|
let mut result = 0;
|
||||||
while result < get_difficulty(difficulty) {
|
let difficulty = get_difficulty(difficulty);
|
||||||
|
while result < difficulty {
|
||||||
n += 1;
|
n += 1;
|
||||||
result = score(prefix_sha.clone(), n);
|
result = score(prefix_sha.clone(), n);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue