Skip to content

Commit

Permalink
Fix leading zeroes bugs (#3763)
Browse files Browse the repository at this point in the history
* remove two unneeded mut's

* ensure correct size for leading_zeros()
  • Loading branch information
tromp committed Jul 20, 2023
1 parent b69f18d commit 399fb19
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/src/config.rs
Expand Up @@ -161,7 +161,7 @@ impl GlobalConfig {
/// apply defaults for each chain type
pub fn for_chain(chain_type: &global::ChainTypes) -> GlobalConfig {
let mut defaults_conf = GlobalConfig::default();
let mut defaults = &mut defaults_conf.members.as_mut().unwrap().server;
let defaults = &mut defaults_conf.members.as_mut().unwrap().server;
defaults.chain_type = chain_type.clone();

match *chain_type {
Expand Down
4 changes: 2 additions & 2 deletions core/src/pow/cuckaroo.rs
Expand Up @@ -70,8 +70,8 @@ impl PoWContext for CuckarooContext {
let mut uvs = vec![0u64; 2 * size];
let mut xor0: u64 = 0;
let mut xor1: u64 = 0;
let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1
// the next three arrays form a linked list of nodes with matching bits 6..1
let mask = u64::MAX >> (size as u64).leading_zeros(); // round size up to 2-power - 1
// the next three arrays form a linked list of nodes with matching bits 6..1
let mut headu = vec![2 * size; 1 + mask as usize];
let mut headv = vec![2 * size; 1 + mask as usize];
let mut prev = vec![0usize; 2 * size];
Expand Down
4 changes: 2 additions & 2 deletions core/src/pow/cuckarood.rs
Expand Up @@ -65,8 +65,8 @@ impl PoWContext for CuckaroodContext {
let mut ndir = vec![0usize; 2];
let mut xor0: u64 = 0;
let mut xor1: u64 = 0;
let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 4..0|dir
let mask = u64::MAX >> (size as u64).leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 4..0|dir
let mut headu = vec![2 * size; 1 + mask as usize];
let mut headv = vec![2 * size; 1 + mask as usize];
let mut prev = vec![0usize; 2 * size];
Expand Down
4 changes: 2 additions & 2 deletions core/src/pow/cuckaroom.rs
Expand Up @@ -64,8 +64,8 @@ impl PoWContext for CuckaroomContext {
let mut to = vec![0u64; size];
let mut xor_from: u64 = 0;
let mut xor_to: u64 = 0;
let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 6..1
let mask = u64::MAX >> (size as u64).leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 6..1
let mut head = vec![size; 1 + mask as usize];
let mut prev = vec![0usize; size];

Expand Down
4 changes: 2 additions & 2 deletions core/src/pow/cuckarooz.rs
Expand Up @@ -63,8 +63,8 @@ impl PoWContext for CuckaroozContext {
let nonces = &proof.nonces;
let mut uvs = vec![0u64; 2 * size];
let mut xoruv: u64 = 0;
let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 6..1
let mask = u64::MAX >> (size as u64).leading_zeros(); // round size up to 2-power - 1
// the next two arrays form a linked list of nodes with matching bits 6..1
let mut head = vec![2 * size; 1 + mask as usize];
let mut prev = vec![0usize; 2 * size];

Expand Down
2 changes: 1 addition & 1 deletion core/src/pow/cuckatoo.rs
Expand Up @@ -261,7 +261,7 @@ impl CuckatooContext {
}
let nonces = &proof.nonces;
let mut uvs = vec![0u64; 2 * size];
let mask = u64::MAX >> size.leading_zeros(); // round size up to 2-power - 1
let mask = u64::MAX >> (size as u64).leading_zeros(); // round size up to 2-power - 1
let mut xor0: u64 = (size as u64 / 2) & 1;
let mut xor1: u64 = xor0;
// the next two arrays form a linked list of nodes with matching bits 6..1
Expand Down
2 changes: 1 addition & 1 deletion servers/src/mining/stratumserver.rs
Expand Up @@ -729,7 +729,7 @@ impl WorkersList {

pub fn login(&self, worker_id: usize, login: String, agent: String) -> Result<(), RpcError> {
let mut wl = self.workers_list.write();
let mut worker = wl
let worker = wl
.get_mut(&worker_id)
.ok_or_else(RpcError::internal_error)?;
worker.login = Some(login);
Expand Down

0 comments on commit 399fb19

Please sign in to comment.