Skip to content

Commit 2870655

Browse files
committed
RandomXVM -> RandomXVm
1 parent e3b6c1c commit 2870655

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

consensus/src/block/alt_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
block::{free::pull_ordered_transactions, PreparedBlock},
2525
context::{
2626
difficulty::DifficultyCache,
27-
rx_vms::RandomXVM,
27+
rx_vms::RandomXVm,
2828
weight::{self, BlockWeightsCache},
2929
AltChainContextCache, AltChainRequestToken, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW,
3030
},
@@ -195,7 +195,7 @@ async fn alt_rx_vm<C>(
195195
parent_chain: Chain,
196196
alt_chain_context: &mut AltChainContextCache,
197197
context_svc: C,
198-
) -> Result<Option<Arc<RandomXVM>>, ExtendedConsensusError>
198+
) -> Result<Option<Arc<RandomXVm>>, ExtendedConsensusError>
199199
where
200200
C: Service<
201201
BlockChainContextRequest,

consensus/src/block/batch_prepare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cuprate_helper::asynch::rayon_spawn_async;
1515

1616
use crate::{
1717
block::{free::pull_ordered_transactions, PreparedBlock, PreparedBlockExPow},
18-
context::rx_vms::RandomXVM,
18+
context::rx_vms::RandomXVm,
1919
transactions::new_tx_verification_data,
2020
BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError,
2121
VerifyBlockResponse,
@@ -148,7 +148,7 @@ where
148148
tracing::debug!("New randomX seed in batch, initialising VM");
149149

150150
let new_vm = rayon_spawn_async(move || {
151-
Arc::new(RandomXVM::new(&new_vm_seed).expect("RandomX VM gave an error on set up!"))
151+
Arc::new(RandomXVm::new(&new_vm_seed).expect("RandomX VM gave an error on set up!"))
152152
})
153153
.await;
154154

consensus/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod tokens;
3333

3434
use cuprate_types::Chain;
3535
use difficulty::DifficultyCache;
36-
use rx_vms::RandomXVM;
36+
use rx_vms::RandomXVm;
3737
use weight::BlockWeightsCache;
3838

3939
pub(crate) use alt_chains::{sealed::AltChainRequestToken, AltChainContextCache};
@@ -236,7 +236,7 @@ pub enum BlockChainContextRequest {
236236
/// seed.
237237
///
238238
/// This should include the seed used to init this VM and the VM.
239-
NewRXVM(([u8; 32], Arc<RandomXVM>)),
239+
NewRXVM(([u8; 32], Arc<RandomXVm>)),
240240
/// A request to add a new block to the cache.
241241
Update(NewBlockData),
242242
/// Pop blocks from the cache to the specified height.
@@ -313,15 +313,15 @@ pub enum BlockChainContextResponse {
313313
/// Blockchain context response.
314314
Context(BlockChainContext),
315315
/// A map of seed height to RandomX VMs.
316-
RxVms(HashMap<usize, Arc<RandomXVM>>),
316+
RxVms(HashMap<usize, Arc<RandomXVm>>),
317317
/// A list of difficulties.
318318
BatchDifficulties(Vec<u128>),
319319
/// An alt chain context cache.
320320
AltChainContextCache(Box<AltChainContextCache>),
321321
/// A difficulty cache for an alt chain.
322322
AltChainDifficultyCache(DifficultyCache),
323323
/// A randomX VM for an alt chain.
324-
AltChainRxVM(Arc<RandomXVM>),
324+
AltChainRxVM(Arc<RandomXVm>),
325325
/// A weight cache for an alt chain
326326
AltChainWeightCache(BlockWeightsCache),
327327
/// A generic Ok response.

consensus/src/context/alt_chains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use cuprate_types::{
1111
use crate::{
1212
ExtendedConsensusError,
1313
__private::Database,
14-
context::{difficulty::DifficultyCache, rx_vms::RandomXVM, weight::BlockWeightsCache},
14+
context::{difficulty::DifficultyCache, rx_vms::RandomXVm, weight::BlockWeightsCache},
1515
};
1616

1717
pub(crate) mod sealed {
@@ -32,7 +32,7 @@ pub struct AltChainContextCache {
3232
pub difficulty_cache: Option<DifficultyCache>,
3333

3434
/// A cached RX VM.
35-
pub cached_rx_vm: Option<(usize, Arc<RandomXVM>)>,
35+
pub cached_rx_vm: Option<(usize, Arc<RandomXVm>)>,
3636

3737
/// The chain height of the alt chain.
3838
pub chain_height: usize,

consensus/src/context/rx_vms.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
};
1010

1111
use futures::{stream::FuturesOrdered, StreamExt};
12-
use randomx_rs::{RandomXCache, RandomXError, RandomXFlag, RandomXVM as VMInner};
12+
use randomx_rs::{RandomXCache, RandomXError, RandomXFlag, RandomXVM as VmInner};
1313
use rayon::prelude::*;
1414
use thread_local::ThreadLocal;
1515
use tower::ServiceExt;
@@ -33,37 +33,37 @@ const RX_SEEDS_CACHED: usize = 2;
3333

3434
/// A multithreaded randomX VM.
3535
#[derive(Debug)]
36-
pub struct RandomXVM {
36+
pub struct RandomXVm {
3737
/// These RandomX VMs all share the same cache.
38-
vms: ThreadLocal<VMInner>,
38+
vms: ThreadLocal<VmInner>,
3939
/// The RandomX cache.
4040
cache: RandomXCache,
4141
/// The flags used to start the RandomX VMs.
4242
flags: RandomXFlag,
4343
}
4444

45-
impl RandomXVM {
45+
impl RandomXVm {
4646
/// Create a new multithreaded randomX VM with the provided seed.
4747
pub fn new(seed: &[u8; 32]) -> Result<Self, RandomXError> {
4848
// TODO: allow passing in flags.
4949
let flags = RandomXFlag::get_recommended_flags();
5050

5151
let cache = RandomXCache::new(flags, seed.as_slice())?;
5252

53-
Ok(RandomXVM {
53+
Ok(RandomXVm {
5454
vms: ThreadLocal::new(),
5555
cache,
5656
flags,
5757
})
5858
}
5959
}
6060

61-
impl RandomX for RandomXVM {
61+
impl RandomX for RandomXVm {
6262
type Error = RandomXError;
6363

6464
fn calculate_hash(&self, buf: &[u8]) -> Result<[u8; 32], Self::Error> {
6565
self.vms
66-
.get_or_try(|| VMInner::new(self.flags, Some(self.cache.clone()), None))?
66+
.get_or_try(|| VmInner::new(self.flags, Some(self.cache.clone()), None))?
6767
.calculate_hash(buf)
6868
.map(|out| out.try_into().unwrap())
6969
}
@@ -72,17 +72,17 @@ impl RandomX for RandomXVM {
7272
/// The randomX VMs cache, keeps the VM needed to calculate the current block's PoW hash (if a VM is needed) and a
7373
/// couple more around this VM.
7474
#[derive(Clone, Debug)]
75-
pub struct RandomXVMCache {
75+
pub struct RandomXVmCache {
7676
/// The top [`RX_SEEDS_CACHED`] RX seeds.
7777
pub(crate) seeds: VecDeque<(usize, [u8; 32])>,
7878
/// The VMs for `seeds` (if after hf 12, otherwise this will be empty).
79-
pub(crate) vms: HashMap<usize, Arc<RandomXVM>>,
79+
pub(crate) vms: HashMap<usize, Arc<RandomXVm>>,
8080

8181
/// A single cached VM that was given to us from a part of Cuprate.
82-
pub(crate) cached_vm: Option<([u8; 32], Arc<RandomXVM>)>,
82+
pub(crate) cached_vm: Option<([u8; 32], Arc<RandomXVm>)>,
8383
}
8484

85-
impl RandomXVMCache {
85+
impl RandomXVmCache {
8686
#[instrument(name = "init_rx_vm_cache", level = "info", skip(database))]
8787
pub async fn init_from_chain_height<D: Database + Clone>(
8888
chain_height: usize,
@@ -106,7 +106,7 @@ impl RandomXVMCache {
106106
.map(|(height, seed)| {
107107
(
108108
*height,
109-
Arc::new(RandomXVM::new(seed).expect("Failed to create RandomX VM!")),
109+
Arc::new(RandomXVm::new(seed).expect("Failed to create RandomX VM!")),
110110
)
111111
})
112112
.collect()
@@ -117,15 +117,15 @@ impl RandomXVMCache {
117117
HashMap::new()
118118
};
119119

120-
Ok(RandomXVMCache {
120+
Ok(RandomXVmCache {
121121
seeds,
122122
vms,
123123
cached_vm: None,
124124
})
125125
}
126126

127127
/// Add a randomX VM to the cache, with the seed it was created with.
128-
pub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVM>)) {
128+
pub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVm>)) {
129129
self.cached_vm.replace(vm);
130130
}
131131

@@ -136,7 +136,7 @@ impl RandomXVMCache {
136136
height: usize,
137137
chain: Chain,
138138
database: D,
139-
) -> Result<Arc<RandomXVM>, ExtendedConsensusError> {
139+
) -> Result<Arc<RandomXVm>, ExtendedConsensusError> {
140140
let seed_height = randomx_seed_height(height);
141141

142142
let BlockchainResponse::BlockHash(seed_hash) = database
@@ -156,13 +156,13 @@ impl RandomXVMCache {
156156
}
157157
}
158158

159-
let alt_vm = rayon_spawn_async(move || Arc::new(RandomXVM::new(&seed_hash).unwrap())).await;
159+
let alt_vm = rayon_spawn_async(move || Arc::new(RandomXVm::new(&seed_hash).unwrap())).await;
160160

161161
Ok(alt_vm)
162162
}
163163

164164
/// Get the main-chain RandomX VMs.
165-
pub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVM>> {
165+
pub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVm>> {
166166
match self.seeds.len().checked_sub(self.vms.len()) {
167167
// No difference in the amount of seeds to VMs.
168168
Some(0) => (),
@@ -184,7 +184,7 @@ impl RandomXVMCache {
184184
}
185185
};
186186

187-
rayon_spawn_async(move || Arc::new(RandomXVM::new(&next_seed_hash).unwrap()))
187+
rayon_spawn_async(move || Arc::new(RandomXVm::new(&next_seed_hash).unwrap()))
188188
.await
189189
};
190190

@@ -200,7 +200,7 @@ impl RandomXVMCache {
200200
seeds_clone
201201
.par_iter()
202202
.map(|(height, seed)| {
203-
let vm = RandomXVM::new(seed).expect("Failed to create RandomX VM!");
203+
let vm = RandomXVm::new(seed).expect("Failed to create RandomX VM!");
204204
let vm = Arc::new(vm);
205205
(*height, vm)
206206
})

consensus/src/context/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct ContextTask<D: Database> {
4545
/// The weight cache.
4646
weight_cache: weight::BlockWeightsCache,
4747
/// The RX VM cache.
48-
rx_vm_cache: rx_vms::RandomXVMCache,
48+
rx_vm_cache: rx_vms::RandomXVmCache,
4949
/// The hard-fork state cache.
5050
hardfork_state: hardforks::HardForkState,
5151

@@ -127,7 +127,7 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
127127

128128
let db = database.clone();
129129
let rx_seed_handle = tokio::spawn(async move {
130-
rx_vms::RandomXVMCache::init_from_chain_height(chain_height, &current_hf, db).await
130+
rx_vms::RandomXVmCache::init_from_chain_height(chain_height, &current_hf, db).await
131131
});
132132

133133
let context_svc = ContextTask {

consensus/src/tests/context/rx_vms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cuprate_consensus_rules::{
99
};
1010

1111
use crate::{
12-
context::rx_vms::{get_last_rx_seed_heights, RandomXVMCache},
12+
context::rx_vms::{get_last_rx_seed_heights, RandomXVmCache},
1313
tests::mock_db::*,
1414
};
1515

@@ -42,7 +42,7 @@ fn rx_heights_consistent() {
4242
async fn rx_vm_created_on_hf_12() {
4343
let db = DummyDatabaseBuilder::default().finish(Some(10));
4444

45-
let mut cache = RandomXVMCache::init_from_chain_height(10, &HardFork::V11, db)
45+
let mut cache = RandomXVmCache::init_from_chain_height(10, &HardFork::V11, db)
4646
.await
4747
.unwrap();
4848

@@ -67,7 +67,7 @@ proptest! {
6767
let rt = Builder::new_multi_thread().enable_all().build().unwrap();
6868

6969
rt.block_on(async move {
70-
let cache = RandomXVMCache::init_from_chain_height(10, &hf, db).await.unwrap();
70+
let cache = RandomXVmCache::init_from_chain_height(10, &hf, db).await.unwrap();
7171
assert!(cache.seeds.len() == cache.vms.len() || hf < HardFork::V12);
7272
});
7373
}

0 commit comments

Comments
 (0)