Skip to content

Commit 76afd49

Browse files
Implement BLOCK_CACHE_SIZE / EXECUTION_STATE_CACHE_SIZE as input parameters (#4621)
## Motivation Those two variables are constants in the program while varying values could help. ## Proposal Add it as parameter inputs. A creation function has been introduced, which leads to a simplification of the code. ## Test Plan The CI. ## Release Plan The goal is to backport it to testnet conway. But let's first merge in in the main. ## Links None.
1 parent be6b4d6 commit 76afd49

File tree

12 files changed

+172
-227
lines changed

12 files changed

+172
-227
lines changed

CLI.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ Client implementation and command-line tool for the Linera blockchain
186186
* `--wasm-runtime <WASM_RUNTIME>` — The WebAssembly runtime to use
187187
* `--tokio-threads <TOKIO_THREADS>` — The number of Tokio worker threads to use
188188
* `--tokio-blocking-threads <TOKIO_BLOCKING_THREADS>` — The number of Tokio blocking threads to use
189+
* `--block-cache-size <BLOCK_CACHE_SIZE>` — Size of the block cache (default: 5000)
190+
191+
Default value: `5000`
192+
* `--execution-state-cache-size <EXECUTION_STATE_CACHE_SIZE>` — Size of the execution state cache (default: 10000)
193+
194+
Default value: `10000`
189195

190196

191197

linera-client/src/client_context.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ where
124124
Si: linera_core::environment::Signer,
125125
W: Persist<Target = Wallet>,
126126
{
127-
pub fn new(storage: S, options: ClientContextOptions, wallet: W, signer: Si) -> Self {
127+
pub fn new(
128+
storage: S,
129+
options: ClientContextOptions,
130+
wallet: W,
131+
signer: Si,
132+
block_cache_size: usize,
133+
execution_state_cache_size: usize,
134+
) -> Self {
128135
#[cfg(not(web))]
129136
let timing_config = options.to_timing_config();
130137
let node_provider = NodeProvider::new(NodeOptions {
@@ -151,6 +158,8 @@ where
151158
name,
152159
options.chain_worker_ttl,
153160
options.to_chain_client_options(),
161+
block_cache_size,
162+
execution_state_cache_size,
154163
);
155164

156165
#[cfg(not(web))]
@@ -174,7 +183,13 @@ where
174183
}
175184

176185
#[cfg(with_testing)]
177-
pub fn new_test_client_context(storage: S, wallet: W, signer: Si) -> Self {
186+
pub fn new_test_client_context(
187+
storage: S,
188+
wallet: W,
189+
signer: Si,
190+
block_cache_size: usize,
191+
execution_state_cache_size: usize,
192+
) -> Self {
178193
use linera_core::{client::ChainClientOptions, node::CrossChainMessageDelivery};
179194

180195
let send_recv_timeout = Duration::from_millis(4000);
@@ -208,6 +223,8 @@ where
208223
cross_chain_message_delivery: CrossChainMessageDelivery::Blocking,
209224
..ChainClientOptions::test_default()
210225
},
226+
block_cache_size,
227+
execution_state_cache_size,
211228
);
212229

213230
ClientContext {

linera-client/src/unit_tests/chain_listener.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ async fn test_chain_listener() -> anyhow::Result<()> {
122122
format!("Client node for {:.8}", chain_id0),
123123
Duration::from_secs(30),
124124
ChainClientOptions::test_default(),
125+
5_000,
126+
10_000,
125127
)),
126128
};
127129
context
@@ -207,6 +209,8 @@ async fn test_chain_listener_admin_chain() -> anyhow::Result<()> {
207209
"Client node with no chains".to_string(),
208210
Duration::from_secs(30),
209211
ChainClientOptions::test_default(),
212+
5_000,
213+
10_000,
210214
)),
211215
};
212216
let context = Arc::new(Mutex::new(context));

linera-client/src/unit_tests/wallet.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async fn test_save_wallet_with_pending_blobs() -> anyhow::Result<()> {
6565
},
6666
blobs: vec![Blob::new_data(b"blob".to_vec())],
6767
});
68-
let mut context = ClientContext::new_test_client_context(storage, wallet, signer);
68+
let mut context =
69+
ClientContext::new_test_client_context(storage, wallet, signer, 5_000, 10_000);
6970
context.save_wallet().await?;
7071
Ok(())
7172
}

