Skip to content

Commit

Permalink
Fix rotation for Grid2dV3a
Browse files Browse the repository at this point in the history
  • Loading branch information
MishK committed Jan 29, 2024
1 parent 5d917f3 commit 38eac1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 19 additions & 0 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 3 additions & 9 deletions src/worker.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 38eac1e

Please sign in to comment.