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