mod.rs
Overview
This file defines configuration structures and related helper functions used to manage node settings, global parameters, and network configurations for the blockchain node. It consolidates configuration management for node operation, synchronization, block production, networking, and cryptographic credentials. The configurations are deserialized from or serialized to files, enabling flexible and declarative control over node behavior.
Key responsibilities include:
Defining the
GlobalConfigstruct with parameters affecting block and transaction processing timings, synchronization thresholds, thread management, and security parameters.Defining the
NodeConfigstruct which captures node-specific settings such as identifiers, file paths for keys and state files, caching parameters, and rate limits.Defining the top-level
Configstruct that aggregatesGlobalConfig, network configuration (NetworkConfig), and local node configuration (NodeConfig).Providing default values for configurations where applicable.
Providing methods to generate network-related configurations (
gossip_config(),gossip_peer(), andnetwork_config()).Implementing a utility function
must_save_state_on_seq_noto determine if the node should save its state at a given block sequence number.
This file interacts extensively with the networking and transport layers, as well as with serialization utilities (serde) to enable configuration file loading and saving.
Detailed Breakdown
Modules Included
blockchain_confignetwork_configserde_configtest(only compiled during testing)
Imports & Re-exports
Uses standard library types such as HashSet,
PathBuf, andDuration.Imports cryptographic and networking types for certificate and key management (
CertFile, CertStore,PrivateKeyFile, GossipPeer).Re-exports configuration loading and saving functions from
serde_config.Uses TypedBuilder for ergonomic construction of the
NodeConfig.Uses types
NodeIdentifierandBlockSeqNofrom local crate modules.
Struct: GlobalConfig
Represents global timing, synchronization, and operational parameters for the node.
Field | Type | Description | Default |
|---|---|---|---|
|
| Duration in milliseconds for one iteration of block production cycle. | 330 |
|
| Maximum verification duration for one block. | 440 (330 * 4 / 3) |
|
| Max execution duration for producing one transaction. | None |
|
| Max execution duration for verifying one transaction. | None |
time_to_verify_transaction_aborted_with_execution_timeout_millis |
| Max execution duration for verifying transactions aborted due to execution timeout. | Derived from produce time |
|
| Timeout between resending attestations. | 3 seconds |
|
| Threshold difference in block sequence number to trigger node synchronization. | 20 |
| Minimum time interval between publishing state directives. | 600 seconds | |
|
| Block gap size that triggers block producer rotation. | 6 |
| Timeout between consecutive NodeJoining messages. | 300 seconds | |
|
| Block gap before sharing state during synchronization. | 32 |
|
| Delay node waits after receiving an unapplicable block before switching to sync mode. | 500 |
|
| Frequency (in blocks) for saving optimistic state. | 200 |
| Hash of the block keeper epoch code. | Hex string | |
| Hash of the block keeper preepoch code. | Hex string | |
|
| Expected maximum number of threads. | 100 |
| Load threshold to trigger thread splitting. | 5000 | |
| Window size for thread load calculation. | 100 | |
|
| Probability estimate for a successful attack. | 1e-9 |
|
| Minimum time duration for block producer rotation round. | 10,000 |
|
| Incremental step time for the rotation round. | 1,000 |
|
| Maximum time duration for block producer rotation round. | 30,000 |
|
| Minimal time after the last finalization to enable synchronization start. | 1200 seconds |
Implementation Details
Implements Default trait to provide sensible default values.
Parameters affect the timing and flow of block production, verification, synchronization, and security.
Some parameters like time_to_verify_transaction_aborted_with_execution_timeout_millis are set dynamically based on others.
Struct: NodeConfig
Represents node-specific configuration parameters related to identity, file paths, caching, parallelization, and rate limiting.
Field | Type | Description | Default |
|---|---|---|---|
|
| Unique identifier for the node. | Required |
|
| Path to blockchain configuration file. Deprecated and unused. | |
|
| Path to BLS key pair file. | |
| Path to block keeper seed key file. | ||
|
| Path to the zerostate file. | |
| Optional path to block keeper set update file. Must match the /v2/bk_set_update API output format. | None | |
| Local directory path shared with other nodes. |
| |
|
| Degree of parallelization for block production. | 20 |
|
| Size of the block cache in the local repository. | 20 |
| Size of the state cache in the local repository. | 10 | |
|
| Number of blocks after which accounts are unloaded from shard state. | None |
|
| Limit on calls per second to on_incoming_block_request function. |
|
|
| Size of the external messages cache. | 1000 |
|
| BlockKeeper node owner wallet public key. | Empty string ( |
|
| Path to signing keys file for authorizing incoming external messages. Required for direct external message sending. | None |
Implementation Details
Uses TypedBuilder macro for ergonomic and default-aware instantiation.
Some fields have default values set via the builder pattern.
The blockchain configuration path is deprecated and planned for removal.
Includes local cache sizes and parallelization degree for performance tuning.
signing_keysis optional and used for security in external message handling.
Struct: Config
Top-level configuration structure that aggregates:
Global parameters (
GlobalConfig)Network configuration (
NetworkConfig)Local node configuration (
NodeConfig)
Fields
Field | Type | Description |
|---|---|---|
|
| Global operational parameters, with a default set. |
|
| Network-specific settings such as peers and certificates. |
|
| Local node-specific configuration parameters. |
Methods
gossip_config() -> anyhow::Result<gossip::GossipConfig>Constructs a gossip protocol configuration based on network settings.
Uses fields like listen address, advertise address, seed nodes, and cluster ID.
gossip_peer() -> anyhow::Result<GossipPeer<NodeIdentifier>>Creates a GossipPeer instance representing this node in the gossip network.
Uses local node identifier, network advertisement address, proxies, API sockets, and resolved signing keys.
network_config(tls_cert_cache: Option<TlsCertCache>) -> anyhow::Result<network::config::NetworkConfig>Builds the network configuration object required for communication.
Loads certificate files and key files.
Resolves signing keys and sets up certificate stores.
Includes peer public keys set and subscription topics.
Function: must_save_state_on_seq_no
pub fn must_save_state_on_seq_no(
seq_no: BlockSeqNo,
parent_seq_no: Option<BlockSeqNo>,
save_state_frequency: u32,
) -> bool
Determines whether the node should save its state at a given block sequence number.
Parameters
seq_no: Current block sequence number.parent_seq_no: Optional sequence number of the parent block.save_state_frequency: Frequency in blocks at which the state should be saved.
Returns
bool:trueif the state should be saved at the current sequence number, otherwisefalse.
Logic
If a
parent_seq_nois provided, compares the division of parent and current sequence numbers bysave_state_frequency.If they differ, it means a save should occur to mark a new interval.
If no
parent_seq_nois given, saves state ifseq_nois an exact multiple ofsave_state_frequency.
Usage Example
let save = must_save_state_on_seq_no(current_seq_no, Some(parent_seq_no), 200);
if save {
// Trigger state saving logic
}
Interaction with Other System Components
Uses
network_configmodule for network-related settings and certificates.Uses
serde_configmodule for loading and saving configuration files.Interacts with
transport_layerfor cryptographic key resolution and TLS certificate caching.References node identity and block sequence number types from the local crate.
Provides configuration information consumed by node runtime components responsible for block production, synchronization, networking, and state management.
Mermaid Diagram: Structure of Configurations in mod.rs
classDiagram
class GlobalConfig {
+time_to_produce_block_millis: u64
+time_to_verify_block_millis: u64
+time_to_produce_transaction_millis: Option<u64>
+time_to_verify_transaction_millis: Option<u64>
+attestation_resend_timeout: Duration
+need_synchronization_block_diff: BlockSeqNo
+producer_change_gap_size: usize
+save_state_frequency: u32
+thread_count_soft_limit: usize
+round_min_time_millis: u64
}
class NodeConfig {
+node_id: NodeIdentifier
+blockchain_config_path: PathBuf
+key_path: String
+zerostate_path: PathBuf
+parallelization_level: usize
+block_cache_size: usize
+rate_limit_on_incoming_block_req: u32
+ext_messages_cache_size: usize
+node_wallet_pubkey: String
+signing_keys: Option<String>
}
class NetworkConfig {
<<imported>>
}
class Config {
+global: GlobalConfig
+network: NetworkConfig
+local: NodeConfig
+gossip_config()
+gossip_peer()
+network_config()
}
Config --> GlobalConfig
Config --> NetworkConfig
Config --> NodeConfig
Usage Notes
Configuration files are typically loaded from JSON or similar serialized formats using functions from
serde_config.Default values are provided for most parameters, facilitating easier initialization.
Network and gossip configurations are dynamically constructed from the loaded settings for communication setup.
The
NodeConfigbuilder pattern allows selective overriding of defaults for custom node setups.Timing and synchronization parameters in
GlobalConfigare critical for maintaining consensus and correct operation as per the blockchain protocol requirements.
References
For details on gossip protocol configuration and peer management, see
Gossip ProtocolandNode Identity and Networking.For cryptographic key and certificate management, see
Cryptographic Credentials.For configuration file serialization and deserialization, see
Serialization and Deserialization.For block sequence numbering and synchronization logic, see
Block SynchronizationandBlockchain State Management.