openmina_core/
constants.rs1use binprot_derive::BinProtWrite;
2use mina_curves::pasta::Fp;
3use mina_p2p_messages::{bigint, number, v2};
4
5pub const GENESIS_PRODUCER_SK: &str = "EKFKgDtU3rcuFTVSEpmpXSkukjmX4cKefYREi6Sdsk7E7wsT7KRw";
6
7pub const PROTOCOL_VERSION: v2::ProtocolVersionStableV2 = v2::ProtocolVersionStableV2 {
8 transaction: number::Number(3),
9 network: number::Number(0),
10 patch: number::Number(0),
11};
12
13pub fn constraint_constants() -> &'static ConstraintConstants {
14 NetworkConfig::global().constraint_constants
15}
16
17#[derive(Clone, Debug)]
18pub struct ForkConstants {
19 pub state_hash: Fp,
20 pub blockchain_length: u32,
21 pub global_slot_since_genesis: u32,
22}
23
24#[derive(Clone, Debug)]
25pub struct ConstraintConstants {
26 pub sub_windows_per_window: u64,
27 pub ledger_depth: u64,
28 pub work_delay: u64,
29 pub block_window_duration_ms: u64,
30 pub transaction_capacity_log_2: u64,
31 pub pending_coinbase_depth: usize,
32 pub coinbase_amount: u64,
33 pub supercharged_coinbase_factor: u64,
34 pub account_creation_fee: u64,
35 pub fork: Option<ForkConstants>,
36}
37#[derive(Clone, Debug, BinProtWrite)]
38pub struct ForkConstantsUnversioned {
39 previous_state_hash: bigint::BigInt,
40 previous_length: number::Int32,
41 genesis_slot: number::Int32,
42}
43
44impl From<&ForkConstants> for ForkConstantsUnversioned {
45 fn from(fork_constants: &ForkConstants) -> Self {
46 Self {
47 previous_state_hash: fork_constants.state_hash.into(),
48 previous_length: fork_constants.blockchain_length.into(),
49 genesis_slot: fork_constants.global_slot_since_genesis.into(),
50 }
51 }
52}
53
54#[derive(Clone, Debug, BinProtWrite)]
55pub struct ConstraintConstantsUnversioned {
56 pub sub_windows_per_window: number::Int64,
57 pub ledger_depth: number::Int64,
58 pub work_delay: number::Int64,
59 pub block_window_duration_ms: number::Int64,
60 pub transaction_capacity_log_2: number::Int64,
61 pub pending_coinbase_depth: number::Int64,
62 pub coinbase_amount: number::UInt64,
63 pub supercharged_coinbase_factor: number::Int64,
64 pub account_creation_fee: number::UInt64,
65 pub fork: Option<ForkConstantsUnversioned>,
66}
67
68impl From<&ConstraintConstants> for ConstraintConstantsUnversioned {
69 fn from(constraints: &ConstraintConstants) -> Self {
70 Self {
71 sub_windows_per_window: constraints.sub_windows_per_window.into(),
72 ledger_depth: constraints.ledger_depth.into(),
73 work_delay: constraints.work_delay.into(),
74 block_window_duration_ms: constraints.block_window_duration_ms.into(),
75 transaction_capacity_log_2: constraints.transaction_capacity_log_2.into(),
76 pending_coinbase_depth: (constraints.pending_coinbase_depth as u64).into(),
77 coinbase_amount: constraints.coinbase_amount.into(),
78 supercharged_coinbase_factor: constraints.supercharged_coinbase_factor.into(),
79 account_creation_fee: constraints.account_creation_fee.into(),
80 fork: constraints.fork.as_ref().map(|fork| fork.into()),
81 }
82 }
83}
84
85impl binprot::BinProtWrite for ConstraintConstants {
86 fn binprot_write<W: std::io::Write>(&self, w: &mut W) -> std::io::Result<()> {
87 let constraints: ConstraintConstantsUnversioned = self.into();
88 constraints.binprot_write(w)
89 }
90}
91
92pub fn slots_per_window(constants: &v2::MinaBaseProtocolConstantsCheckedValueStableV1) -> u32 {
93 constants.slots_per_sub_window.as_u32() * (constraint_constants().sub_windows_per_window as u32)
94}
95
96const fn days_to_ms(days: u64) -> u64 {
97 days * 24 * 60 * 60 * 1000
98}
99
100pub const CHECKPOINTS_PER_YEAR: u64 = 12;
101
102pub fn checkpoint_window_size_in_slots() -> u32 {
103 let one_year_ms = days_to_ms(365);
104 let slots_per_year = one_year_ms / constraint_constants().block_window_duration_ms;
105 let size_in_slots = slots_per_year / CHECKPOINTS_PER_YEAR;
106 assert_eq!(slots_per_year % CHECKPOINTS_PER_YEAR, 0);
107 size_in_slots as u32
108}
109
110pub const DEFAULT_GENESIS_TIMESTAMP_MILLISECONDS: u64 = 1707157200000;
111
112pub const PROTOCOL_TRANSACTION_VERSION: u8 = 3;
113pub const PROTOCOL_NETWORK_VERSION: u8 = 3;
114pub const TX_POOL_MAX_SIZE: u32 = 3000;
115
116pub use v2::PROTOCOL_CONSTANTS;
117
118use crate::NetworkConfig;