use std::{collections::HashSet, sync::Arc};
use linera_base::{crypto::ValidatorSecretKey, identifiers::ChainId, time::Duration};
use crate::CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES;
#[derive(Clone)]
pub struct ChainWorkerConfig {
pub nickname: String,
pub key_pair: Option<Arc<ValidatorSecretKey>>,
pub allow_inactive_chains: bool,
pub allow_messages_from_deprecated_epochs: bool,
pub long_lived_services: bool,
pub block_time_grace_period: Duration,
pub ttl: Option<Duration>,
pub sender_chain_ttl: Option<Duration>,
pub chain_info_max_received_log_entries: usize,
pub block_cache_size: usize,
pub execution_state_cache_size: usize,
pub priority_bundle_origins: HashSet<ChainId>,
pub ignored_bundle_origins: HashSet<ChainId>,
pub cross_chain_message_chunk_limit: usize,
pub allow_revert_confirm: bool,
pub reset_on_corrupted_chain_state: Option<Duration>,
pub recovery_whitelist: Option<HashSet<ChainId>>,
}
impl ChainWorkerConfig {
pub fn with_key_pair(mut self, key_pair: Option<ValidatorSecretKey>) -> Self {
self.key_pair = key_pair.map(Arc::new);
self
}
pub fn key_pair(&self) -> Option<&ValidatorSecretKey> {
self.key_pair.as_ref().map(Arc::as_ref)
}
pub(crate) fn recovery_allowed_for(&self, chain_id: &ChainId) -> bool {
self.recovery_whitelist
.as_ref()
.is_none_or(|set| set.contains(chain_id))
}
}
impl Default for ChainWorkerConfig {
fn default() -> Self {
Self {
nickname: String::new(),
key_pair: None,
allow_inactive_chains: false,
allow_messages_from_deprecated_epochs: false,
long_lived_services: false,
block_time_grace_period: Default::default(),
ttl: None,
sender_chain_ttl: None,
chain_info_max_received_log_entries: CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
block_cache_size: crate::worker::DEFAULT_BLOCK_CACHE_SIZE,
execution_state_cache_size: crate::worker::DEFAULT_EXECUTION_STATE_CACHE_SIZE,
priority_bundle_origins: HashSet::new(),
ignored_bundle_origins: HashSet::new(),
cross_chain_message_chunk_limit: usize::MAX,
allow_revert_confirm: false,
reset_on_corrupted_chain_state: None,
recovery_whitelist: None,
}
}
}