Skip to main content

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