Expand description
Chain identifier and network discrimination for Mina Protocol.
This module provides the ChainId
type, which uniquely identifies
different Mina blockchain networks (Mainnet, Devnet, etc.) and ensures peers
only connect to compatible networks. The chain ID is computed from protocol
parameters, genesis state, and constraint system digests to create a
deterministic network identifier.
§Purpose
Chain IDs serve multiple critical functions in the Mina protocol:
- Network Isolation: Prevents nodes from different networks (e.g., mainnet vs devnet) from connecting to each other
- Protocol Compatibility: Ensures all peers use the same protocol parameters
- Security: Used in cryptographic operations and peer authentication
- Private Network Support: Enables creation of isolated test networks
§Chain ID Computation
The chain ID is a 32-byte Blake2b hash computed from:
- Genesis State Hash: The hash of the initial blockchain state
- Constraint System Digests: Hashes of the SNARK constraint systems
- Genesis Constants: Protocol parameters like slot timing and consensus settings
- Protocol Versions: Transaction and network protocol version numbers
- Transaction Pool Size: Maximum transaction pool configuration
This ensures that any change to fundamental protocol parameters results in a different chain ID, preventing incompatible nodes from connecting.
§Network Identifiers
OpenMina includes predefined chain IDs for official networks:
MAINNET_CHAIN_ID
: The production Mina blockchainDEVNET_CHAIN_ID
: The development/testing blockchain
Custom networks can compute their own chain IDs using ChainId::compute()
.
§Usage in Networking
Chain IDs are used throughout OpenMina’s networking stack:
- Peer Discovery: Nodes advertise their chain ID to find compatible peers
- Connection Authentication: WebRTC and libp2p connections verify chain ID compatibility
- Private Networks: The
preshared_key()
method generates cryptographic keys for private network isolation
§Example
use openmina_core::ChainId;
// Use predefined network
let mainnet_id = openmina_core::MAINNET_CHAIN_ID;
println!("Mainnet ID: {}", mainnet_id);
// Parse from hex string
let chain_id = ChainId::from_hex("a7351abc7ddf2ea92d1b38cc8e636c271c1dfd2c081c637f62ebc2af34eb7cc1")?;
// Generate preshared key for private networking
let psk = chain_id.preshared_key();
Structs§
- ChainId
- Unique identifier for a Mina blockchain network.
Constants§
- DEVNET_
CHAIN_ ID - Chain ID for the Mina development network (Devnet).
- MAINNET_
CHAIN_ ID - Chain ID for the Mina production network (Mainnet).
Functions§
Type Aliases§
- Md5 🔒