From c248140e0072c68d650365f2814a5d6f90ce88c6 Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 19 Sep 2025 16:18:40 +0200 Subject: [PATCH 1/2] fix: racecondition return on install_crypto fn --- crates/precompile/src/interface.rs | 7 +------ crates/primitives/src/once_lock.rs | 6 ++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/precompile/src/interface.rs b/crates/precompile/src/interface.rs index f4651c7a63..f05cd83bf4 100644 --- a/crates/precompile/src/interface.rs +++ b/crates/precompile/src/interface.rs @@ -11,12 +11,7 @@ static CRYPTO: OnceLock> = OnceLock::new(); /// Install a custom crypto provider globally. pub fn install_crypto(crypto: C) -> bool { - if CRYPTO.get().is_some() { - return false; - } - - CRYPTO.get_or_init(|| Box::new(crypto)); - true + CRYPTO.set(Box::new(crypto)).is_ok() } /// Get the installed crypto provider, or the default if none is installed. diff --git a/crates/primitives/src/once_lock.rs b/crates/primitives/src/once_lock.rs index 90d129ea6a..4cb22b2fb0 100644 --- a/crates/primitives/src/once_lock.rs +++ b/crates/primitives/src/once_lock.rs @@ -41,6 +41,12 @@ mod no_std_impl { pub fn get(&self) -> Option<&T> { self.inner.get() } + + /// Sets the contents of the OnceLock. + #[inline] + pub fn set(&self, value: T) -> Result<(), T> { + self.inner.set(Box::new(value)).map_err(|e| e.into_inner()) + } } } From 7bfcf9a77ec62876fb5849fad033794570749845 Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 19 Sep 2025 20:03:45 +0200 Subject: [PATCH 2/2] rm nightly item --- crates/primitives/src/once_lock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives/src/once_lock.rs b/crates/primitives/src/once_lock.rs index 4cb22b2fb0..21cb9b9abb 100644 --- a/crates/primitives/src/once_lock.rs +++ b/crates/primitives/src/once_lock.rs @@ -45,7 +45,7 @@ mod no_std_impl { /// Sets the contents of the OnceLock. #[inline] pub fn set(&self, value: T) -> Result<(), T> { - self.inner.set(Box::new(value)).map_err(|e| e.into_inner()) + self.inner.set(Box::new(value)).map_err(|e| *e) } } }