diff --git a/bin/node/.env b/bin/node/.env index 01e699aff..fc4c2793e 100644 --- a/bin/node/.env +++ b/bin/node/.env @@ -14,3 +14,4 @@ MIDEN_NODE_VALIDATOR_INSECURE_SECRET_KEY= MIDEN_NODE_RPC_URL=http://0.0.0.0:57291 MIDEN_NODE_DATA_DIRECTORY=./ MIDEN_NODE_ENABLE_OTEL=true +MIDEN_NTX_DATA_STORE_SCRIPT_CACHE_SIZE= diff --git a/bin/node/src/commands/bundled.rs b/bin/node/src/commands/bundled.rs index a51c191eb..594959aa4 100644 --- a/bin/node/src/commands/bundled.rs +++ b/bin/node/src/commands/bundled.rs @@ -322,6 +322,7 @@ impl BundledCommand { ntx_builder.tx_prover_url, ntx_builder.ticker_interval, checkpoint, + ntx_builder.script_cache_size, ) .run() .await diff --git a/bin/node/src/commands/mod.rs b/bin/node/src/commands/mod.rs index ecfee995f..7e8fa7e69 100644 --- a/bin/node/src/commands/mod.rs +++ b/bin/node/src/commands/mod.rs @@ -35,10 +35,12 @@ const ENV_GENESIS_CONFIG_FILE: &str = "MIDEN_GENESIS_CONFIG_FILE"; const ENV_MAX_TXS_PER_BATCH: &str = "MIDEN_MAX_TXS_PER_BATCH"; const ENV_MAX_BATCHES_PER_BLOCK: &str = "MIDEN_MAX_BATCHES_PER_BLOCK"; const ENV_MEMPOOL_TX_CAPACITY: &str = "MIDEN_NODE_MEMPOOL_TX_CAPACITY"; +const ENV_NTX_SCRIPT_CACHE_SIZE: &str = "MIDEN_NTX_DATA_STORE_SCRIPT_CACHE_SIZE"; const ENV_VALIDATOR_INSECURE_SECRET_KEY: &str = "MIDEN_NODE_VALIDATOR_INSECURE_SECRET_KEY"; const DEFAULT_NTX_TICKER_INTERVAL: Duration = Duration::from_millis(200); const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); +const DEFAULT_NTX_SCRIPT_CACHE_SIZE: NonZeroUsize = NonZeroUsize::new(1000).unwrap(); // Formats a Duration into a human-readable string for display in clap help text. fn duration_to_human_readable_string(duration: Duration) -> String { @@ -65,6 +67,14 @@ pub struct NtxBuilderConfig { value_name = "DURATION" )] pub ticker_interval: Duration, + + #[arg( + long = "ntx-builder.script-cache-size", + env = ENV_NTX_SCRIPT_CACHE_SIZE, + value_name = "NUM", + default_value_t = DEFAULT_NTX_SCRIPT_CACHE_SIZE + )] + pub script_cache_size: NonZeroUsize, } /// Configuration for the Block Producer component diff --git a/crates/ntx-builder/src/builder.rs b/crates/ntx-builder/src/builder.rs index 34ebdc06f..3d0a00aab 100644 --- a/crates/ntx-builder/src/builder.rs +++ b/crates/ntx-builder/src/builder.rs @@ -91,12 +91,6 @@ pub struct NetworkTransactionBuilder { } impl NetworkTransactionBuilder { - /// Default cache size for note scripts. - /// - /// Each cached script contains the deserialized `NoteScript` object, so the actual memory usage - /// depends on the complexity of the scripts being cached. - const DEFAULT_SCRIPT_CACHE_SIZE: NonZeroUsize = NonZeroUsize::new(1000).unwrap(); - /// Creates a new instance of the network transaction builder. pub fn new( store_url: Url, @@ -104,8 +98,9 @@ impl NetworkTransactionBuilder { tx_prover_url: Option, ticker_interval: Duration, bp_checkpoint: Arc, + script_cache_size: NonZeroUsize, ) -> Self { - let script_cache = LruCache::new(Self::DEFAULT_SCRIPT_CACHE_SIZE); + let script_cache = LruCache::new(script_cache_size); let coordinator = Coordinator::new(MAX_IN_PROGRESS_TXS); Self { store_url,