rm redundant get_difficulty calls

This commit is contained in:
Aravinth Manivannan 2021-03-31 17:40:15 +05:30
parent 1b65c603bd
commit 9c837bf6a8
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
4 changed files with 17 additions and 6 deletions

View file

@ -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
View file

@ -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",

View file

@ -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

View file

@ -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);
} }