-
Notifications
You must be signed in to change notification settings - Fork 679
/
Copy pathmod.rs
1476 lines (1387 loc) · 56.8 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2013-2020 Blockstack PBC, a public benefit corporation
// Copyright (C) 2020 Stacks Open Internet Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::collections::HashSet;
use clarity::vm::costs::ExecutionCost;
use lazy_static::lazy_static;
use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksBlockId};
use stacks_common::types::StacksEpoch as GenericStacksEpoch;
pub use stacks_common::types::StacksEpochId;
use stacks_common::util::log;
pub use self::mempool::MemPoolDB;
use crate::burnchains::bitcoin::indexer::get_bitcoin_stacks_epochs;
use crate::burnchains::bitcoin::BitcoinNetworkType;
use crate::burnchains::{Burnchain, Error as burnchain_error};
use crate::chainstate::burn::ConsensusHash;
pub mod mempool;
#[cfg(test)]
pub mod tests;
use std::cmp::Ordering;
pub type StacksEpoch = GenericStacksEpoch<ExecutionCost>;
// fork set identifier -- to be mixed with the consensus hash (encodes the version)
pub const SYSTEM_FORK_SET_VERSION: [u8; 4] = [23u8, 0u8, 0u8, 0u8];
// chain id
pub use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, STACKS_EPOCH_MAX};
// peer version (big-endian)
// first byte == major network protocol version (currently 0x18)
// second and third bytes are unused
// fourth byte == highest epoch supported by this node
pub const PEER_VERSION_MAINNET_MAJOR: u32 = 0x18000000;
pub const PEER_VERSION_TESTNET_MAJOR: u32 = 0xfacade00;
pub const PEER_VERSION_EPOCH_1_0: u8 = 0x00;
pub const PEER_VERSION_EPOCH_2_0: u8 = 0x00;
pub const PEER_VERSION_EPOCH_2_05: u8 = 0x05;
pub const PEER_VERSION_EPOCH_2_1: u8 = 0x06;
pub const PEER_VERSION_EPOCH_2_2: u8 = 0x07;
pub const PEER_VERSION_EPOCH_2_3: u8 = 0x08;
pub const PEER_VERSION_EPOCH_2_4: u8 = 0x09;
pub const PEER_VERSION_EPOCH_2_5: u8 = 0x0a;
pub const PEER_VERSION_EPOCH_3_0: u8 = 0x0b;
// this should be updated to the latest network epoch version supported by
// this node. this will be checked by the `validate_epochs()` method.
pub const PEER_NETWORK_EPOCH: u32 = PEER_VERSION_EPOCH_2_5 as u32;
// set the fourth byte of the peer version
pub const PEER_VERSION_MAINNET: u32 = PEER_VERSION_MAINNET_MAJOR | PEER_NETWORK_EPOCH;
pub const PEER_VERSION_TESTNET: u32 = PEER_VERSION_TESTNET_MAJOR | PEER_NETWORK_EPOCH;
// network identifiers
pub const NETWORK_ID_MAINNET: u32 = 0x17000000;
pub const NETWORK_ID_TESTNET: u32 = 0xff000000;
// default port
pub const NETWORK_P2P_PORT: u16 = 6265;
// sliding burnchain window over which a miner's past block-commit payouts will be used to weight
// its current block-commit in a sortition
pub const MINING_COMMITMENT_WINDOW: u8 = 6;
// Number of previous burnchain blocks to search to find burnchain-hosted Stacks operations
pub const BURNCHAIN_TX_SEARCH_WINDOW: u8 = 6;
// This controls a miner heuristic for dropping a transaction from repeated consideration
// in the mempool. If the transaction caused the block limit to be reached when the block
// was previously `TX_BLOCK_LIMIT_PROPORTION_HEURISTIC`% full, the transaction will be dropped
// from the mempool. 20% is chosen as a heuristic here to allow for large transactions to be
// attempted, but if they cannot be included in an otherwise mostly empty block, not to consider
// them again.
pub const TX_BLOCK_LIMIT_PROPORTION_HEURISTIC: u64 = 20;
pub const GENESIS_EPOCH: StacksEpochId = StacksEpochId::Epoch20;
/// The number of blocks which will share the block bonus
/// from burn blocks that occurred without a sortition.
/// (See: https://forum.stacks.org/t/pox-consensus-and-stx-future-supply)
#[cfg(test)]
pub const INITIAL_MINING_BONUS_WINDOW: u16 = 10;
#[cfg(not(test))]
pub const INITIAL_MINING_BONUS_WINDOW: u16 = 10_000;
pub const STACKS_2_0_LAST_BLOCK_TO_PROCESS: u64 = 700_000;
pub const MAINNET_2_0_GENESIS_ROOT_HASH: &str =
"9653c92b1ad726e2dc17862a3786f7438ab9239c16dd8e7aaba8b0b5c34b52af";
/// This is the "dummy" parent to the actual first burnchain block that we process.
pub const FIRST_BURNCHAIN_CONSENSUS_HASH: ConsensusHash = ConsensusHash([0u8; 20]);
// TODO: TO BE SET BY STACKS_V1_MINER_THRESHOLD
pub const BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT: u64 = 666050;
pub const BITCOIN_MAINNET_FIRST_BLOCK_TIMESTAMP: u32 = 1610643248;
pub const BITCOIN_MAINNET_FIRST_BLOCK_HASH: &str =
"0000000000000000000ab248c8e35c574514d052a83dbc12669e19bc43df486e";
pub const BITCOIN_MAINNET_INITIAL_REWARD_START_BLOCK: u64 = 651389;
pub const BITCOIN_MAINNET_STACKS_2_05_BURN_HEIGHT: u64 = 713_000;
pub const BITCOIN_MAINNET_STACKS_21_BURN_HEIGHT: u64 = 781_551;
/// This is Epoch-2.2 activation height proposed in SIP-022
pub const BITCOIN_MAINNET_STACKS_22_BURN_HEIGHT: u64 = 787_651;
/// This is Epoch-2.3 activation height proposed in SIP-023
pub const BITCOIN_MAINNET_STACKS_23_BURN_HEIGHT: u64 = 788_240;
/// This is Epoch-2.3, now Epoch-2.4, activation height proposed in SIP-024
pub const BITCOIN_MAINNET_STACKS_24_BURN_HEIGHT: u64 = 791_551;
/// This is Epoch-2.5, activation height proposed in SIP-021
pub const BITCOIN_MAINNET_STACKS_25_BURN_HEIGHT: u64 = 840_360;
/// This is Epoch-3.0, activation height proposed in SIP-021
pub const BITCOIN_MAINNET_STACKS_30_BURN_HEIGHT: u64 = 2_000_000;
pub const BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT: u64 = 2000000;
pub const BITCOIN_TESTNET_FIRST_BLOCK_TIMESTAMP: u32 = 1622691840;
pub const BITCOIN_TESTNET_FIRST_BLOCK_HASH: &str =
"000000000000010dd0863ec3d7a0bae17c1957ae1de9cbcdae8e77aad33e3b8c";
pub const BITCOIN_TESTNET_STACKS_2_05_BURN_HEIGHT: u64 = 2_104_380;
pub const BITCOIN_TESTNET_STACKS_21_BURN_HEIGHT: u64 = 2_422_101;
pub const BITCOIN_TESTNET_STACKS_22_BURN_HEIGHT: u64 = 2_431_300;
pub const BITCOIN_TESTNET_STACKS_23_BURN_HEIGHT: u64 = 2_431_633;
pub const BITCOIN_TESTNET_STACKS_24_BURN_HEIGHT: u64 = 2_432_545;
pub const BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT: u64 = 2_583_893;
pub const BITCOIN_TESTNET_STACKS_30_BURN_HEIGHT: u64 = 30_000_000;
/// This constant sets the approximate testnet bitcoin height at which 2.5 Xenon
/// was reorged back to 2.5 instantiation. This is only used to calculate the
/// expected affirmation maps (so it only must be accurate to the reward cycle).
pub const BITCOIN_TESTNET_STACKS_25_REORGED_HEIGHT: u64 = 2_586_000;
pub const BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT: u64 = 0;
pub const BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP: u32 = 0;
pub const BITCOIN_REGTEST_FIRST_BLOCK_HASH: &str =
"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206";
pub const FIRST_STACKS_BLOCK_HASH: BlockHeaderHash = BlockHeaderHash([0u8; 32]);
pub const EMPTY_MICROBLOCK_PARENT_HASH: BlockHeaderHash = BlockHeaderHash([0u8; 32]);
lazy_static! {
pub static ref FIRST_STACKS_BLOCK_ID: StacksBlockId =
StacksBlockId::new(&FIRST_BURNCHAIN_CONSENSUS_HASH, &FIRST_STACKS_BLOCK_HASH);
}
pub const BOOT_BLOCK_HASH: BlockHeaderHash = BlockHeaderHash([0xff; 32]);
pub const BURNCHAIN_BOOT_CONSENSUS_HASH: ConsensusHash = ConsensusHash([0xff; 20]);
pub const MICROSTACKS_PER_STACKS: u32 = 1_000_000;
pub const POX_SUNSET_START: u64 = 100_000;
pub const POX_SUNSET_END: u64 = POX_SUNSET_START + 400_000;
pub const POX_PREPARE_WINDOW_LENGTH: u32 = 100;
pub const POX_REWARD_CYCLE_LENGTH: u32 = 2100;
/// The maximum amount that PoX rewards can be scaled by.
/// That is, if participation is very low, rewards are:
/// POX_MAXIMAL_SCALING x (rewards with 100% participation)
/// Set a 4x, this implies the lower bound of participation for scaling
/// is 25%
pub const POX_MAXIMAL_SCALING: u128 = 4;
/// This is the amount that PoX threshold adjustments are stepped by.
pub const POX_THRESHOLD_STEPS_USTX: u128 = 10_000 * (MICROSTACKS_PER_STACKS as u128);
pub const POX_MAX_NUM_CYCLES: u8 = 12;
// These values are taken from the corresponding variables in `pox-tesnet.clar`.
pub const POX_TESTNET_STACKING_THRESHOLD_25: u128 = 8000;
pub const POX_TESTNET_CYCLE_LENGTH: u128 = 1050;
pub const POX_V1_MAINNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_MAINNET_STACKS_21_BURN_HEIGHT as u32) + 1;
pub const POX_V1_TESTNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_TESTNET_STACKS_21_BURN_HEIGHT as u32) + 1;
pub const POX_V2_MAINNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_MAINNET_STACKS_22_BURN_HEIGHT as u32) + 1;
pub const POX_V2_TESTNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_TESTNET_STACKS_22_BURN_HEIGHT as u32) + 1;
pub const POX_V3_MAINNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_MAINNET_STACKS_25_BURN_HEIGHT as u32) + 1;
pub const POX_V3_TESTNET_EARLY_UNLOCK_HEIGHT: u32 =
(BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT as u32) + 1;
/// Burn block height at which the ASTRules::PrecheckSize becomes the default behavior on mainnet
pub const AST_RULES_PRECHECK_SIZE: u64 = 752000; // on or about Aug 30 2022
// Stacks 1.0 did not allow smart contracts so all limits are 0.
pub const BLOCK_LIMIT_MAINNET_10: ExecutionCost = ExecutionCost {
write_length: 0,
write_count: 0,
read_length: 0,
read_count: 0,
runtime: 0,
};
// Block limit in Stacks 2.0.
pub const BLOCK_LIMIT_MAINNET_20: ExecutionCost = ExecutionCost {
write_length: 15_000_000, // roughly 15 mb
write_count: 7_750,
read_length: 100_000_000,
read_count: 7_750,
runtime: 5_000_000_000,
};
// Block limit in Stacks 2.05.
pub const BLOCK_LIMIT_MAINNET_205: ExecutionCost = ExecutionCost {
write_length: 15_000_000,
write_count: 15_000,
read_length: 100_000_000,
read_count: 15_000,
runtime: 5_000_000_000,
};
// Block limit in Stacks 2.1
pub const BLOCK_LIMIT_MAINNET_21: ExecutionCost = ExecutionCost {
write_length: 15_000_000,
write_count: 15_000,
read_length: 100_000_000,
read_count: 15_000,
runtime: 5_000_000_000,
};
// Block limit for the testnet in Stacks 2.0.
pub const HELIUM_BLOCK_LIMIT_20: ExecutionCost = ExecutionCost {
write_length: 15_0_000_000,
write_count: 5_0_000,
read_length: 1_000_000_000,
read_count: 5_0_000,
// allow much more runtime in helium blocks than mainnet
runtime: 100_000_000_000,
};
pub const FAULT_DISABLE_MICROBLOCKS_COST_CHECK: &str = "MICROBLOCKS_DISABLE_COST_CHECK";
pub const FAULT_DISABLE_MICROBLOCKS_BYTES_CHECK: &str = "MICROBLOCKS_DISABLE_BYTES_CHECK";
pub fn check_fault_injection(fault_name: &str) -> bool {
use std::env;
// only activates if we're testing
if env::var("BITCOIND_TEST") != Ok("1".to_string()) {
return false;
}
env::var(fault_name) == Ok("1".to_string())
}
lazy_static! {
pub static ref STACKS_EPOCHS_MAINNET: [StacksEpoch; 9] = [
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_10.clone(),
network_epoch: PEER_VERSION_EPOCH_1_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_2_05_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: BITCOIN_MAINNET_STACKS_2_05_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_21_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_205.clone(),
network_epoch: PEER_VERSION_EPOCH_2_05
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: BITCOIN_MAINNET_STACKS_21_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_22_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_1
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: BITCOIN_MAINNET_STACKS_22_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_23_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_2
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch23,
start_height: BITCOIN_MAINNET_STACKS_23_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_24_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_3
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch24,
start_height: BITCOIN_MAINNET_STACKS_24_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_25_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_4
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch25,
start_height: BITCOIN_MAINNET_STACKS_25_BURN_HEIGHT,
end_height: BITCOIN_MAINNET_STACKS_30_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_5
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch30,
start_height: BITCOIN_MAINNET_STACKS_30_BURN_HEIGHT,
end_height: STACKS_EPOCH_MAX,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_3_0
},
];
}
lazy_static! {
pub static ref STACKS_EPOCHS_TESTNET: [StacksEpoch; 9] = [
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_10.clone(),
network_epoch: PEER_VERSION_EPOCH_1_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_2_05_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: BITCOIN_TESTNET_STACKS_2_05_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_21_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_205.clone(),
network_epoch: PEER_VERSION_EPOCH_2_05
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: BITCOIN_TESTNET_STACKS_21_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_22_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_1
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: BITCOIN_TESTNET_STACKS_22_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_23_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_2
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch23,
start_height: BITCOIN_TESTNET_STACKS_23_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_24_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_3
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch24,
start_height: BITCOIN_TESTNET_STACKS_24_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_4
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch25,
start_height: BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT,
end_height: BITCOIN_TESTNET_STACKS_30_BURN_HEIGHT,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_5
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch30,
start_height: BITCOIN_TESTNET_STACKS_30_BURN_HEIGHT,
end_height: STACKS_EPOCH_MAX,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_3_0
},
];
}
lazy_static! {
pub static ref STACKS_EPOCHS_REGTEST: [StacksEpoch; 9] = [
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: 0,
block_limit: BLOCK_LIMIT_MAINNET_10.clone(),
network_epoch: PEER_VERSION_EPOCH_1_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: 0,
end_height: 1000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_0
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: 1000,
end_height: 2000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_05
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 2000,
end_height: 3000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_1
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: 3000,
end_height: 4000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_2
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch23,
start_height: 4000,
end_height: 5000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_3
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch24,
start_height: 5000,
end_height: 6000,
block_limit: HELIUM_BLOCK_LIMIT_20.clone(),
network_epoch: PEER_VERSION_EPOCH_2_4
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch25,
start_height: 6000,
end_height: 7001,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_2_5
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch30,
start_height: 7001,
end_height: STACKS_EPOCH_MAX,
block_limit: BLOCK_LIMIT_MAINNET_21.clone(),
network_epoch: PEER_VERSION_EPOCH_3_0
},
];
}
/// Stacks 2.05 epoch marker. All block-commits in 2.05 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_05_MARKER: u8 = 0x05;
/// Stacks 2.1 epoch marker. All block-commits in 2.1 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_1_MARKER: u8 = 0x06;
/// Stacks 2.2 epoch marker. All block-commits in 2.2 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_2_MARKER: u8 = 0x07;
/// Stacks 2.3 epoch marker. All block-commits in 2.3 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_3_MARKER: u8 = 0x08;
/// Stacks 2.4 epoch marker. All block-commits in 2.4 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_4_MARKER: u8 = 0x09;
/// Stacks 2.5 epoch marker. All block-commits in 2.5 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_2_5_MARKER: u8 = 0x0a;
/// Stacks 3.0 epoch marker. All block-commits in 3.0 must have a memo bitfield with this value
/// *or greater*.
pub static STACKS_EPOCH_3_0_MARKER: u8 = 0x0b;
#[test]
fn test_ord_for_stacks_epoch() {
let epochs = STACKS_EPOCHS_MAINNET.clone();
assert_eq!(epochs[0].cmp(&epochs[1]), Ordering::Less);
assert_eq!(epochs[1].cmp(&epochs[2]), Ordering::Less);
assert_eq!(epochs[0].cmp(&epochs[2]), Ordering::Less);
assert_eq!(epochs[0].cmp(&epochs[0]), Ordering::Equal);
assert_eq!(epochs[1].cmp(&epochs[1]), Ordering::Equal);
assert_eq!(epochs[2].cmp(&epochs[2]), Ordering::Equal);
assert_eq!(epochs[3].cmp(&epochs[3]), Ordering::Equal);
assert_eq!(epochs[4].cmp(&epochs[4]), Ordering::Equal);
assert_eq!(epochs[2].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[2].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[1].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[3].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[3].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[3].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[4].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[4].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[4].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[4].cmp(&epochs[3]), Ordering::Greater);
assert_eq!(epochs[5].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[5].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[5].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[5].cmp(&epochs[3]), Ordering::Greater);
assert_eq!(epochs[5].cmp(&epochs[4]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[3]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[4]), Ordering::Greater);
assert_eq!(epochs[6].cmp(&epochs[5]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[3]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[4]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[5]), Ordering::Greater);
assert_eq!(epochs[7].cmp(&epochs[6]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[0]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[1]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[2]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[3]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[4]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[5]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[6]), Ordering::Greater);
assert_eq!(epochs[8].cmp(&epochs[7]), Ordering::Greater);
}
#[test]
fn test_ord_for_stacks_epoch_id() {
assert_eq!(
StacksEpochId::Epoch10.cmp(&StacksEpochId::Epoch20),
Ordering::Less
);
assert_eq!(
StacksEpochId::Epoch20.cmp(&StacksEpochId::Epoch2_05),
Ordering::Less
);
assert_eq!(
StacksEpochId::Epoch10.cmp(&StacksEpochId::Epoch2_05),
Ordering::Less
);
assert_eq!(
StacksEpochId::Epoch10.cmp(&StacksEpochId::Epoch10),
Ordering::Equal
);
assert_eq!(
StacksEpochId::Epoch20.cmp(&StacksEpochId::Epoch20),
Ordering::Equal
);
assert_eq!(
StacksEpochId::Epoch2_05.cmp(&StacksEpochId::Epoch2_05),
Ordering::Equal
);
assert_eq!(
StacksEpochId::Epoch2_05.cmp(&StacksEpochId::Epoch20),
Ordering::Greater
);
assert_eq!(
StacksEpochId::Epoch2_05.cmp(&StacksEpochId::Epoch10),
Ordering::Greater
);
assert_eq!(
StacksEpochId::Epoch20.cmp(&StacksEpochId::Epoch10),
Ordering::Greater
);
}
pub trait StacksEpochExtension {
#[cfg(test)]
fn unit_test(stacks_epoch_id: StacksEpochId, epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_05(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_05_only(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_pre_2_05(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_1(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_2(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_3(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_4(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_5(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_3_0(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_2_1_only(epoch_2_0_block_height: u64) -> Vec<StacksEpoch>;
#[cfg(test)]
fn unit_test_3_0_only(first_burnchain_height: u64) -> Vec<StacksEpoch>;
fn all(
epoch_2_0_block_height: u64,
epoch_2_05_block_height: u64,
epoch_2_1_block_height: u64,
) -> Vec<StacksEpoch>;
fn validate_epochs(epochs: &[StacksEpoch]) -> Vec<StacksEpoch>;
/// This method gets the epoch vector.
///
/// Choose according to:
/// 1) Use the custom epochs defined on the underlying `BitcoinIndexerConfig`, if they exist.
/// 2) Use hard-coded static values, otherwise.
///
/// It is an error (panic) to set custom epochs if running on `Mainnet`.
///
fn get_epochs(
bitcoin_network: BitcoinNetworkType,
configured_epochs: Option<&Vec<StacksEpoch>>,
) -> Vec<StacksEpoch>;
}
impl StacksEpochExtension for StacksEpoch {
fn get_epochs(
bitcoin_network: BitcoinNetworkType,
configured_epochs: Option<&Vec<StacksEpoch>>,
) -> Vec<StacksEpoch> {
match configured_epochs {
Some(epochs) => {
assert!(bitcoin_network != BitcoinNetworkType::Mainnet);
epochs.clone()
}
None => get_bitcoin_stacks_epochs(bitcoin_network),
}
}
#[cfg(test)]
fn unit_test_pre_2_05(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
]
}
#[cfg(test)]
fn unit_test_2_05(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: first_burnchain_height + 4,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height + 4,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
]
}
#[cfg(test)]
fn unit_test_2_05_only(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: 0,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
]
}
#[cfg(test)]
fn unit_test_2_1(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: first_burnchain_height + 4,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height + 4,
end_height: first_burnchain_height + 8,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: first_burnchain_height + 8,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_1,
},
]
}
#[cfg(test)]
fn unit_test_2_2(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: first_burnchain_height + 4,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height + 4,
end_height: first_burnchain_height + 8,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: first_burnchain_height + 8,
end_height: first_burnchain_height + 12,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_1,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: first_burnchain_height + 12,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_2,
},
]
}
#[cfg(test)]
fn unit_test_2_3(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test_2_3 first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: first_burnchain_height + 4,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height + 4,
end_height: first_burnchain_height + 8,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: first_burnchain_height + 8,
end_height: first_burnchain_height + 12,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_1,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: first_burnchain_height + 12,
end_height: first_burnchain_height + 16,
block_limit: ExecutionCost {
write_length: 220220,
write_count: 220220,
read_length: 220220,
read_count: 220220,
runtime: 220220,
},
network_epoch: PEER_VERSION_EPOCH_2_2,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch23,
start_height: first_burnchain_height + 16,
end_height: STACKS_EPOCH_MAX,
block_limit: ExecutionCost {
write_length: 230230,
write_count: 230230,
read_length: 230230,
read_count: 230230,
runtime: 230230,
},
network_epoch: PEER_VERSION_EPOCH_2_3,
},
]
}
#[cfg(test)]
fn unit_test_2_4(first_burnchain_height: u64) -> Vec<StacksEpoch> {
info!(
"StacksEpoch unit_test_2_4 first_burn_height = {}",
first_burnchain_height
);
vec![
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: first_burnchain_height,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_1_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: first_burnchain_height + 4,
block_limit: ExecutionCost::max_value(),
network_epoch: PEER_VERSION_EPOCH_2_0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch2_05,
start_height: first_burnchain_height + 4,
end_height: first_burnchain_height + 8,
block_limit: ExecutionCost {
write_length: 205205,
write_count: 205205,
read_length: 205205,
read_count: 205205,
runtime: 205205,
},
network_epoch: PEER_VERSION_EPOCH_2_05,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: first_burnchain_height + 8,
end_height: first_burnchain_height + 12,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_1,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch22,
start_height: first_burnchain_height + 12,
end_height: first_burnchain_height + 16,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,
read_length: 210210,
read_count: 210210,
runtime: 210210,
},
network_epoch: PEER_VERSION_EPOCH_2_2,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch23,
start_height: first_burnchain_height + 16,
end_height: first_burnchain_height + 20,
block_limit: ExecutionCost {
write_length: 210210,
write_count: 210210,