Przeglądaj źródła

darkfid/stratum: Pad target and send 8 MSB

x 7 miesięcy temu
rodzic
commit
61a7077956
1 zmienionych plików z 6 dodań i 2 usunięć
  1. 6 2
      bin/darkfid/src/registry/model.rs

+ 6 - 2
bin/darkfid/src/registry/model.rs

@@ -248,8 +248,12 @@ pub async fn generate_next_block_template(
     // Grab forks' next mine target and difficulty
     // Grab forks' next mine target and difficulty
     let (target, difficulty) = extended_fork.module.next_mine_target_and_difficulty()?;
     let (target, difficulty) = extended_fork.module.next_mine_target_and_difficulty()?;
 
 
-    // The target should be compacted to 8 bytes little-endian.
-    let target = target.to_bytes_le()[..8].to_vec();
+    // The target should be compacted to 8 bytes. We'll send the MSB.
+    let target_bytes = target.to_bytes_le();
+    let mut padded = [0u8; 32];
+    let len = target_bytes.len().min(32);
+    padded[..len].copy_from_slice(&target_bytes[..len]);
+    let target = padded[24..32].to_vec();
 
 
     // Cast difficulty to f64. This should always work.
     // Cast difficulty to f64. This should always work.
     let difficulty = difficulty.to_string().parse()?;
     let difficulty = difficulty.to_string().parse()?;