chia_consensus/
consensus_constants.rs

1use chia_protocol::Bytes32;
2use chia_streamable_macro::streamable;
3
4#[cfg(feature = "py-bindings")]
5use chia_py_streamable_macro::{PyGetters, PyJsonDict, PyStreamable};
6use hex_literal::hex;
7
8#[cfg_attr(
9    feature = "py-bindings",
10    pyo3::pyclass(module = "chia_rs"),
11    derive(PyJsonDict, PyStreamable, PyGetters),
12    py_uppercase,
13    py_pickle
14)]
15#[streamable]
16pub struct ConsensusConstants {
17    /// How many blocks to target per sub-slot.
18    slot_blocks_target: u32,
19
20    /// How many blocks must be created per slot (to make challenge sb).
21    min_blocks_per_challenge_block: u8,
22
23    /// Max number of blocks that can be infused into a sub-slot.
24    /// Note: This must be less than SUB_EPOCH_BLOCKS/2, and > SLOT_BLOCKS_TARGET.
25    max_sub_slot_blocks: u32,
26
27    /// The number of signage points per sub-slot (including the 0th sp at the sub-slot start).
28    num_sps_sub_slot: u8,
29
30    /// The sub_slot_iters for the first epoch.
31    sub_slot_iters_starting: u64,
32
33    /// Multiplied by the difficulty to get iterations.
34    difficulty_constant_factor: u128,
35
36    /// The difficulty for the first epoch.
37    difficulty_starting: u64,
38
39    /// The maximum factor by which difficulty and sub_slot_iters can change per epoch.
40    difficulty_change_max_factor: u32,
41
42    /// The number of blocks per sub-epoch.
43    sub_epoch_blocks: u32,
44
45    /// The number of blocks per sub-epoch, must be a multiple of SUB_EPOCH_BLOCKS.
46    epoch_blocks: u32,
47
48    /// The number of bits to look at in difficulty and min iters. The rest are zeroed.
49    significant_bits: u8,
50
51    /// Max is 1024 (based on ClassGroupElement int size).
52    discriminant_size_bits: u16,
53
54    /// H(plot id + challenge hash + signage point) must start with these many zeroes.
55    /// This applies to original plots, and proof-of-space format
56    number_zero_bits_plot_filter_v1: u8,
57
58    /// H(plot id + challenge hash + signage point) must start with these many zeroes.
59    /// This applies to the new plot format, and proof-of-space format
60    number_zero_bits_plot_filter_v2: u8,
61
62    /// The smallest and largest allowed plot size for the original plot
63    /// format, v1. These are the K-values for the plots.
64    min_plot_size_v1: u8,
65    max_plot_size_v1: u8,
66
67    /// The smallest and largest allowed plot size for the the new plot
68    /// format, v2. These are the K-values for the plots. In addition to these
69    /// constraints, v2 plot sizes must be even numbers. The new plot format
70    /// was introduced in Chia-3.0.
71    min_plot_size_v2: u8,
72    max_plot_size_v2: u8,
73
74    /// The target number of seconds per sub-slot.
75    sub_slot_time_target: u16,
76
77    /// The difference between signage point and infusion point (plus required_iters).
78    num_sp_intervals_extra: u8,
79
80    /// After soft-fork2, this is the new MAX_FUTURE_TIME.
81    max_future_time2: u32,
82
83    /// Than the average of the last NUMBER_OF_TIMESTAMPS blocks.
84    number_of_timestamps: u8,
85
86    /// Used as the initial cc rc challenges, as well as first block back pointers, and first SES back pointer.
87    /// We override this value based on the chain being run (testnet0, testnet1, mainnet, etc).
88    genesis_challenge: Bytes32,
89
90    /// Forks of chia should change these values to provide replay attack protection.
91    agg_sig_me_additional_data: Bytes32,
92    /// By convention, the below additional data is derived from the agg_sig_me_additional_data
93    agg_sig_parent_additional_data: Bytes32,
94    agg_sig_puzzle_additional_data: Bytes32,
95    agg_sig_amount_additional_data: Bytes32,
96    agg_sig_puzzle_amount_additional_data: Bytes32,
97    agg_sig_parent_amount_additional_data: Bytes32,
98    agg_sig_parent_puzzle_additional_data: Bytes32,
99
100    /// The block at height must pay out to this pool puzzle hash.
101    genesis_pre_farm_pool_puzzle_hash: Bytes32,
102
103    /// The block at height must pay out to this farmer puzzle hash.
104    genesis_pre_farm_farmer_puzzle_hash: Bytes32,
105
106    /// The maximum number of classgroup elements within an n-wesolowski proof.
107    max_vdf_witness_size: u8,
108
109    /// Size of mempool = 10x the size of block.
110    mempool_block_buffer: u8,
111
112    /// Max coin amount uint(1 << 64). This allows coin amounts to fit in 64 bits. This is around 18M chia.
113    max_coin_amount: u64,
114
115    /// Max block cost in clvm cost units.
116    max_block_cost_clvm: u64,
117
118    /// Cost per byte of generator program.
119    cost_per_byte: u64,
120
121    weight_proof_threshold: u8,
122
123    weight_proof_recent_blocks: u32,
124
125    max_block_count_per_requests: u32,
126
127    blocks_cache_size: u32,
128
129    max_generator_size: u32,
130
131    max_generator_ref_list_size: u32,
132
133    pool_sub_slot_iters: u64,
134
135    /// The hard fork planned with the 2.0 release.
136    /// This is the block with the first plot filter adjustment.
137    hard_fork_height: u32,
138
139    /// The hard fork planned with the 3.0 release.
140    /// This is the first block where the new plot format and proof-of-space
141    /// is valid
142    hard_fork2_height: u32,
143
144    /// The 128 plot filter adjustment height.
145    /// This affects the plot filter for original plots
146    plot_filter_128_height: u32,
147
148    /// The 64 plot filter adjustment height.
149    /// This affects the plot filter for original plots
150    plot_filter_64_height: u32,
151
152    /// The 32 plot filter adjustment height.
153    /// This affects the plot filter for original plots
154    plot_filter_32_height: u32,
155
156    /// initial plot difficulty for the v2 plot format.
157    plot_difficulty_initial: u8,
158
159    /// Plot difficulty is a feature of the new plot format, v2 (introduced in Chia 3.0)
160    /// The plot difficulty will increase at these block heights. The new
161    /// difficulty will be 4, 5, 6, 7 and 8 respectively.
162    plot_difficulty_4_height: u32,
163    plot_difficulty_5_height: u32,
164    plot_difficulty_6_height: u32,
165    plot_difficulty_7_height: u32,
166    plot_difficulty_8_height: u32,
167}
168
169pub const TEST_CONSTANTS: ConsensusConstants = ConsensusConstants {
170    slot_blocks_target: 32,
171    min_blocks_per_challenge_block: 16,
172    max_sub_slot_blocks: 128,
173    num_sps_sub_slot: 64,
174    sub_slot_iters_starting: u64::pow(2, 27),
175    difficulty_constant_factor: u128::pow(2, 67),
176    difficulty_starting: 7,
177    difficulty_change_max_factor: 3,
178    sub_epoch_blocks: 384,
179    epoch_blocks: 4608,
180    significant_bits: 8,
181    discriminant_size_bits: 1024,
182    number_zero_bits_plot_filter_v1: 9,
183    number_zero_bits_plot_filter_v2: 9, // placeholder
184    min_plot_size_v1: 32,
185    max_plot_size_v1: 50,
186    min_plot_size_v2: 28,
187    max_plot_size_v2: 32,
188    sub_slot_time_target: 600,
189    num_sp_intervals_extra: 3,
190    max_future_time2: 2 * 60,
191    number_of_timestamps: 11,
192    genesis_challenge: Bytes32::new(hex!(
193        "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"
194    )),
195    agg_sig_me_additional_data: Bytes32::new(hex!(
196        "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"
197    )),
198    agg_sig_parent_additional_data: Bytes32::new(hex!(
199        "baf5d69c647c91966170302d18521b0a85663433d161e72c826ed08677b53a74"
200    )),
201    agg_sig_puzzle_additional_data: Bytes32::new(hex!(
202        "284fa2ef486c7a41cc29fc99c9d08376161e93dd37817edb8219f42dca7592c4"
203    )),
204    agg_sig_amount_additional_data: Bytes32::new(hex!(
205        "cda186a9cd030f7a130fae45005e81cae7a90e0fa205b75f6aebc0d598e0348e"
206    )),
207    agg_sig_puzzle_amount_additional_data: Bytes32::new(hex!(
208        "0f7d90dff0613e6901e24dae59f1e690f18b8f5fbdcf1bb192ac9deaf7de22ad"
209    )),
210    agg_sig_parent_amount_additional_data: Bytes32::new(hex!(
211        "585796bd90bb553c0430b87027ffee08d88aba0162c6e1abbbcc6b583f2ae7f9"
212    )),
213    agg_sig_parent_puzzle_additional_data: Bytes32::new(hex!(
214        "2ebfdae17b29d83bae476a25ea06f0c4bd57298faddbbc3ec5ad29b9b86ce5df"
215    )),
216    genesis_pre_farm_pool_puzzle_hash: Bytes32::new(hex!(
217        "d23da14695a188ae5708dd152263c4db883eb27edeb936178d4d988b8f3ce5fc"
218    )),
219    genesis_pre_farm_farmer_puzzle_hash: Bytes32::new(hex!(
220        "3d8765d3a597ec1d99663f6c9816d915b9f68613ac94009884c4addaefcce6af"
221    )),
222    max_vdf_witness_size: 64,
223    mempool_block_buffer: 10,
224    max_coin_amount: u64::MAX,
225    max_block_cost_clvm: 11_000_000_000,
226    cost_per_byte: 12000,
227    weight_proof_threshold: 2,
228    blocks_cache_size: 4608 + (128 * 4),
229    weight_proof_recent_blocks: 1000,
230    max_block_count_per_requests: 32,
231    max_generator_size: 1_000_000,
232    max_generator_ref_list_size: 512,
233    pool_sub_slot_iters: 37_600_000_000,
234    hard_fork_height: 5_496_000,
235    hard_fork2_height: 0xffff_ffff, // placeholder
236    plot_filter_128_height: 10_542_000,
237    plot_filter_64_height: 15_592_000,
238    plot_filter_32_height: 20_643_000,
239
240    // placeholder values
241    plot_difficulty_initial: 2,
242    plot_difficulty_4_height: 0xffff_ffff,
243    plot_difficulty_5_height: 0xffff_ffff,
244    plot_difficulty_6_height: 0xffff_ffff,
245    plot_difficulty_7_height: 0xffff_ffff,
246    plot_difficulty_8_height: 0xffff_ffff,
247};