node.rs

Overview

This file implements the main entry point and core runtime logic for the Acki-Nacki node, which is a critical component responsible for participating in the blockchain network. It manages node initialization, configuration loading, network setup, block processing, validation, threading, and graceful shutdown. The node coordinates multiple services and threads to maintain the blockchain state, process blocks, handle attestation, and communicate with other nodes through gossip and network protocols.

The file contains the Args struct for command-line argument parsing, initialization routines, an asynchronous main runtime using Tokio, and various helper functions. It orchestrates the interaction between networking, storage, cryptographic keys, block producers, validators, and HTTP APIs.


Main Entities and Functions

Args Struct

Usage example:

let args = Args::parse();
println!("Config file: {:?}", args.config_path);

main() -> Result<(), std::io::Error>


tokio_main()


execute(args: Args, metrics: Option<Metrics>) -> anyhow::Result<()>

Main responsibilities:

This function orchestrates almost all major components and threads of the node.


verify_zerostate(zs: &ZeroState, message_db: &MessageDurableStorage) -> anyhow::Result<()>

Checks performed:


dispatch_hot_reload(...)


clear_missing_block_locks(...) -> anyhow::Result<HashMap<ThreadIdentifier, ActionLockCollection>>

Algorithm:


into_external_message(message: tvm_block::Message, thread_id: ThreadIdentifier) -> anyhow::Result<NetworkMessage>


resolve_bp(...) -> ResolvingResult


debug_used_features()


Important Implementation Details


Interactions with Other Parts of the System


Visual Diagram: Class and Major Structs Interaction

classDiagram
class Node {
+new()
+execute()
}
class Args {
+config_path: PathBuf
+clear_missing_block_locks: bool
+check_zerostate_validity: bool
}
class RepositoryImpl {
+load_saved_blocks()
+select_thread_last_finalized_block()
+get_all_metadata()
}
class BlockStateRepository {
+get()
}
class Authority {
+builder()
+get_thread_authority()
}
class ValidationService {
+new()
+interface()
}
class BlockProcessorService {
+new()
}
class TVMBlockProducerProcess {
+builder()
+build()
}
class RoutingService {
+new()
+start()
}
class GossipHandle {
+with_chitchat()
}
class BasicNetwork {
+new()
+start()
}
class MessageDurableStorage {}
class ActionLockCollection {
+new()
+get()
+remove()
}
Node --> RepositoryImpl : uses
Node --> ValidationService : uses
Node --> BlockProcessorService : uses
Node --> TVMBlockProducerProcess : uses
Node --> Authority : holds
Node --> RoutingService : interacts
RoutingService --> BasicNetwork : uses
BasicNetwork --> GossipHandle : uses
RepositoryImpl --> BlockStateRepository : uses
RepositoryImpl --> ActionLockCollection : manages
execute o-- Args : reads
execute --> RepositoryImpl : creates
execute --> BlockStateRepository : creates
execute --> Authority : creates
execute --> ValidationService : creates
execute --> GossipHandle : creates
execute --> BasicNetwork : creates

Usage Flow (Simplified)

  1. Startup: main() initializes runtime and calls tokio_main().

  2. Argument Parsing: Args::parse() reads command-line options.

  3. Tracing & Metrics: Initialize observability.

  4. Configuration Loading: Load node, network, gossip, and Aerospike configs.

  5. Storage Initialization: Setup durable stores, caches, block state repositories.

  6. Zerostate Loading & Verification: Load blockchain zerostate, verify integrity.

  7. Network & Gossip Start: Start gossip and network layers.

  8. Signal Handling: Spawn thread to handle SIGHUP (reload), SIGINT/SIGTERM (shutdown).

  9. Routing & Node Threads: Start routing and spawn a Node instance per blockchain thread.

  10. Services Startup: Start block processor, validation, attestation, HTTP server, message router.

  11. Runtime Operation: Node runs asynchronously, processing blocks, syncing state, handling messages.

  12. Shutdown: On signal, cleanly shutdown services, save state, and exit.


References


This file is the orchestrator and runtime core that integrates multiple components and services into a working blockchain node instance capable of syncing, producing, validating, and serving blockchain data in a distributed network environment.