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:

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

Imports & Re-exports


Struct: GlobalConfig

Represents global timing, synchronization, and operational parameters for the node.

Field

Type

Description

Default

time_to_produce_block_millis

u64

Duration in milliseconds for one iteration of block production cycle.

330

time_to_verify_block_millis

u64

Maximum verification duration for one block.

440 (330 * 4 / 3)

time_to_produce_transaction_millis

Option<u64>

Max execution duration for producing one transaction.

None

time_to_verify_transaction_millis

Option<u64>

Max execution duration for verifying one transaction.

None

time_to_verify_transaction_aborted_with_execution_timeout_millis

Option<u64>

Max execution duration for verifying transactions aborted due to execution timeout.

Derived from produce time

attestation_resend_timeout

Duration

Timeout between resending attestations.

3 seconds

need_synchronization_block_diff

<BlockSeqNo as Sub>::Output

Threshold difference in block sequence number to trigger node synchronization.

20

min_time_between_state_publish_directives

Duration

Minimum time interval between publishing state directives.

600 seconds

producer_change_gap_size

usize

Block gap size that triggers block producer rotation.

6

node_joining_timeout

Duration

Timeout between consecutive NodeJoining messages.

300 seconds

sync_gap

u64

Block gap before sharing state during synchronization.

32

sync_delay_milliseconds

u128

Delay node waits after receiving an unapplicable block before switching to sync mode.

500

save_state_frequency

u32

Frequency (in blocks) for saving optimistic state.

200

block_keeper_epoch_code_hash

String

Hash of the block keeper epoch code.

Hex string

block_keeper_preepoch_code_hash

String

Hash of the block keeper preepoch code.

Hex string

thread_count_soft_limit

usize

Expected maximum number of threads.

100

thread_load_threshold

usize

Load threshold to trigger thread splitting.

5000

thread_load_window_size

usize

Window size for thread load calculation.

100

chance_of_successful_attack

f64

Probability estimate for a successful attack.

1e-9

round_min_time_millis

u64

Minimum time duration for block producer rotation round.

10,000

round_step_millis

u64

Incremental step time for the rotation round.

1,000

round_max_time_millis

u64

Maximum time duration for block producer rotation round.

30,000

time_to_enable_sync_finalized

Duration

Minimal time after the last finalization to enable synchronization start.

1200 seconds

Implementation Details


Struct: NodeConfig

Represents node-specific configuration parameters related to identity, file paths, caching, parallelization, and rate limiting.

Field

Type

Description

Default

node_id

NodeIdentifier

Unique identifier for the node.

Required

blockchain_config_path

PathBuf

Path to blockchain configuration file. Deprecated and unused.

"blockchain_config.json"

key_path

String

Path to BLS key pair file.

"block_keeper.keys.json"

block_keeper_seed_path

String

Path to block keeper seed key file.

"block_keeper.keys.json"

zerostate_path

PathBuf

Path to the zerostate file.

"zerostate"

bk_set_update_path

Option<PathBuf>

Optional path to block keeper set update file. Must match the /v2/bk_set_update API output format.

None

external_state_share_local_base_dir

PathBuf

Local directory path shared with other nodes.

"/tmp"

parallelization_level

usize

Degree of parallelization for block production.

20

block_cache_size

usize

Size of the block cache in the local repository.

20

state_cache_size

usize

Size of the state cache in the local repository.

10

unload_after

Option<u32>

Number of blocks after which accounts are unloaded from shard state.

None

rate_limit_on_incoming_block_req

u32

Limit on calls per second to on_incoming_block_request function.

u32::MAX

ext_messages_cache_size

usize

Size of the external messages cache.

1000

node_wallet_pubkey

String

BlockKeeper node owner wallet public key.

Empty string ("")

signing_keys

Option<String>

Path to signing keys file for authorizing incoming external messages. Required for direct external message sending.

None

Implementation Details


Struct: Config

Top-level configuration structure that aggregates:

Fields

Field

Type

Description

global

GlobalConfig

Global operational parameters, with a default set.

network

NetworkConfig

Network-specific settings such as peers and certificates.

local

NodeConfig

Local node-specific configuration parameters.

Methods


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

Returns

Logic

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


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


References