mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 03:29:30 +00:00
workspace: add naming convention lints (#261)
* add lint to {Cargo,clippy}.toml * `RandomXVM` -> `RandomXVm` * epee: `TT` -> `T2`
This commit is contained in:
parent
bec8cc0aa4
commit
b837d350a4
10 changed files with 40 additions and 37 deletions
|
@ -262,6 +262,7 @@ empty_structs_with_brackets = "deny"
|
|||
empty_enum_variants_with_brackets = "deny"
|
||||
empty_drop = "deny"
|
||||
clone_on_ref_ptr = "deny"
|
||||
upper_case_acronyms = "deny"
|
||||
|
||||
# Hot
|
||||
# inline_always = "deny"
|
||||
|
@ -309,6 +310,7 @@ let_underscore_drop = "deny"
|
|||
unreachable_pub = "deny"
|
||||
unused_qualifications = "deny"
|
||||
variant_size_differences = "deny"
|
||||
non_camel_case_types = "deny"
|
||||
|
||||
# Hot
|
||||
# unused_results = "deny"
|
||||
|
|
1
clippy.toml
Normal file
1
clippy.toml
Normal file
|
@ -0,0 +1 @@
|
|||
upper-case-acronyms-aggressive = true
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
block::{free::pull_ordered_transactions, PreparedBlock},
|
||||
context::{
|
||||
difficulty::DifficultyCache,
|
||||
rx_vms::RandomXVM,
|
||||
rx_vms::RandomXVm,
|
||||
weight::{self, BlockWeightsCache},
|
||||
AltChainContextCache, AltChainRequestToken, BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW,
|
||||
},
|
||||
|
@ -195,7 +195,7 @@ async fn alt_rx_vm<C>(
|
|||
parent_chain: Chain,
|
||||
alt_chain_context: &mut AltChainContextCache,
|
||||
context_svc: C,
|
||||
) -> Result<Option<Arc<RandomXVM>>, ExtendedConsensusError>
|
||||
) -> Result<Option<Arc<RandomXVm>>, ExtendedConsensusError>
|
||||
where
|
||||
C: Service<
|
||||
BlockChainContextRequest,
|
||||
|
|
|
@ -15,7 +15,7 @@ use cuprate_helper::asynch::rayon_spawn_async;
|
|||
|
||||
use crate::{
|
||||
block::{free::pull_ordered_transactions, PreparedBlock, PreparedBlockExPow},
|
||||
context::rx_vms::RandomXVM,
|
||||
context::rx_vms::RandomXVm,
|
||||
transactions::new_tx_verification_data,
|
||||
BlockChainContextRequest, BlockChainContextResponse, ExtendedConsensusError,
|
||||
VerifyBlockResponse,
|
||||
|
@ -148,7 +148,7 @@ where
|
|||
tracing::debug!("New randomX seed in batch, initialising VM");
|
||||
|
||||
let new_vm = rayon_spawn_async(move || {
|
||||
Arc::new(RandomXVM::new(&new_vm_seed).expect("RandomX VM gave an error on set up!"))
|
||||
Arc::new(RandomXVm::new(&new_vm_seed).expect("RandomX VM gave an error on set up!"))
|
||||
})
|
||||
.await;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ mod tokens;
|
|||
|
||||
use cuprate_types::Chain;
|
||||
use difficulty::DifficultyCache;
|
||||
use rx_vms::RandomXVM;
|
||||
use rx_vms::RandomXVm;
|
||||
use weight::BlockWeightsCache;
|
||||
|
||||
pub(crate) use alt_chains::{sealed::AltChainRequestToken, AltChainContextCache};
|
||||
|
@ -236,7 +236,7 @@ pub enum BlockChainContextRequest {
|
|||
/// seed.
|
||||
///
|
||||
/// This should include the seed used to init this VM and the VM.
|
||||
NewRXVM(([u8; 32], Arc<RandomXVM>)),
|
||||
NewRXVM(([u8; 32], Arc<RandomXVm>)),
|
||||
/// A request to add a new block to the cache.
|
||||
Update(NewBlockData),
|
||||
/// Pop blocks from the cache to the specified height.
|
||||
|
@ -313,7 +313,7 @@ pub enum BlockChainContextResponse {
|
|||
/// Blockchain context response.
|
||||
Context(BlockChainContext),
|
||||
/// A map of seed height to RandomX VMs.
|
||||
RxVms(HashMap<usize, Arc<RandomXVM>>),
|
||||
RxVms(HashMap<usize, Arc<RandomXVm>>),
|
||||
/// A list of difficulties.
|
||||
BatchDifficulties(Vec<u128>),
|
||||
/// An alt chain context cache.
|
||||
|
@ -321,7 +321,7 @@ pub enum BlockChainContextResponse {
|
|||
/// A difficulty cache for an alt chain.
|
||||
AltChainDifficultyCache(DifficultyCache),
|
||||
/// A randomX VM for an alt chain.
|
||||
AltChainRxVM(Arc<RandomXVM>),
|
||||
AltChainRxVM(Arc<RandomXVm>),
|
||||
/// A weight cache for an alt chain
|
||||
AltChainWeightCache(BlockWeightsCache),
|
||||
/// A generic Ok response.
|
||||
|
|
|
@ -11,7 +11,7 @@ use cuprate_types::{
|
|||
use crate::{
|
||||
ExtendedConsensusError,
|
||||
__private::Database,
|
||||
context::{difficulty::DifficultyCache, rx_vms::RandomXVM, weight::BlockWeightsCache},
|
||||
context::{difficulty::DifficultyCache, rx_vms::RandomXVm, weight::BlockWeightsCache},
|
||||
};
|
||||
|
||||
pub(crate) mod sealed {
|
||||
|
@ -32,7 +32,7 @@ pub struct AltChainContextCache {
|
|||
pub difficulty_cache: Option<DifficultyCache>,
|
||||
|
||||
/// A cached RX VM.
|
||||
pub cached_rx_vm: Option<(usize, Arc<RandomXVM>)>,
|
||||
pub cached_rx_vm: Option<(usize, Arc<RandomXVm>)>,
|
||||
|
||||
/// The chain height of the alt chain.
|
||||
pub chain_height: usize,
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
use futures::{stream::FuturesOrdered, StreamExt};
|
||||
use randomx_rs::{RandomXCache, RandomXError, RandomXFlag, RandomXVM as VMInner};
|
||||
use randomx_rs::{RandomXCache, RandomXError, RandomXFlag, RandomXVM as VmInner};
|
||||
use rayon::prelude::*;
|
||||
use thread_local::ThreadLocal;
|
||||
use tower::ServiceExt;
|
||||
|
@ -33,16 +33,16 @@ const RX_SEEDS_CACHED: usize = 2;
|
|||
|
||||
/// A multithreaded randomX VM.
|
||||
#[derive(Debug)]
|
||||
pub struct RandomXVM {
|
||||
pub struct RandomXVm {
|
||||
/// These RandomX VMs all share the same cache.
|
||||
vms: ThreadLocal<VMInner>,
|
||||
vms: ThreadLocal<VmInner>,
|
||||
/// The RandomX cache.
|
||||
cache: RandomXCache,
|
||||
/// The flags used to start the RandomX VMs.
|
||||
flags: RandomXFlag,
|
||||
}
|
||||
|
||||
impl RandomXVM {
|
||||
impl RandomXVm {
|
||||
/// Create a new multithreaded randomX VM with the provided seed.
|
||||
pub fn new(seed: &[u8; 32]) -> Result<Self, RandomXError> {
|
||||
// TODO: allow passing in flags.
|
||||
|
@ -50,7 +50,7 @@ impl RandomXVM {
|
|||
|
||||
let cache = RandomXCache::new(flags, seed.as_slice())?;
|
||||
|
||||
Ok(RandomXVM {
|
||||
Ok(RandomXVm {
|
||||
vms: ThreadLocal::new(),
|
||||
cache,
|
||||
flags,
|
||||
|
@ -58,12 +58,12 @@ impl RandomXVM {
|
|||
}
|
||||
}
|
||||
|
||||
impl RandomX for RandomXVM {
|
||||
impl RandomX for RandomXVm {
|
||||
type Error = RandomXError;
|
||||
|
||||
fn calculate_hash(&self, buf: &[u8]) -> Result<[u8; 32], Self::Error> {
|
||||
self.vms
|
||||
.get_or_try(|| VMInner::new(self.flags, Some(self.cache.clone()), None))?
|
||||
.get_or_try(|| VmInner::new(self.flags, Some(self.cache.clone()), None))?
|
||||
.calculate_hash(buf)
|
||||
.map(|out| out.try_into().unwrap())
|
||||
}
|
||||
|
@ -72,17 +72,17 @@ impl RandomX for RandomXVM {
|
|||
/// The randomX VMs cache, keeps the VM needed to calculate the current block's PoW hash (if a VM is needed) and a
|
||||
/// couple more around this VM.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RandomXVMCache {
|
||||
pub struct RandomXVmCache {
|
||||
/// The top [`RX_SEEDS_CACHED`] RX seeds.
|
||||
pub(crate) seeds: VecDeque<(usize, [u8; 32])>,
|
||||
/// The VMs for `seeds` (if after hf 12, otherwise this will be empty).
|
||||
pub(crate) vms: HashMap<usize, Arc<RandomXVM>>,
|
||||
pub(crate) vms: HashMap<usize, Arc<RandomXVm>>,
|
||||
|
||||
/// A single cached VM that was given to us from a part of Cuprate.
|
||||
pub(crate) cached_vm: Option<([u8; 32], Arc<RandomXVM>)>,
|
||||
pub(crate) cached_vm: Option<([u8; 32], Arc<RandomXVm>)>,
|
||||
}
|
||||
|
||||
impl RandomXVMCache {
|
||||
impl RandomXVmCache {
|
||||
#[instrument(name = "init_rx_vm_cache", level = "info", skip(database))]
|
||||
pub async fn init_from_chain_height<D: Database + Clone>(
|
||||
chain_height: usize,
|
||||
|
@ -106,7 +106,7 @@ impl RandomXVMCache {
|
|||
.map(|(height, seed)| {
|
||||
(
|
||||
*height,
|
||||
Arc::new(RandomXVM::new(seed).expect("Failed to create RandomX VM!")),
|
||||
Arc::new(RandomXVm::new(seed).expect("Failed to create RandomX VM!")),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
|
@ -117,7 +117,7 @@ impl RandomXVMCache {
|
|||
HashMap::new()
|
||||
};
|
||||
|
||||
Ok(RandomXVMCache {
|
||||
Ok(RandomXVmCache {
|
||||
seeds,
|
||||
vms,
|
||||
cached_vm: None,
|
||||
|
@ -125,7 +125,7 @@ impl RandomXVMCache {
|
|||
}
|
||||
|
||||
/// Add a randomX VM to the cache, with the seed it was created with.
|
||||
pub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVM>)) {
|
||||
pub fn add_vm(&mut self, vm: ([u8; 32], Arc<RandomXVm>)) {
|
||||
self.cached_vm.replace(vm);
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ impl RandomXVMCache {
|
|||
height: usize,
|
||||
chain: Chain,
|
||||
database: D,
|
||||
) -> Result<Arc<RandomXVM>, ExtendedConsensusError> {
|
||||
) -> Result<Arc<RandomXVm>, ExtendedConsensusError> {
|
||||
let seed_height = randomx_seed_height(height);
|
||||
|
||||
let BlockchainResponse::BlockHash(seed_hash) = database
|
||||
|
@ -156,13 +156,13 @@ impl RandomXVMCache {
|
|||
}
|
||||
}
|
||||
|
||||
let alt_vm = rayon_spawn_async(move || Arc::new(RandomXVM::new(&seed_hash).unwrap())).await;
|
||||
let alt_vm = rayon_spawn_async(move || Arc::new(RandomXVm::new(&seed_hash).unwrap())).await;
|
||||
|
||||
Ok(alt_vm)
|
||||
}
|
||||
|
||||
/// Get the main-chain RandomX VMs.
|
||||
pub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVM>> {
|
||||
pub async fn get_vms(&mut self) -> HashMap<usize, Arc<RandomXVm>> {
|
||||
match self.seeds.len().checked_sub(self.vms.len()) {
|
||||
// No difference in the amount of seeds to VMs.
|
||||
Some(0) => (),
|
||||
|
@ -184,7 +184,7 @@ impl RandomXVMCache {
|
|||
}
|
||||
};
|
||||
|
||||
rayon_spawn_async(move || Arc::new(RandomXVM::new(&next_seed_hash).unwrap()))
|
||||
rayon_spawn_async(move || Arc::new(RandomXVm::new(&next_seed_hash).unwrap()))
|
||||
.await
|
||||
};
|
||||
|
||||
|
@ -200,7 +200,7 @@ impl RandomXVMCache {
|
|||
seeds_clone
|
||||
.par_iter()
|
||||
.map(|(height, seed)| {
|
||||
let vm = RandomXVM::new(seed).expect("Failed to create RandomX VM!");
|
||||
let vm = RandomXVm::new(seed).expect("Failed to create RandomX VM!");
|
||||
let vm = Arc::new(vm);
|
||||
(*height, vm)
|
||||
})
|
||||
|
|
|
@ -46,7 +46,7 @@ pub struct ContextTask<D: Database> {
|
|||
/// The weight cache.
|
||||
weight_cache: weight::BlockWeightsCache,
|
||||
/// The RX VM cache.
|
||||
rx_vm_cache: rx_vms::RandomXVMCache,
|
||||
rx_vm_cache: rx_vms::RandomXVmCache,
|
||||
/// The hard-fork state cache.
|
||||
hardfork_state: hardforks::HardForkState,
|
||||
|
||||
|
@ -128,7 +128,7 @@ impl<D: Database + Clone + Send + 'static> ContextTask<D> {
|
|||
|
||||
let db = database.clone();
|
||||
let rx_seed_handle = tokio::spawn(async move {
|
||||
rx_vms::RandomXVMCache::init_from_chain_height(chain_height, ¤t_hf, db).await
|
||||
rx_vms::RandomXVmCache::init_from_chain_height(chain_height, ¤t_hf, db).await
|
||||
});
|
||||
|
||||
let context_svc = ContextTask {
|
||||
|
|
|
@ -9,7 +9,7 @@ use cuprate_consensus_rules::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
context::rx_vms::{get_last_rx_seed_heights, RandomXVMCache},
|
||||
context::rx_vms::{get_last_rx_seed_heights, RandomXVmCache},
|
||||
tests::mock_db::*,
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ fn rx_heights_consistent() {
|
|||
async fn rx_vm_created_on_hf_12() {
|
||||
let db = DummyDatabaseBuilder::default().finish(Some(10));
|
||||
|
||||
let mut cache = RandomXVMCache::init_from_chain_height(10, &HardFork::V11, db)
|
||||
let mut cache = RandomXVmCache::init_from_chain_height(10, &HardFork::V11, db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -67,7 +67,7 @@ proptest! {
|
|||
let rt = Builder::new_multi_thread().enable_all().build().unwrap();
|
||||
|
||||
rt.block_on(async move {
|
||||
let cache = RandomXVMCache::init_from_chain_height(10, &hf, db).await.unwrap();
|
||||
let cache = RandomXVmCache::init_from_chain_height(10, &hf, db).await.unwrap();
|
||||
assert!(cache.seeds.len() == cache.vms.len() || hf < HardFork::V12);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ epee_object!(
|
|||
a: u8,
|
||||
);
|
||||
|
||||
struct TT {
|
||||
struct T2 {
|
||||
a: u8,
|
||||
}
|
||||
|
||||
epee_object!(
|
||||
TT,
|
||||
T2,
|
||||
a: u8 = 0,
|
||||
);
|
||||
|
||||
|
@ -35,5 +35,5 @@ fn duplicate_key_with_default() {
|
|||
b'a', 0x0B, 0x00,
|
||||
];
|
||||
|
||||
assert!(from_bytes::<TT, _>(&mut &data[..]).is_err());
|
||||
assert!(from_bytes::<T2, _>(&mut &data[..]).is_err());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue