diff --git a/Cargo.toml b/Cargo.toml index 20ce425e9..2dcf71529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,6 +175,7 @@ validator = [ "randomx", "smol", + "system", "wasm-runtime", ] @@ -257,6 +258,7 @@ rpc = [ ] system = [ + "futures", "pin-project-lite", "rand", "smol", diff --git a/src/validator/mod.rs b/src/validator/mod.rs index e7d60e6cc..4a1a1d87b 100644 --- a/src/validator/mod.rs +++ b/src/validator/mod.rs @@ -43,6 +43,9 @@ use consensus::{Consensus, Fork, Proposal}; pub mod pow; use pow::PoWModule; +/// RandomX infrastructure +pub mod randomx_factory; + /// Monero infrastructure pub mod xmr; diff --git a/src/validator/pow.rs b/src/validator/pow.rs index 041151d6e..47414a250 100644 --- a/src/validator/pow.rs +++ b/src/validator/pow.rs @@ -37,7 +37,7 @@ use crate::{ Blockchain, BlockchainOverlayPtr, }, util::{ringbuffer::RingBuffer, time::Timestamp}, - validator::utils::median, + validator::{randomx_factory::init_dataset_wrapper, utils::median}, Error, Result, }; @@ -380,9 +380,9 @@ pub fn mine_block( let dataset = if threads > 1 { let a = (dataset_item_count * (t as u32)) / (threads as u32); let b = (dataset_item_count * (t as u32 + 1)) / (threads as u32); - RandomXDataset::new(flags, cache.clone(), a, b - a)? + init_dataset_wrapper(flags, cache.clone(), a, b - a)? } else { - RandomXDataset::new(flags, cache.clone(), 0, dataset_item_count)? + init_dataset_wrapper(flags, cache.clone(), 0, dataset_item_count)? }; let stop_signal = stop_signal.clone(); diff --git a/src/validator/randomx.rs b/src/validator/randomx_factory.rs similarity index 88% rename from src/validator/randomx.rs rename to src/validator/randomx_factory.rs index 9f8352819..d0b02fac7 100644 --- a/src/validator/randomx.rs +++ b/src/validator/randomx_factory.rs @@ -29,6 +29,26 @@ use randomx::{RandomXCache, RandomXDataset, RandomXFlags, RandomXVM}; use crate::Result; +/// Wrapper for creating a [`RandomXDataset`] +pub fn init_dataset_wrapper( + flags: RandomXFlags, + cache: RandomXCache, + start_item: u32, + item_count: u32, + /* priority: i32, */ +) -> Result { + /* set_thread_priority(priority); */ + + /* + if (is_x86_feature_detected!("avx2") && item_count % 5) { + let dataset = RandomXDataset::new(flags, cache, start_item, item_count - (item_count % 5))?; + let dataset = RandomXDataset::new(flags, cache, start_item + item_count - 5, 5)?; + } + */ + + Ok(RandomXDataset::new(flags, cache, start_item, item_count)?) +} + /// The RandomX virtual machine instance used to verify mining. #[derive(Clone)] pub struct RandomXVMInstance { @@ -56,7 +76,7 @@ impl RandomXVMInstance { Err(err) => { warn!( target: "validator::randomx", - "[VALIDATOR] Error initializing RandomX cache with flags {:?}: {}" + "[VALIDATOR] Error initializing RandomX cache with flags {:?}: {}", flags, err, ); warn!( @@ -77,7 +97,7 @@ impl RandomXVMInstance { /// Calculate the RandomX mining hash pub fn calculate_hash(&self, input: &[u8]) -> Result> { - let lock = self.instance.write()?; + let lock = self.instance.write().unwrap(); Ok(lock.calculate_hash(input)?) } } @@ -119,7 +139,7 @@ impl RandomXFactory { ) -> Result { let res; { - let mut inner = self.inner.write()?; + let mut inner = self.inner.write().unwrap(); res = inner.create(key, cache, dataset)?; } Ok(res) @@ -127,13 +147,13 @@ impl RandomXFactory { /// Get the number of VMs currently allocated pub fn get_count(&self) -> Result { - let inner = self.inner.read()?; + let inner = self.inner.read().unwrap(); Ok(inner.get_count()) } /// Get the flags used to create the VMs pub fn get_flags(&self) -> Result { - let inner = self.inner.read()?; + let inner = self.inner.read().unwrap(); Ok(inner.get_flags()) } }