mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 12:09:37 +00:00
Make the output distribution cache only available under a feature
Enables a mode with reduced memory usage *and* increased safety given current unsafety of the cache. Relevant to https://github.com/serai-dex/serai/issues/415.
This commit is contained in:
parent
351436a258
commit
3f7bdaa64b
2 changed files with 16 additions and 5 deletions
|
@ -91,7 +91,7 @@ std = [
|
||||||
|
|
||||||
"monero-generators/std",
|
"monero-generators/std",
|
||||||
|
|
||||||
"futures/std",
|
"futures?/std",
|
||||||
|
|
||||||
"hex/std",
|
"hex/std",
|
||||||
"serde/std",
|
"serde/std",
|
||||||
|
@ -100,6 +100,7 @@ std = [
|
||||||
"base58-monero/std",
|
"base58-monero/std",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
cache-distribution = ["futures"]
|
||||||
http-rpc = ["digest_auth", "simple-request", "tokio"]
|
http-rpc = ["digest_auth", "simple-request", "tokio"]
|
||||||
multisig = ["transcript", "frost", "dleq", "std"]
|
multisig = ["transcript", "frost", "dleq", "std"]
|
||||||
binaries = ["tokio/rt-multi-thread", "tokio/macros", "http-rpc"]
|
binaries = ["tokio/rt-multi-thread", "tokio/macros", "http-rpc"]
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
use std_shims::{sync::OnceLock, vec::Vec, collections::HashSet};
|
use std_shims::{vec::Vec, collections::HashSet};
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(feature = "cache-distribution")]
|
||||||
|
use std_shims::sync::OnceLock;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "cache-distribution", not(feature = "std")))]
|
||||||
use std_shims::sync::Mutex;
|
use std_shims::sync::Mutex;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(all(feature = "cache-distribution", feature = "std"))]
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
|
|
||||||
use zeroize::{Zeroize, ZeroizeOnDrop};
|
use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||||
|
@ -27,9 +30,11 @@ const BLOCK_TIME: usize = 120;
|
||||||
const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME;
|
const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME;
|
||||||
const TIP_APPLICATION: f64 = (LOCK_WINDOW * BLOCK_TIME) as f64;
|
const TIP_APPLICATION: f64 = (LOCK_WINDOW * BLOCK_TIME) as f64;
|
||||||
|
|
||||||
// TODO: Expose an API to reset this in case a reorg occurs/the RPC fails/returns garbage
|
// TODO: Resolve safety of this in case a reorg occurs/the network changes
|
||||||
// TODO: Update this when scanning a block, as possible
|
// TODO: Update this when scanning a block, as possible
|
||||||
|
#[cfg(feature = "cache-distribution")]
|
||||||
static DISTRIBUTION_CELL: OnceLock<Mutex<Vec<u64>>> = OnceLock::new();
|
static DISTRIBUTION_CELL: OnceLock<Mutex<Vec<u64>>> = OnceLock::new();
|
||||||
|
#[cfg(feature = "cache-distribution")]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn DISTRIBUTION() -> &'static Mutex<Vec<u64>> {
|
fn DISTRIBUTION() -> &'static Mutex<Vec<u64>> {
|
||||||
DISTRIBUTION_CELL.get_or_init(|| Mutex::new(Vec::with_capacity(3000000)))
|
DISTRIBUTION_CELL.get_or_init(|| Mutex::new(Vec::with_capacity(3000000)))
|
||||||
|
@ -159,11 +164,16 @@ impl Decoys {
|
||||||
height: usize,
|
height: usize,
|
||||||
inputs: &[SpendableOutput],
|
inputs: &[SpendableOutput],
|
||||||
) -> Result<Vec<Decoys>, RpcError> {
|
) -> Result<Vec<Decoys>, RpcError> {
|
||||||
|
#[cfg(feature = "cache-distribution")]
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
let mut distribution = DISTRIBUTION().lock();
|
let mut distribution = DISTRIBUTION().lock();
|
||||||
|
#[cfg(feature = "cache-distribution")]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
let mut distribution = DISTRIBUTION().lock().await;
|
let mut distribution = DISTRIBUTION().lock().await;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "cache-distribution"))]
|
||||||
|
let mut distribution = vec![];
|
||||||
|
|
||||||
let decoy_count = ring_len - 1;
|
let decoy_count = ring_len - 1;
|
||||||
|
|
||||||
// Convert the inputs in question to the raw output data
|
// Convert the inputs in question to the raw output data
|
||||||
|
|
Loading…
Reference in a new issue