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
10/// Configuration parameters for the [`ChainWorkerState`][`super::state::ChainWorkerState`].
11#[derive(Clone, Default)]
12pub struct ChainWorkerConfig {
13    /// The signature key pair of the validator. The key may be missing for replicas
14    /// without voting rights (possibly with a partial view of chains).
15    pub key_pair: Option<Arc<ValidatorSecretKey>>,
16    /// Whether inactive chains are allowed in storage.
17    pub allow_inactive_chains: bool,
18    /// Whether new messages from deprecated epochs are allowed.
19    pub allow_messages_from_deprecated_epochs: bool,
20    /// Whether the user application services should be long-lived.
21    pub long_lived_services: bool,
22    /// Blocks with a timestamp this far in the future will still be accepted, but the validator
23    /// will wait until that timestamp before voting.
24    pub grace_period: Duration,
25}
26
27impl ChainWorkerConfig {
28    /// Configures the `key_pair` in this [`ChainWorkerConfig`].
29    pub fn with_key_pair(mut self, key_pair: Option<ValidatorSecretKey>) -> Self {
30        match key_pair {
31            Some(validator_secret) => {
32                self.key_pair = Some(Arc::new(validator_secret));
33            }
34            None => {
35                self.key_pair = None;
36            }
37        }
38        self
39    }
40
41    /// Gets a reference to the [`ValidatorSecretKey`], if available.
42    pub fn key_pair(&self) -> Option<&ValidatorSecretKey> {
43        self.key_pair.as_ref().map(Arc::as_ref)
44    }
45}