linera-core/src/client/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub struct Client<Env: Environment> {
211211
impl<Env: Environment> Client<Env> {
212212
/// Creates a new `Client` with a new cache and notifiers.
213213
#[instrument(level = "trace", skip_all)]
214+
#[allow(clippy::too_many_arguments)]
214215
pub fn new(
215216
environment: Env,
216217
admin_id: ChainId,
@@ -219,12 +220,16 @@ impl<Env: Environment> Client<Env> {
219220
name: impl Into<String>,
220221
chain_worker_ttl: Duration,
221222
options: ChainClientOptions,
223+
block_cache_size: usize,
224+
execution_state_cache_size: usize,
222225
) -> Self {
223226
let tracked_chains = Arc::new(RwLock::new(tracked_chains.into_iter().collect()));
224227
let state = WorkerState::new_for_client(
225228
name.into(),
226229
environment.storage().clone(),
227230
tracked_chains.clone(),
231+
block_cache_size,
232+
execution_state_cache_size,
228233
)
229234
.with_long_lived_services(long_lived_services)
230235
.with_allow_inactive_chains(true)

linera-core/src/unit_tests/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ where
861861
format!("Node {}", i),
862862
Some(validator_keypair.secret_key),
863863
storage.clone(),
864+
5_000,
865+
10_000,
864866
)
865867
.with_allow_inactive_chains(false)
866868
.with_allow_messages_from_deprecated_epochs(false);
@@ -1047,6 +1049,8 @@ where
10471049
format!("Client node for {:.8}", chain_id),
10481050
Duration::from_secs(30),
10491051
ChainClientOptions::test_default(),
1052+
5_000,
1053+
10_000,
10501054
));
10511055
Ok(client.create_chain_client(
10521056
chain_id,

linera-core/src/unit_tests/worker_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ where
149149
"Single validator node".to_string(),
150150
Some(validator_keypair.secret_key),
151151
storage,
152+
5_000,
153+
10_000,
152154
)
153155
.with_allow_inactive_chains(is_client)
154156
.with_allow_messages_from_deprecated_epochs(is_client)

linera-core/src/worker.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ use crate::{
4343
value_cache::ValueCache,
4444
};
4545

46-
const BLOCK_CACHE_SIZE: usize = 5_000;
47-
const EXECUTION_STATE_CACHE_SIZE: usize = 10_000;
48-
4946
#[cfg(test)]
5047
#[path = "unit_tests/worker_tests.rs"]
5148
mod worker_tests;
@@ -343,13 +340,15 @@ where
343340
nickname: String,
344341
key_pair: Option<ValidatorSecretKey>,
345342
storage: StorageClient,
343+
block_cache_size: usize,
344+
execution_state_cache_size: usize,
346345
) -> Self {
347346
WorkerState {
348347
nickname,
349348
storage,
350349
chain_worker_config: ChainWorkerConfig::default().with_key_pair(key_pair),
351-
block_cache: Arc::new(ValueCache::new(BLOCK_CACHE_SIZE)),
352-
execution_state_cache: Arc::new(ValueCache::new(EXECUTION_STATE_CACHE_SIZE)),
350+
block_cache: Arc::new(ValueCache::new(block_cache_size)),
351+
execution_state_cache: Arc::new(ValueCache::new(execution_state_cache_size)),
353352
tracked_chains: None,
354353
delivery_notifiers: Arc::default(),
355354
chain_worker_tasks: Arc::default(),
@@ -362,13 +361,15 @@ where
362361
nickname: String,
363362
storage: StorageClient,
364363
tracked_chains: Arc<RwLock<HashSet<ChainId>>>,
364+
block_cache_size: usize,
365+
execution_state_cache_size: usize,
365366
) -> Self {
366367
WorkerState {
367368
nickname,
368369
storage,
369370
chain_worker_config: ChainWorkerConfig::default(),
370-
block_cache: Arc::new(ValueCache::new(BLOCK_CACHE_SIZE)),
371-
execution_state_cache: Arc::new(ValueCache::new(EXECUTION_STATE_CACHE_SIZE)),
371+
block_cache: Arc::new(ValueCache::new(block_cache_size)),
372+
execution_state_cache: Arc::new(ValueCache::new(execution_state_cache_size)),
372373
tracked_chains: Some(tracked_chains),
373374
delivery_notifiers: Arc::default(),
374375
chain_worker_tasks: Arc::default(),

linera-sdk/src/test/validator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ impl TestValidator {
9292
"Single validator node".to_string(),
9393
Some(validator_keypair.secret_key.copy()),
9494
storage.clone(),
95+
5_000,
96+
10_000,
9597
);
9698

9799
// Create an admin chain.

0 commit comments

Comments
 (0)