diff --git a/src/rpc.rs b/src/rpc.rs index ec1dd5f..837b848 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -17,6 +17,7 @@ use serde::Serialize; #[derive(Clone)] pub(crate) struct MiningParams { pub(crate) pre_hash: H256, + pub(crate) rot: [u8; 4], pub(crate) parent_hash: H256, pub(crate) win_difficulty: U256, pub(crate) pow_difficulty: U256, @@ -183,9 +184,27 @@ impl MiningContext { pub_key.reverse(); let pub_key = ecies_ed25519::PublicKey::from_bytes(&pub_key).unwrap(); + let rot_hash = match self.p3d_params.algo { + AlgoType::Grid2dV3_1 | AlgoType::Grid2dV3a => pre_hash, + _ => parent_hash, + }; + + let mut r: [u8;32] = rot_hash.encode()[0..32].try_into().unwrap(); + if matches!(self.p3d_params.algo, AlgoType::Grid2dV3a) { + for a in r[3..].iter() { + // exclude rotation less than 20 + if *a > 20 { + r[3] = a.clone(); + break; + } + } + } + let rot: [u8; 4] = r[0..4].try_into().unwrap(); + let mut lock = self.cur_state.lock().unwrap(); (*lock) = Some(MiningParams { pre_hash, + rot, parent_hash, win_difficulty, pow_difficulty, diff --git a/src/worker.rs b/src/worker.rs index 7fd3026..5eb3097 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -1,5 +1,4 @@ use std::collections::HashSet; -use std::convert::TryInto; use std::f32::consts::PI; use std::fmt::Write; use std::str::FromStr; @@ -20,7 +19,7 @@ use rayon::prelude::*; use sha3::{Digest, Sha3_256}; use tokio::time; -use crate::rpc::{AlgoType, MiningObj, MiningProposal}; +use crate::rpc::{MiningObj, MiningProposal}; use super::MiningContext; use super::P3dParams; @@ -79,16 +78,11 @@ pub(crate) fn worker(ctx: &MiningContext) { let MiningParams { pre_hash, - parent_hash, + rot, win_difficulty, pow_difficulty, .. } = mining_params; - let rot_hash = match &algo { - AlgoType::Grid2dV3_1 | AlgoType::Grid2dV3a => pre_hash, - _ => parent_hash, - }; - let rot = rot_hash.encode()[0..4].try_into().ok(); let mining_obj: MiningObj = MiningObj { obj_id: 1, @@ -100,7 +94,7 @@ pub(crate) fn worker(ctx: &MiningContext) { algo.as_p3d_algo(), grid as i16, sect as i16, - rot, + Some(rot), ); let (first_hash, obj_hash, poscan_hash) = match res_hashes {