mx_core/constants.rs
1//! `MultiversX` protocol constants.
2//!
3//! This module provides shared protocol constants used across the entire workspace.
4//! All crates should import these constants from mx-core to ensure consistency.
5
6/// Special shard ID for metachain (0xFFFFFFFF).
7///
8/// This value represents `u32::MAX` and is used throughout the `MultiversX` protocol
9/// to identify operations and data structures that belong to the metachain.
10///
11/// Prefer [`METACHAIN_SHARD_ID`] which is the canonical name used across
12/// the codebase. Both constants hold the same value (`0xFFFF_FFFF`).
13#[deprecated(note = "Use METACHAIN_SHARD_ID instead")]
14pub const META_SHARD_ID: u32 = u32::MAX;
15
16/// Alias for metachain shard ID used in P2P topics.
17///
18/// This is identical to `META_SHARD_ID` (both are `0xFFFF_FFFF`) and exists
19/// for clarity when working with gossipsub topic names.
20pub const METACHAIN_SHARD_ID: u32 = 0xFFFF_FFFF;
21
22/// Shard ID representing all shards in P2P topics.
23///
24/// This special value (`0xFFFF_FFF0`) is used in gossipsub topic suffixes
25/// to indicate that a message should be broadcast to all shards.
26pub const ALL_SHARD_ID: u32 = 0xFFFF_FFF0;
27
28/// Transaction option flag for hash signing (keccak256 hash instead of raw JSON).
29///
30/// When this flag is set in the transaction options field, the signature
31/// is computed over the keccak256 hash of the transaction JSON payload
32/// rather than the raw JSON bytes.
33pub const TX_OPTION_HASH_SIGN: u32 = 1;
34
35/// Transaction option flag for guarded transactions.
36///
37/// When this flag is set, the transaction includes a guardian signature
38/// for additional security.
39pub const TX_OPTION_GUARDED: u32 = 2;
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[allow(deprecated)]
46 #[test]
47 fn test_meta_shard_id_consistency() {
48 // Verify that META_SHARD_ID and METACHAIN_SHARD_ID are identical
49 assert_eq!(META_SHARD_ID, METACHAIN_SHARD_ID);
50 assert_eq!(META_SHARD_ID, 0xFFFF_FFFF);
51 assert_eq!(META_SHARD_ID, u32::MAX);
52 }
53
54 #[allow(deprecated)]
55 #[test]
56 fn test_all_shard_id() {
57 assert_eq!(ALL_SHARD_ID, 0xFFFF_FFF0);
58 // Verify it's distinct from metachain
59 assert_ne!(ALL_SHARD_ID, META_SHARD_ID);
60 }
61
62 #[test]
63 fn test_tx_option_flags() {
64 assert_eq!(TX_OPTION_HASH_SIGN, 1);
65 assert_eq!(TX_OPTION_GUARDED, 2);
66 // Verify flags are distinct
67 assert_ne!(TX_OPTION_HASH_SIGN, TX_OPTION_GUARDED);
68 }
69}