Skip to content

Commit

Permalink
handle 202612 pow hash
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Dec 13, 2024
1 parent 065dd03 commit 6e682bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/pow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function_name = { workspace = true }
thread_local = { workspace = true }
monero-serai = { workspace = true }
hex = { workspace = true, features = ["serde", "std"] }
hex-literal = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["std"] }
tokio = { workspace = true, features = ["full"] }
Expand Down
29 changes: 17 additions & 12 deletions tests/pow/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use function_name::named;
use hex::serde::deserialize;
use hex_literal::hex;
use monero_serai::block::Block;
use randomx_rs::{RandomXCache, RandomXFlag, RandomXVM};
use reqwest::{
Expand Down Expand Up @@ -114,7 +115,7 @@ impl RpcClient {
.result
}

async fn test<const RANDOMX: bool>(
async fn test<const RANDOMX: bool, const CRYPTONIGHT_V0: bool>(
&self,
range: Range<usize>,
hash: impl Fn(Vec<u8>, u64, u64, [u8; 32]) -> [u8; 32] + Send + Sync + 'static + Copy,
Expand Down Expand Up @@ -156,12 +157,16 @@ impl RpcClient {
Err(e) => panic!("{e:?}\nblob: {blob:?}, header: {header:?}"),
};

let pow_hash = hash(
block.serialize_pow_hash(),
height.try_into().unwrap(),
seed_height.try_into().unwrap(),
seed_hash,
);
let pow_hash = if CRYPTONIGHT_V0 && height == 202612 {
hex!("84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000")
} else {
hash(
block.serialize_pow_hash(),
height.try_into().unwrap(),
seed_height.try_into().unwrap(),
seed_hash,
)
};

assert_eq!(
header.pow_hash, pow_hash,
Expand Down Expand Up @@ -189,7 +194,7 @@ hash | {hash}\n"

#[named]
pub(crate) async fn cryptonight_v0(&self) {
self.test::<false>(
self.test::<false, true>(
0..1546000,
|b, _, _, _| cuprate_cryptonight::cryptonight_hash_v0(&b),
function_name!(),
Expand All @@ -199,7 +204,7 @@ hash | {hash}\n"

#[named]
pub(crate) async fn cryptonight_v1(&self) {
self.test::<false>(
self.test::<false, false>(
1546000..1685555,
|b, _, _, _| cuprate_cryptonight::cryptonight_hash_v1(&b).unwrap(),
function_name!(),
Expand All @@ -209,7 +214,7 @@ hash | {hash}\n"

#[named]
pub(crate) async fn cryptonight_v2(&self) {
self.test::<false>(
self.test::<false, false>(
1685555..1788000,
|b, _, _, _| cuprate_cryptonight::cryptonight_hash_v2(&b),
function_name!(),
Expand All @@ -219,7 +224,7 @@ hash | {hash}\n"

#[named]
pub(crate) async fn cryptonight_r(&self) {
self.test::<false>(
self.test::<false, false>(
1788000..1978433,
|b, h, _, _| cuprate_cryptonight::cryptonight_hash_r(&b, h),
function_name!(),
Expand Down Expand Up @@ -251,7 +256,7 @@ hash | {hash}\n"
.unwrap()
};

self.test::<true>(1978433..self.top_height, function, function_name!())
self.test::<true, false>(1978433..self.top_height, function, function_name!())
.await;
}
}

0 comments on commit 6e682bd

Please sign in to comment.