pub(crate) mod is_disabled {
use super::checks::*;
pub(crate) fn confirmation_tag() -> bool {
confirmation_tag::FLAG.load(core::sync::atomic::Ordering::Relaxed)
}
pub(crate) fn leaf_node_lifetime() -> bool {
leaf_node_lifetime::FLAG.load(core::sync::atomic::Ordering::Relaxed)
}
}
#[cfg(test)]
use std::sync::atomic::AtomicBool;
#[cfg(test)]
#[derive(Clone, Copy, Debug)]
pub struct SkipValidationHandle {
#[allow(dead_code)]
name: &'static str,
flag: &'static AtomicBool,
}
pub(crate) mod checks {
pub(crate) mod confirmation_tag {
use std::sync::atomic::AtomicBool;
pub(in crate::skip_validation) static FLAG: AtomicBool = AtomicBool::new(false);
#[cfg(test)]
pub(crate) use lock::handle;
#[cfg(test)]
mod lock {
use super::FLAG;
use crate::skip_validation::SkipValidationHandle;
use once_cell::sync::Lazy;
use std::sync::{Mutex, MutexGuard};
const NAME: &str = "confirmation_tag";
static MUTEX: Lazy<Mutex<SkipValidationHandle>> =
Lazy::new(|| Mutex::new(SkipValidationHandle::new_confirmation_tag_handle()));
pub(crate) fn handle() -> MutexGuard<'static, SkipValidationHandle> {
MUTEX.lock().unwrap_or_else(|e| {
panic!("error taking skip-validation mutex for '{NAME}': {e}")
})
}
impl SkipValidationHandle {
pub fn new_confirmation_tag_handle() -> Self {
Self {
name: NAME,
flag: &FLAG,
}
}
}
}
}
pub(crate) mod leaf_node_lifetime {
use std::sync::atomic::AtomicBool;
pub(in crate::skip_validation) static FLAG: AtomicBool = AtomicBool::new(false);
#[cfg(test)]
pub(crate) use lock::handle;
#[cfg(test)]
mod lock {
use super::FLAG;
use crate::skip_validation::SkipValidationHandle;
use once_cell::sync::Lazy;
use std::sync::{Mutex, MutexGuard};
const NAME: &str = "leaf_node_lifetime";
static MUTEX: Lazy<Mutex<SkipValidationHandle>> =
Lazy::new(|| Mutex::new(SkipValidationHandle::new_leaf_node_lifetime_handle()));
pub(crate) fn handle() -> MutexGuard<'static, SkipValidationHandle> {
MUTEX.lock().unwrap_or_else(|e| {
panic!("error taking skip-validation mutex for '{NAME}': {e}")
})
}
impl SkipValidationHandle {
pub fn new_leaf_node_lifetime_handle() -> Self {
Self {
name: NAME,
flag: &FLAG,
}
}
}
}
}
}
#[cfg(test)]
impl SkipValidationHandle {
pub fn disable_validation(self) {
self.flag.store(true, core::sync::atomic::Ordering::Relaxed);
}
pub fn enable_validation(self) {
self.flag
.store(false, core::sync::atomic::Ordering::Relaxed);
}
pub fn with_disabled<R, F: FnMut() -> R>(self, mut f: F) -> R {
self.disable_validation();
let r = f();
self.enable_validation();
r
}
}