Skip to main content

casper_node/reactor/main_reactor/
config.rs

1use datasize::DataSize;
2use serde::{Deserialize, Serialize};
3use tracing::error;
4
5use casper_types::Chainspec;
6
7use crate::{
8    logging::LoggingConfig, types::NodeConfig, BinaryPortConfig, BlockAccumulatorConfig,
9    BlockSynchronizerConfig, BlockValidatorConfig, ConsensusConfig, ContractRuntimeConfig,
10    DiagnosticsPortConfig, EventStreamServerConfig, FetcherConfig, GossipConfig, NetworkConfig,
11    RestServerConfig, StorageConfig, TransactionAcceptorConfig, TransactionBufferConfig,
12    UpgradeWatcherConfig,
13};
14
15/// Root configuration.
16#[derive(Clone, DataSize, Debug, Default, Serialize, Deserialize)]
17// Disallow unknown fields to ensure config files and command-line overrides contain valid keys.
18#[serde(deny_unknown_fields)]
19pub struct Config {
20    /// Config values for the node.
21    pub node: NodeConfig,
22    /// Config values for logging.
23    pub logging: LoggingConfig,
24    /// Config values for consensus.
25    pub consensus: ConsensusConfig,
26    /// Config values for network.
27    pub network: NetworkConfig,
28    /// Config values for the event stream server.
29    pub event_stream_server: EventStreamServerConfig,
30    /// Config values for the REST server.
31    pub rest_server: RestServerConfig,
32    /// Config values for storage.
33    pub storage: StorageConfig,
34    /// Config values for gossip.
35    pub gossip: GossipConfig,
36    /// Config values for fetchers.
37    pub fetcher: FetcherConfig,
38    /// Config values for the contract runtime.
39    pub contract_runtime: ContractRuntimeConfig,
40    /// Config values for the transaction acceptor.
41    pub transaction_acceptor: TransactionAcceptorConfig,
42    /// Config values for the transaction buffer.
43    pub transaction_buffer: TransactionBufferConfig,
44    /// Config values for the diagnostics port.
45    pub diagnostics_port: DiagnosticsPortConfig,
46    /// Config values for the block accumulator.
47    pub block_accumulator: BlockAccumulatorConfig,
48    /// Config values for the block synchronizer.
49    pub block_synchronizer: BlockSynchronizerConfig,
50    /// Config values for the block validator.
51    pub block_validator: BlockValidatorConfig,
52    /// Config values for the upgrade watcher.
53    pub upgrade_watcher: UpgradeWatcherConfig,
54    /// Config values for the BinaryPort server.
55    pub binary_port_server: BinaryPortConfig,
56}
57
58impl Config {
59    /// This modifies `self` so that all configured options are within the bounds set in the
60    /// provided chainspec.
61    pub(crate) fn ensure_valid(&mut self, chainspec: &Chainspec) {
62        if self.transaction_acceptor.timestamp_leeway
63            > chainspec.transaction_config.max_timestamp_leeway
64        {
65            error!(
66                configured_timestamp_leeway = %self.transaction_acceptor.timestamp_leeway,
67                max_timestamp_leeway = %chainspec.transaction_config.max_timestamp_leeway,
68                "setting value for 'transaction_acceptor.timestamp_leeway' to maximum permitted by \
69                chainspec 'transaction_config.max_timestamp_leeway'",
70            );
71            self.transaction_acceptor.timestamp_leeway =
72                chainspec.transaction_config.max_timestamp_leeway;
73        }
74    }
75
76    /// Set network config.
77    #[cfg(test)]
78    pub(crate) fn with_network_config(mut self, network_config: NetworkConfig) -> Self {
79        self.network = network_config;
80        self
81    }
82}