From 3283cd79e42834f2fe02f96e5f76ce63057754c5 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 22 Apr 2024 00:29:18 -0400 Subject: [PATCH] Remove the distribution cache It's a notable bandwidth/performance improvement, yet it's not ready. We need a dedicated Distribution struct which is managed by the wallet and passed in. While we can do that now, it's not currently worth the effort. --- Cargo.lock | 1 - coins/monero/Cargo.toml | 5 ----- coins/monero/src/wallet/decoys.rs | 26 -------------------------- tests/no-std/Cargo.toml | 2 +- 4 files changed, 1 insertion(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57e438de..992831ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4672,7 +4672,6 @@ dependencies = [ name = "monero-serai" version = "0.1.4-alpha" dependencies = [ - "async-lock", "async-trait", "base58-monero", "curve25519-dalek", diff --git a/coins/monero/Cargo.toml b/coins/monero/Cargo.toml index 357803c9..c1637358 100644 --- a/coins/monero/Cargo.toml +++ b/coins/monero/Cargo.toml @@ -47,8 +47,6 @@ frost = { package = "modular-frost", path = "../../crypto/frost", version = "0.8 monero-generators = { path = "generators", version = "0.4", default-features = false } -async-lock = { version = "3", default-features = false, optional = true } - hex-literal = "0.4" hex = { version = "0.4", default-features = false, features = ["alloc"] } serde = { version = "1", default-features = false, features = ["derive", "alloc"] } @@ -93,8 +91,6 @@ std = [ "monero-generators/std", - "async-lock?/std", - "hex/std", "serde/std", "serde_json/std", @@ -102,7 +98,6 @@ std = [ "base58-monero/std", ] -cache-distribution = ["async-lock"] http-rpc = ["digest_auth", "simple-request", "tokio"] multisig = ["transcript", "frost", "std"] binaries = ["tokio/rt-multi-thread", "tokio/macros", "http-rpc"] diff --git a/coins/monero/src/wallet/decoys.rs b/coins/monero/src/wallet/decoys.rs index b0282f37..0cdff89a 100644 --- a/coins/monero/src/wallet/decoys.rs +++ b/coins/monero/src/wallet/decoys.rs @@ -1,13 +1,5 @@ use std_shims::{vec::Vec, collections::HashSet}; -#[cfg(feature = "cache-distribution")] -use std_shims::sync::OnceLock; - -#[cfg(all(feature = "cache-distribution", not(feature = "std")))] -use std_shims::sync::Mutex; -#[cfg(all(feature = "cache-distribution", feature = "std"))] -use async_lock::Mutex; - use zeroize::{Zeroize, ZeroizeOnDrop}; use rand_core::{RngCore, CryptoRng}; @@ -29,16 +21,6 @@ const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME; #[allow(clippy::cast_precision_loss)] const TIP_APPLICATION: f64 = (DEFAULT_LOCK_WINDOW * BLOCK_TIME) as f64; -// TODO: Resolve safety of this in case a reorg occurs/the network changes -// TODO: Update this when scanning a block, as possible -#[cfg(feature = "cache-distribution")] -static DISTRIBUTION_CELL: OnceLock>> = OnceLock::new(); -#[cfg(feature = "cache-distribution")] -#[allow(non_snake_case)] -fn DISTRIBUTION() -> &'static Mutex> { - DISTRIBUTION_CELL.get_or_init(|| Mutex::new(Vec::with_capacity(3000000))) -} - #[allow(clippy::too_many_arguments)] async fn select_n<'a, R: RngCore + CryptoRng, RPC: RpcConnection>( rng: &mut R, @@ -158,14 +140,6 @@ async fn select_decoys( inputs: &[SpendableOutput], fingerprintable_canonical: bool, ) -> Result, RpcError> { - #[cfg(feature = "cache-distribution")] - #[cfg(not(feature = "std"))] - let mut distribution = DISTRIBUTION().lock(); - #[cfg(feature = "cache-distribution")] - #[cfg(feature = "std")] - let mut distribution = DISTRIBUTION().lock().await; - - #[cfg(not(feature = "cache-distribution"))] let mut distribution = vec![]; let decoy_count = ring_len - 1; diff --git a/tests/no-std/Cargo.toml b/tests/no-std/Cargo.toml index dc128786..756ca880 100644 --- a/tests/no-std/Cargo.toml +++ b/tests/no-std/Cargo.toml @@ -36,4 +36,4 @@ dkg = { path = "../../crypto/dkg", default-features = false } bitcoin-serai = { path = "../../coins/bitcoin", default-features = false, features = ["hazmat"] } monero-generators = { path = "../../coins/monero/generators", default-features = false } -monero-serai = { path = "../../coins/monero", default-features = false, features = ["cache-distribution"] } +monero-serai = { path = "../../coins/monero", default-features = false }