Fix leading zeroes bugs (#3763)

* remove two unneeded mut's

* ensure correct size for leading_zeros()
This commit is contained in:
John Tromp 2023-07-20 15:25:53 +02:00 committed by GitHub
parent b69f18d0a2
commit 399fb19c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 11 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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