linera_core/chain_worker/
config.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Configuration parameters for the chain worker.
5
6use std::sync::Arc;
7
8use linera_base::{crypto::ValidatorSecretKey, time::Duration};
9
10use crate::CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES;
11
12/// Configuration parameters for the chain worker and its owning
13/// [`WorkerState`][`crate::worker::WorkerState`].
14#[derive(Clone)]
15pub struct ChainWorkerConfig {
16    /// A name used for logging.
17    pub nickname: String,
18    /// The signature key pair of the validator. The key may be missing for replicas
19    /// without voting rights (possibly with a partial view of chains).
20    pub key_pair: Option<Arc<ValidatorSecretKey>>,
21    /// Whether inactive chains are allowed in storage.
22    pub allow_inactive_chains: bool,
23    /// Whether new messages from deprecated epochs are allowed.
24    pub allow_messages_from_deprecated_epochs: bool,
25    /// Whether the user application services should be long-lived.
26    pub long_lived_services: bool,
27    /// Blocks with a timestamp this far in the future will still be accepted, but the validator
28    /// will wait until that timestamp before voting.
29    pub block_time_grace_period: Duration,
30    /// Idle chain workers free their memory after this duration without requests.
31    /// `None` means no expiry (handle lives forever).
32    pub ttl: Option<Duration>,
33    /// TTL for sender chains. `None` means no expiry.
34    pub sender_chain_ttl: Option<Duration>,
35    /// The size to truncate receive log entries in chain info responses.
36    pub chain_info_max_received_log_entries: usize,
37    /// Maximum number of entries in the block cache.
38    pub block_cache_size: usize,
39    /// Maximum number of entries in the execution state cache.
40    pub execution_state_cache_size: usize,
41}
42
43impl ChainWorkerConfig {
44    /// Configures the `key_pair` in this [`ChainWorkerConfig`].
45    pub fn with_key_pair(mut self, key_pair: Option<ValidatorSecretKey>) -> Self {
46        self.key_pair = key_pair.map(Arc::new);
47        self
48    }
49
50    /// Gets a reference to the [`ValidatorSecretKey`], if available.
51    pub fn key_pair(&self) -> Option<&ValidatorSecretKey> {
52        self.key_pair.as_ref().map(Arc::as_ref)
53    }
54}
55
56impl Default for ChainWorkerConfig {
57    fn default() -> Self {
58        Self {
59            nickname: String::new(),
60            key_pair: None,
61            allow_inactive_chains: false,
62            allow_messages_from_deprecated_epochs: false,
63            long_lived_services: false,
64            block_time_grace_period: Default::default(),
65            ttl: None,
66            sender_chain_ttl: Some(Duration::from_secs(1)),
67            chain_info_max_received_log_entries: CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
68            block_cache_size: 5000,
69            execution_state_cache_size: 10_000,
70        }
71    }
72}