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
//! Collection of all runtime features.
//!
//! Steps to add a new feature are outlined below. Note that these steps only cover
//! the process of getting a feature into the core Safecoin code.
//! - For features that are unambiguously good (ie bug fixes), these steps are sufficient.
//! - For features that should go up for community vote (ie fee structure changes), more
//!   information on the additional steps to follow can be found at:
//!   <https://spl.solana.com/feature-proposal#feature-proposal-life-cycle>
//!
//! 1. Generate a new keypair with `safecoin-keygen new --outfile feature.json --no-passphrase`
//!    - Keypairs should be held by core contributors only. If you're a non-core contributor going
//!      through these steps, the PR process will facilitate a keypair holder being picked. That
//!      person will generate the keypair, provide pubkey for PR, and ultimately enable the feature.
//! 2. Add a public module for the feature, specifying keypair pubkey as the id with
//!    `solana_sdk::declare_id!()` within the module.
//!    Additionally, add an entry to `FEATURE_NAMES` map.
//! 3. Add desired logic to check for and switch on feature availability.
//!
//! For more information on how features are picked up, see comments for `Feature`.

use {
    lazy_static::lazy_static,
    solana_sdk::{
        clock::Slot,
        hash::{Hash, Hasher},
        pubkey::Pubkey,
    },
    std::collections::{HashMap, HashSet},
};

pub mod deprecate_rewards_sysvar {
    solana_sdk::declare_id!("GVriKcZATdgSzmhmu9PtimfheaKYksK5mhgoN5fbRhXg");
}

pub mod pico_inflation {
    solana_sdk::declare_id!("HC5H1tGb2RBRbrECSKmBVjwTsEEJziTTRsm3XSdTefrJ");
}

pub mod full_inflation {
    pub mod devnet_and_testnet {
        solana_sdk::declare_id!("JC1GQujpgHz92Am65FxcxByqqDGTdYJs6jLjgebnDpJF");
    }

    pub mod mainnet {
        pub mod certusone {
            pub mod vote {
                solana_sdk::declare_id!("7Ra6gKzEBFyYJ7fdsrCuzihZcxKu7AbmDy2FBEQFzap2");
            }
            pub mod enable {
                solana_sdk::declare_id!("54ZqXvMyCKShnBrGj2ni6m4kXTjRUrkc21dFoT9npJZk");
            }
        }
    }
}

pub mod secp256k1_program_enabled {
    solana_sdk::declare_id!("3tF9nXQrHzTV5jdDqzn6LVWMoJagN1zRgr4APfY6qmpi");
}

pub mod safe_token_v2_multisig_fix {
    solana_sdk::declare_id!("EwSWSBRpzYZSEqdZ215WMmnce6WiEsk57rSEB3e7ghh6");
}

pub mod no_overflow_rent_distribution {
    solana_sdk::declare_id!("9TyDRDhs933rTCWGwzSUTSx1XeJT14sc17o1cNQzUaBq");
}

pub mod filter_stake_delegation_accounts {
    solana_sdk::declare_id!("HpGqShCRhP7QwMBXTs1KbATiHWa383EUWjg3kbQjN2Kf");
}

pub mod require_custodian_for_locked_stake_authorize {
    solana_sdk::declare_id!("FKWSvfcXATHSBBNvr5VE6ns4tNsTG3EGzcDw2xVtowZQ");
}

pub mod safe_token_v2_self_transfer_fix {
    solana_sdk::declare_id!("2XDc17ZmSTbpqV3B5fmEGac4CKCYnbJj7vnfASvdzqyN");
}

pub mod warp_timestamp_again {
    solana_sdk::declare_id!("EgfbGcUzJotpXW8H4TnhVwDbrjm75xecKnrSAfqv4YvW");
}

pub mod check_init_vote_data {
    solana_sdk::declare_id!("CfH5RJxvjkQ1LaBSrnCDnYvHZtL6FuTQ751myi6DJEb5");
}

pub mod secp256k1_recover_syscall_enabled {
    solana_sdk::declare_id!("Bk9KRo8RKyBuE4W9uWD6jijdP7nLMbi2h26wc9aZnsab");
}

pub mod system_transfer_zero_check {
    solana_sdk::declare_id!("ACrERgP7eXsQquYUNQwASR884izTTXnR2jDnxjWRPEde");
}

pub mod blake3_syscall_enabled {
    solana_sdk::declare_id!("EJjfy9f9NY7qyBWv5vkSFTNGEdrGPKoLZEUG5ktcHuTk");
}

pub mod dedupe_config_program_signers {
    solana_sdk::declare_id!("Ffpg1Q73ocztQKMTbkTMeTAVpcGUb95u2aUaCeFQ47NY");
}

pub mod verify_tx_signatures_len {
    solana_sdk::declare_id!("H9EqD4wZCFzqo3P5jbNrAQ8nhNq3xfaA3NLh9Z7sLXwY");
}

pub mod vote_stake_checked_instructions {
    solana_sdk::declare_id!("BjfQ729TvPN84xsvsGMUsRLAqGc1ttSCQ6C5Zd3rUg2N");
}

pub mod rent_for_sysvars {
    solana_sdk::declare_id!("8bwDv5gkxZap8PyNAahSSGvfdcoFmpyustP6U7ysHiKP");
}

pub mod libsecp256k1_0_5_upgrade_enabled {
    solana_sdk::declare_id!("EVHL8iX15Gf6PpjdMd7pqPivjPQ2LLbK9fkGsrsGWy9r");
}

pub mod tx_wide_compute_cap {
    solana_sdk::declare_id!("J3WyHmj9HcTEzMAGPKZLBVir6b5VniMBnNZk8puvxDxL");
}

pub mod safe_token_v2_set_authority_fix {
    solana_sdk::declare_id!("Cb3jN13cfCNDV9dp36djNpcZXF7r82UAE4U1tZjXnFx5");
}

pub mod merge_nonce_error_into_system_error {
    solana_sdk::declare_id!("4n5Ko6ax8yLi21CXoBMFbCy52QydH7jpy42W5df7GZqT");
}

pub mod disable_fees_sysvar {
    solana_sdk::declare_id!("CcxsWdzHQ3wyNpLQ7E8konzi5cGz6UqXfeRTDTkGrCLt");
}

pub mod stake_merge_with_unmatched_credits_observed {
    solana_sdk::declare_id!("BrbirQE6i85NmJ3eB6jRLJbuYMT26HhSeHFYdxrfbUkk");
}

pub mod zk_token_sdk_enabled {
    solana_sdk::declare_id!("LtC5sq6KbLrLiyYceekkCYKbqHYjXt2RMjeWVYqh9za");
}

pub mod curve25519_syscall_enabled {
    solana_sdk::declare_id!("AbUw25egriAS7t3uHCtdJFjuzXRJdsihEMSLCmEfSWum");
}

pub mod versioned_tx_message_enabled {
    solana_sdk::declare_id!("AtsKod95wFiFsmFvwN1xsXWTurv4CgrCoKyZYQqRkVdW");
}

pub mod libsecp256k1_fail_on_bad_count {
    solana_sdk::declare_id!("ELGoo15JsBsoS649X4HDyqpisjsk9Z3xMQHA2tc5fsVh");
}

pub mod libsecp256k1_fail_on_bad_count2 {
    solana_sdk::declare_id!("57hm6ERNDfJLmgXj2jM9qsxUzNSDK3MtTrbTdDrN6wd8");
}

pub mod instructions_sysvar_owned_by_sysvar {
    solana_sdk::declare_id!("Cw3DVuS5cftJsULpNoexEES6voZx268FdZWdnYJ7AQr8");
}

pub mod stake_program_advance_activating_credits_observed {
    solana_sdk::declare_id!("8SgjbhRrT9Lu5gX8zyWtbeMynSMLfKs1VkDoVVbojSDp");
}

pub mod credits_auto_rewind {
    solana_sdk::declare_id!("BUS12ciZ5gCoFafUHWW8qaFMMtwFQGVxjsDheWLdqBE2");
}

pub mod demote_program_write_locks {
    solana_sdk::declare_id!("4mKMV9GnGmbgncfkSQJid9Kcnu1sYL5kJSWmHLGNNW2W");
}

pub mod ed25519_program_enabled {
    solana_sdk::declare_id!("BUiQnBRcQXphWNg9izLmu4Q7yvPCrETjbBAqPbJRbigo");
}

pub mod return_data_syscall_enabled {
    solana_sdk::declare_id!("JBReCcnWddZuLuQP2uHtirrqBTgbXq13nf27pFZn4yAG");
}

pub mod reduce_required_deploy_balance {
    solana_sdk::declare_id!("CChcJjMA6MbJnEa3JN5vSuuitmiZCrpiJCuYpwLNc6xJ");
}

pub mod sol_log_data_syscall_enabled {
    solana_sdk::declare_id!("FfA1fo35R7A1hAdTySiBYWP53vmtmNjoY93hk3BFij8q");
}

pub mod stakes_remove_delegation_if_inactive {
    solana_sdk::declare_id!("7cRMwESG7sdDrPBKWUWJZnUzPB1FRXj2YDCFRepjpcvX");
}

pub mod do_support_realloc {
    solana_sdk::declare_id!("7X2unCk3oLEhsrgkXKkRcfHcFiv2B361bMSoSXG7VogL");
}

// Note: when this feature is cleaned up, also remove the secp256k1 program from
// the list of builtins and remove its files from /programs
pub mod prevent_calling_precompiles_as_programs {
    solana_sdk::declare_id!("1tqRX4kb9mxhLJFeUG7a9AZ3ZSt9ycCTyNmvYPcprdJ");
}

pub mod optimize_epoch_boundary_updates {
    solana_sdk::declare_id!("9aRcTW6CA2gm66oFyRqp9bV6qF5VYHiuSxdxTGm78rEi");
}

pub mod remove_native_loader {
    solana_sdk::declare_id!("ATWHHk7mdfaatNZTuKPUMvcBc9iKZStmph9ASzaWoSSj");
}

pub mod send_to_tpu_vote_port {
    solana_sdk::declare_id!("JAB9JKLm1zmdv9ntxnbTUxgGK9p2WdmDjzwf5ptMZQ4L");
}

pub mod requestable_heap_size {
    solana_sdk::declare_id!("2m2vf4z2t6DV7GuwUxiyUCuvUv4kf8n6ZsYWRXZPu7Cb");
}

pub mod disable_fee_calculator {
    solana_sdk::declare_id!("5fWcNUDYBNyX6ntr9c9JGqSMntZfwXMJxvMhD9TDh4Yo");
}

pub mod add_compute_budget_program {
    solana_sdk::declare_id!("HTTwDioiNtkTJf24JqUN8KNZYDevmVG3uH4sRQbT4Bch");
}

pub mod nonce_must_be_writable {
    solana_sdk::declare_id!("GwDyeFyJHbnVqXRPPty3vT6bk7YJyEvKiVSiJVzL3SiF");
}

pub mod safe_token_v3_3_0_release {
    solana_sdk::declare_id!("9steApkUSZKDra4d6GBqvjtLLovtqqquqxRj6HAySanV");
}

pub mod leave_nonce_on_success {
    solana_sdk::declare_id!("7ckuburuhbvpBc8tN9RoYR6uETFrC9Bf9rpffWvfH5Kj");
}

pub mod reject_empty_instruction_without_program {
    solana_sdk::declare_id!("CDSGXXUAYKsBjzByscc6QmiKghH68EBymxvreC2CEKHV");
}

pub mod fixed_memcpy_nonoverlapping_check {
    solana_sdk::declare_id!("AcdZ7SdrHcQvAABPKtENAqMChCZvRPVzqJD9TiKBsyWb");
}

pub mod reject_non_rent_exempt_vote_withdraws {
    solana_sdk::declare_id!("GxV3gunVo45B7U9PXFguaQcH5UhXuAvgoatzSDT5L6aM");
}

pub mod evict_invalid_stakes_cache_entries {
    solana_sdk::declare_id!("DuTNokfa22zREonYdWbZPoEwqjmKzPixetUyT4ffW3f2");
}

pub mod allow_votes_to_directly_update_vote_state {
    solana_sdk::declare_id!("Ff8b1fBeB86q8cjq47ZhsQLgv5EkHu3G1C99zjUfAzrq");
}

pub mod cap_accounts_data_len {
    solana_sdk::declare_id!("8ChajqNo7MSfq7G31GP6tw1bkEZEu7FAz5aG4mvhXKEX");
}

pub mod max_tx_account_locks {
    solana_sdk::declare_id!("ANaFEkPDA4bPGcXhBodHMX9yZ83kxUZhgdUqPhiev84N");
}

pub mod require_rent_exempt_accounts {
    solana_sdk::declare_id!("9RGjVttxDUgh6H82kTZiRNLawVgQmKaLhdhvWSXUhbv");
}

pub mod filter_votes_outside_slot_hashes {
    solana_sdk::declare_id!("FZZFGwVXMN6r94Ugcrvpd1tukiSFygdcM9FwcrsaTVY2");
}

pub mod update_syscall_base_costs {
    solana_sdk::declare_id!("4YytQkV3PmnLHYDVnPAajtxCVAT64CPYWwYMHCXGsMw6");
}

pub mod stake_deactivate_delinquent_instruction {
    solana_sdk::declare_id!("437r62HoAdUb63amq3D7ENnBLDhHT2xY8eFkLJYVKK4x");
}

pub mod stake_redelegate_instruction {
    solana_sdk::declare_id!("3EPmAX94PvVJCjMeFfRFvj4avqCPL8vv3TGsZQg7ydMx");
}

pub mod vote_withdraw_authority_may_change_authorized_voter {
    solana_sdk::declare_id!("2BYtq3z2Ywz2bP2UR8RwP6yepGyexGQY6eJyesptZgn2");
}

pub mod safe_associated_token_account_v1_0_4 {
    solana_sdk::declare_id!("4sFvovX9vpPjdonPZPs2rLj3g2urvtwMvmw1RqxrdNjk");
}

pub mod reject_vote_account_close_unless_zero_credit_epoch {
    solana_sdk::declare_id!("8EEoVj3mSZs6mJ89hVFTNW6ZKoFWYfAWNneSP4F53NfP");
}

pub mod add_get_processed_sibling_instruction_syscall {
    solana_sdk::declare_id!("CNGf1dMHeDnvrSAAc3CxrFeseEhdouFuFhxhcbaqAeuc");
}

pub mod bank_tranaction_count_fix {
    solana_sdk::declare_id!("6dj2gJhSm1XHUbpRKVNjngEMfJia4YydaqUurF16P7qE");
}

pub mod disable_bpf_deprecated_load_instructions {
    solana_sdk::declare_id!("2fbhBGLzd9rM6MhVPGf7y3Z4GCsUSpep3sasbMi7LzsM");
}

pub mod disable_bpf_unresolved_symbols_at_runtime {
    solana_sdk::declare_id!("HSx7BtUEsXXeimVnF1EcziqahCgxL9oBf9tb3PsSjmab");
}

pub mod record_instruction_in_transaction_context_push {
    solana_sdk::declare_id!("Fc7KWisNu1RwAsRwrdvEQpcwvBw8EFgX8tXurT16L96J");
}

pub mod syscall_saturated_math {
    solana_sdk::declare_id!("CPuuztV5gCNKSdDTnfGKgDTo9cNZVPYsVbZUv1UhmR7h");
}

pub mod check_physical_overlapping {
    solana_sdk::declare_id!("EVhbxh9zEjkfHEx4kjkx9TvadV6F6WkaaxUKdTxwdiV3");
}

pub mod limit_secp256k1_recovery_id {
    solana_sdk::declare_id!("Acois5V3T9jv2hdFJXuVeKQzcHonJWACG5cewknQredH");
}

pub mod disable_deprecated_loader {
    solana_sdk::declare_id!("GTUMCZ8LTNxVfxdrw7ZsDFTxXb7TutYkzJnFwinpE6dg");
}

pub mod check_slice_translation_size {
    solana_sdk::declare_id!("GmC19j9qLn2RFk5NduX6QXaDhVpGncVVBzyM8e9WMz2F");
}

pub mod stake_split_uses_rent_sysvar {
    solana_sdk::declare_id!("FQnc7U4koHqWgRvFaBJjZnV8VPg6L6wWK33yJeDp4yvV");
}

pub mod add_get_minimum_delegation_instruction_to_stake_program {
    solana_sdk::declare_id!("St8k9dVXP97xT6faW24YmRSYConLbhsMJA4TJTBLmMT");
}

pub mod error_on_syscall_bpf_function_hash_collisions {
    solana_sdk::declare_id!("8199Q2gMD2kwgfopK5qqVWuDbegLgpuFUFHCcUJQDN8b");
}

pub mod reject_callx_r10 {
    solana_sdk::declare_id!("3NKRSwpySNwD3TvP5pHnRmkAQRsdkXWRr1WaQh8p4PWX");
}

pub mod drop_redundant_turbine_path {
    solana_sdk::declare_id!("FAbr5JVAvaF2DtqZzxPHoPBn6dEP4gKTW5tS1GNYfQYw");
}

pub mod executables_incur_cpi_data_cost {
    solana_sdk::declare_id!("CL54RJ5iQE5Jk7VJaNegv98TY7tvLqivensTEUsEnhsS");
}

pub mod fix_recent_blockhashes {
    solana_sdk::declare_id!("6iyggb5MTcsvdcugX7bEKbHV8c6jdLbpHwkncrgLMhfo");
}

pub mod update_rewards_from_cached_accounts {
    solana_sdk::declare_id!("28s7i3htzhahXQKqmS2ExzbEoUypg9krwvtK2M9UWXh9");
}

pub mod safe_token_v3_4_0 {
    solana_sdk::declare_id!("GqQz6K1Rj99MbzLL8iVee9sSZH6b8XRd6N5r4gAn3Sff");
}

pub mod safe_associated_token_account_v1_1_0 {
    solana_sdk::declare_id!("3dbt1wqFxD9uSLoZ1bRfkaETTbvVUWqDPGmgFXixitCE");
}

pub mod default_units_per_instruction {
    solana_sdk::declare_id!("HgX6iprND6esDrPTuiSSbNmDuAbKSAwFifjjSYKuwwkK");
}

pub mod stake_allow_zero_undelegated_amount {
    solana_sdk::declare_id!("sTKz343FM8mqtyGvYWvbLpTThw3ixRM4Xk8QvZ985mw");
}

pub mod require_static_program_ids_in_transaction {
    solana_sdk::declare_id!("8FdwgyHFEjhAdjWfV2vfqk7wA1g9X3fQpKH7SBpEv3kC");
}

pub mod stake_raise_minimum_delegation_to_1_sol {
    // This is a feature-proposal *feature id*.  The feature keypair address is `3YHAo6wWw5rDbQxb59BmJkQ3XwVhX3m8tdBVbtxnJmma`.
    solana_sdk::declare_id!("4xmyBuR2VCXzy9H6qYpH9ckfgnTuMDQFPFBfTs4eBCY1");
}

pub mod stake_minimum_delegation_for_rewards {
    solana_sdk::declare_id!("ELjxSXwNsyXGfAh8TqX8ih22xeT8huF6UngQirbLKYKH");
}

pub mod add_set_compute_unit_price_ix {
    solana_sdk::declare_id!("G4o7bAuRYtxChqR3bD2XhEqh9HE7TDJHdaxiQyegy3TY");
}

pub mod disable_deploy_of_alloc_free_syscall {
    solana_sdk::declare_id!("79HWsX9rpnnJBPcdNURVqygpMAfxdrAirzAGAVmf92im");
}

pub mod include_account_index_in_rent_error {
    solana_sdk::declare_id!("FrYss5jrBWh6S2NTAmurKd2LEn9Bm4h9idwqvBZ3tTng");
}

pub mod add_shred_type_to_shred_seed {
    solana_sdk::declare_id!("CeNiDsNf3t6fGegpcFb1WiyQiCwkfAEYrGVd8kKkLZoe");
}

pub mod warp_timestamp_with_a_vengeance {
    solana_sdk::declare_id!("FxQ1YgnmZfQw4ggDz9vThyTed8ZTukGKugndChYLHHuV");
}

pub mod separate_nonce_from_blockhash {
    solana_sdk::declare_id!("D7Z7kpxHoMog9cbx1WHiaRsUsneoVwWKCqS95BPLZu1P");
}

pub mod enable_durable_nonce {
    solana_sdk::declare_id!("2eWUxhwU8ZHRFrUz86CEvqUvWhQc5v7A1uDtV9vN93Ad");
}

pub mod vote_state_update_credit_per_dequeue {
    solana_sdk::declare_id!("CveezY6FDLVBToHDcvJRmtMouqzsmj4UXYh5ths5G5Uv");
}

pub mod quick_bail_on_panic {
    solana_sdk::declare_id!("HLRgJbaGwAJbmL6Tsu8N9oGfLhsc7DopsvP4UPjzjyr3");
}

pub mod nonce_must_be_authorized {
    solana_sdk::declare_id!("B9oxgU37tuCohjc322GiLiaD8c1LsZtJ7RwMjHWKKpVB");
}

pub mod nonce_must_be_advanceable {
    solana_sdk::declare_id!("8qKM9RwaBzj6u8Ax9AHBBy6GEwNcrduY6UmDF7KPqt8G");
}

pub mod vote_authorize_with_seed {
    solana_sdk::declare_id!("HeRuYxnBuFFAM9fd5FmaGSeBdHP4SEm1dR18rXUVJkyi");
}

pub mod cap_accounts_data_size_per_block {
    solana_sdk::declare_id!("FZpH2SfxGhFjmEWyzt6VY17ebJ7S9tcZ1D3XSpxF6qfj");
}

pub mod preserve_rent_epoch_for_rent_exempt_accounts {
    solana_sdk::declare_id!("8bxNk6MJqCQLeMrL2viWTKiSftGeUoie6KpEQD8dVzAd");
}

pub mod enable_bpf_loader_extend_program_ix {
    solana_sdk::declare_id!("GPg3fNRkPPTYvtJTEefRPPjtCer2fucW66iS74HUeSM9");
}

pub mod enable_early_verification_of_account_modifications {
    solana_sdk::declare_id!("9LD4rrdYAqUWRb39cWVzYgA9MVsVQAerTTnmbSrjbVSn");
}

pub mod prevent_crediting_accounts_that_end_rent_paying {
    solana_sdk::declare_id!("2dtQ7jzJtQdAWZM8baLKLo9taHw2Hg7fMLb6wvBL3LhG");
}

pub mod cap_bpf_program_instruction_accounts {
    solana_sdk::declare_id!("ZMe3G91j5MYBRdxMELJPa5WKyGF35geL1CAf2ge55Y8");
}

pub mod loosen_cpi_size_restriction {
    solana_sdk::declare_id!("6bHAHY3xkTEGzzqu4dweMYqhiAXVAC2dUj2QDgXoe7uP");
}

pub mod use_default_units_in_fee_calculation {
    solana_sdk::declare_id!("5tYtSxXTy9SWv7RoHPa5FSFTVuuqdvS5qv22nkpAaYDS");
}

pub mod compact_vote_state_updates {
    solana_sdk::declare_id!("3Av7XvYZmZ6RBhQeM4Wt54aKN3iJtW2HsErG7wxwPwqE");
}

pub mod concurrent_replay_of_forks {
    solana_sdk::declare_id!("8v9fX8s1QR8fbH6T5AyPHBp67SMZNSvcBkMbJzeoktK4");
}

pub mod incremental_snapshot_only_incremental_hash_calculation {
    solana_sdk::declare_id!("EM2qfX7PqW1JhGFThHUeVQ8GFaHBGFmae7G7oP1Jbwbk");
}

pub mod vote_state_update_root_fix {
    solana_sdk::declare_id!("F9hCEfctdkoka5Mcjkq2YvusjZymxRfADYf4Vo7tbRmC");
}

pub mod return_none_for_zero_lamport_accounts {
    solana_sdk::declare_id!("4uFe1EAUqBRUfXHhHuGc9oAG42yymQMY1WQKuV4iLEpa");
}

pub mod disable_rehash_for_rent_epoch {
    solana_sdk::declare_id!("J1fn5rAjqRuSi3fx9iHZbvux1cSdTNDDAzatTvbtXEcF");
}

pub mod on_load_preserve_rent_epoch_for_rent_exempt_accounts {
    solana_sdk::declare_id!("CwAfu54G3uayqUt3YUhbGBZhBxf6nY3NRGZtinXCsBV");
}

pub mod increase_tx_account_lock_limit {
    solana_sdk::declare_id!("59ub3TYn7sigxPDqbLcNLE579DJZrW3DgPerQ9dkpQMX");
}

pub mod check_syscall_outputs_do_not_overlap {
    solana_sdk::declare_id!("6GLqd1nKHsQzabMdUaz3ppfyrVq3Dc3dcWFNZUEc9gKe");
}

pub mod commission_updates_only_allowed_in_first_half_of_epoch {
    solana_sdk::declare_id!("HbQhEfjaT3JW6HAftt9DnZPeJSgPVFJcVqAo4YyLXS6P");
}

pub mod enable_turbine_fanout_experiments {
    solana_sdk::declare_id!("GHPrWcXHqfHvHX4RCZ4oTEnEEQHcf4QJxqsFvm3MaWC4");
}

pub mod disable_turbine_fanout_experiments {
    solana_sdk::declare_id!("93NxcLB9SR2dMLRBNqkw7S3koiSQm6LmFYgJAnbXPC3a");
}

pub mod drop_merkle_shreds {
    solana_sdk::declare_id!("ExaQpo9PVJigohcXpEFzeVaYi3bPATpHx9J9wbEqRCex");
}

pub mod keep_merkle_shreds {
    solana_sdk::declare_id!("7pD9setQSbrYSKJTh23qTRFnZLpMuGp9zNwQ6C3oRHKe");
}

pub mod move_serialized_len_ptr_in_cpi {
    solana_sdk::declare_id!("B5FXDmNzjpZqcp5jvJtWfgBA14c5KYRLT959gdh8uR1Z");
}

pub mod enable_request_heap_frame_ix {
    solana_sdk::declare_id!("5i8xgKX9kiD3tgkSwpvJWKa3dmtrLBNbuEXDS93JQy22");
}

lazy_static! {
    /// Map of feature identifiers to user-visible description
    pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
        (secp256k1_program_enabled::id(), "secp256k1 program"),
        (deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
        (pico_inflation::id(), "pico inflation"),
        (full_inflation::devnet_and_testnet::id(), "full inflation on devnet and testnet"),
        (safe_token_v2_multisig_fix::id(), "safe-token multisig fix"),
        (no_overflow_rent_distribution::id(), "no overflow rent distribution"),
        (filter_stake_delegation_accounts::id(), "filter stake_delegation_accounts #14062"),
        (require_custodian_for_locked_stake_authorize::id(), "require custodian to authorize withdrawer change for locked stake"),
        (safe_token_v2_self_transfer_fix::id(), "safe-token self-transfer fix"),
        (full_inflation::mainnet::certusone::enable::id(), "full inflation enabled by Certus One"),
        (full_inflation::mainnet::certusone::vote::id(), "community vote allowing Certus One to enable full inflation"),
        (warp_timestamp_again::id(), "warp timestamp again, adjust bounding to 25% fast 80% slow #15204"),
        (check_init_vote_data::id(), "check initialized Vote data"),
        (secp256k1_recover_syscall_enabled::id(), "secp256k1_recover syscall"),
        (system_transfer_zero_check::id(), "perform all checks for transfers of 0 lamports"),
        (blake3_syscall_enabled::id(), "blake3 syscall"),
        (dedupe_config_program_signers::id(), "dedupe config program signers"),
        (verify_tx_signatures_len::id(), "prohibit extra transaction signatures"),
        (vote_stake_checked_instructions::id(), "vote/state program checked instructions #18345"),
        (rent_for_sysvars::id(), "collect rent from accounts owned by sysvars"),
        (libsecp256k1_0_5_upgrade_enabled::id(), "upgrade libsecp256k1 to v0.5.0"),
        (tx_wide_compute_cap::id(), "transaction wide compute cap"),
        (safe_token_v2_set_authority_fix::id(), "safe-token set_authority fix"),
        (merge_nonce_error_into_system_error::id(), "merge NonceError into SystemError"),
        (disable_fees_sysvar::id(), "disable fees sysvar"),
        (stake_merge_with_unmatched_credits_observed::id(), "allow merging active stakes with unmatched credits_observed #18985"),
        (zk_token_sdk_enabled::id(), "enable Zk Token proof program and syscalls"),
        (curve25519_syscall_enabled::id(), "enable curve25519 syscalls"),
        (versioned_tx_message_enabled::id(), "enable versioned transaction message processing"),
        (libsecp256k1_fail_on_bad_count::id(), "fail libsec256k1_verify if count appears wrong"),
        (libsecp256k1_fail_on_bad_count2::id(), "fail libsec256k1_verify if count appears wrong"),
        (instructions_sysvar_owned_by_sysvar::id(), "fix owner for instructions sysvar"),
        (stake_program_advance_activating_credits_observed::id(), "Enable advancing credits observed for activation epoch #19309"),
        (credits_auto_rewind::id(), "Auto rewind stake's credits_observed if (accidental) vote recreation is detected #22546"),
        (demote_program_write_locks::id(), "demote program write locks to readonly, except when upgradeable loader present #19593 #20265"),
        (ed25519_program_enabled::id(), "enable builtin ed25519 signature verify program"),
        (return_data_syscall_enabled::id(), "enable sol_{set,get}_return_data syscall"),
        (reduce_required_deploy_balance::id(), "reduce required payer balance for program deploys"),
        (sol_log_data_syscall_enabled::id(), "enable sol_log_data syscall"),
        (stakes_remove_delegation_if_inactive::id(), "remove delegations from stakes cache when inactive"),
        (do_support_realloc::id(), "support account data reallocation"),
        (prevent_calling_precompiles_as_programs::id(), "prevent calling precompiles as programs"),
        (optimize_epoch_boundary_updates::id(), "optimize epoch boundary updates"),
        (remove_native_loader::id(), "remove support for the native loader"),
        (send_to_tpu_vote_port::id(), "send votes to the tpu vote port"),
        (requestable_heap_size::id(), "Requestable heap frame size"),
        (disable_fee_calculator::id(), "deprecate fee calculator"),
        (add_compute_budget_program::id(), "Add compute_budget_program"),
        (nonce_must_be_writable::id(), "nonce must be writable"),
        (safe_token_v3_3_0_release::id(), "safe-token v3.3.0 release"),
        (leave_nonce_on_success::id(), "leave nonce as is on success"),
        (reject_empty_instruction_without_program::id(), "fail instructions which have native_loader as program_id directly"),
        (fixed_memcpy_nonoverlapping_check::id(), "use correct check for nonoverlapping regions in memcpy syscall"),
        (reject_non_rent_exempt_vote_withdraws::id(), "fail vote withdraw instructions which leave the account non-rent-exempt"),
        (evict_invalid_stakes_cache_entries::id(), "evict invalid stakes cache entries on epoch boundaries"),
        (allow_votes_to_directly_update_vote_state::id(), "enable direct vote state update"),
        (cap_accounts_data_len::id(), "cap the accounts data len"),
        (max_tx_account_locks::id(), "enforce max number of locked accounts per transaction"),
        (require_rent_exempt_accounts::id(), "require all new transaction accounts with data to be rent-exempt"),
        (filter_votes_outside_slot_hashes::id(), "filter vote slots older than the slot hashes history"),
        (update_syscall_base_costs::id(), "update syscall base costs"),
        (stake_deactivate_delinquent_instruction::id(), "enable the deactivate delinquent stake instruction #23932"),
        (vote_withdraw_authority_may_change_authorized_voter::id(), "vote account withdraw authority may change the authorized voter #22521"),
        (safe_associated_token_account_v1_0_4::id(), "SPL Associated Token Account Program release version 1.0.4, tied to token 3.3.0 #22648"),
        (reject_vote_account_close_unless_zero_credit_epoch::id(), "fail vote account withdraw to 0 unless account earned 0 credits in last completed epoch"),
        (add_get_processed_sibling_instruction_syscall::id(), "add add_get_processed_sibling_instruction_syscall"),
        (bank_tranaction_count_fix::id(), "fixes Bank::transaction_count to include all committed transactions, not just successful ones"),
        (disable_bpf_deprecated_load_instructions::id(), "disable ldabs* and ldind* BPF instructions"),
        (disable_bpf_unresolved_symbols_at_runtime::id(), "disable reporting of unresolved BPF symbols at runtime"),
        (record_instruction_in_transaction_context_push::id(), "move the CPI stack overflow check to the end of push"),
        (syscall_saturated_math::id(), "syscalls use saturated math"),
        (check_physical_overlapping::id(), "check physical overlapping regions"),
        (limit_secp256k1_recovery_id::id(), "limit secp256k1 recovery id"),
        (disable_deprecated_loader::id(), "disable the deprecated BPF loader"),
        (check_slice_translation_size::id(), "check size when translating slices"),
        (stake_split_uses_rent_sysvar::id(), "stake split instruction uses rent sysvar"),
        (add_get_minimum_delegation_instruction_to_stake_program::id(), "add GetMinimumDelegation instruction to stake program"),
        (error_on_syscall_bpf_function_hash_collisions::id(), "error on bpf function hash collisions"),
        (reject_callx_r10::id(), "Reject bpf callx r10 instructions"),
        (drop_redundant_turbine_path::id(), "drop redundant turbine path"),
        (executables_incur_cpi_data_cost::id(), "Executables incur CPI data costs"),
        (fix_recent_blockhashes::id(), "stop adding hashes for skipped slots to recent blockhashes"),
        (update_rewards_from_cached_accounts::id(), "update rewards from cached accounts"),
        (safe_token_v3_4_0::id(), "SPL Token Program version 3.4.0 release #24740"),
        (safe_associated_token_account_v1_1_0::id(), "SPL Associated Token Account Program version 1.1.0 release #24741"),
        (default_units_per_instruction::id(), "Default max tx-wide compute units calculated per instruction"),
        (stake_allow_zero_undelegated_amount::id(), "Allow zero-lamport undelegated amount for initialized stakes #24670"),
        (require_static_program_ids_in_transaction::id(), "require static program ids in versioned transactions"),
        (stake_raise_minimum_delegation_to_1_sol::id(), "Raise minimum stake delegation to 1.0 SAFE #24357"),
        (stake_minimum_delegation_for_rewards::id(), "stakes must be at least the minimum delegation to earn rewards"),
        (add_set_compute_unit_price_ix::id(), "add compute budget ix for setting a compute unit price"),
        (disable_deploy_of_alloc_free_syscall::id(), "disable new deployments of deprecated sol_alloc_free_ syscall"),
        (include_account_index_in_rent_error::id(), "include account index in rent tx error #25190"),
        (add_shred_type_to_shred_seed::id(), "add shred-type to shred seed #25556"),
        (warp_timestamp_with_a_vengeance::id(), "warp timestamp again, adjust bounding to 150% slow #25666"),
        (separate_nonce_from_blockhash::id(), "separate durable nonce and blockhash domains #25744"),
        (enable_durable_nonce::id(), "enable durable nonce #25744"),
        (vote_state_update_credit_per_dequeue::id(), "Calculate vote credits for VoteStateUpdate per vote dequeue to match credit awards for Vote instruction"),
        (quick_bail_on_panic::id(), "quick bail on panic"),
        (nonce_must_be_authorized::id(), "nonce must be authorized"),
        (nonce_must_be_advanceable::id(), "durable nonces must be advanceable"),
        (vote_authorize_with_seed::id(), "An instruction you can use to change a vote accounts authority when the current authority is a derived key #25860"),
        (cap_accounts_data_size_per_block::id(), "cap the accounts data size per block #25517"),
        (stake_redelegate_instruction::id(), "enable the redelegate stake instruction #26294"),
        (preserve_rent_epoch_for_rent_exempt_accounts::id(), "preserve rent epoch for rent exempt accounts #26479"),
        (enable_bpf_loader_extend_program_ix::id(), "enable bpf upgradeable loader ExtendProgram instruction #25234"),
        (enable_early_verification_of_account_modifications::id(), "enable early verification of account modifications #25899"),
        (disable_rehash_for_rent_epoch::id(), "on accounts hash calculation, do not try to rehash accounts #28934"),
        (on_load_preserve_rent_epoch_for_rent_exempt_accounts::id(), "on bank load account, do not try to fix up rent_epoch #28541"),
        (prevent_crediting_accounts_that_end_rent_paying::id(), "prevent crediting rent paying accounts #26606"),
        (cap_bpf_program_instruction_accounts::id(), "enforce max number of accounts per bpf program instruction #26628"),
        (loosen_cpi_size_restriction::id(), "loosen cpi size restrictions #26641"),
        (use_default_units_in_fee_calculation::id(), "use default units per instruction in fee calculation #26785"),
        (compact_vote_state_updates::id(), "Compact vote state updates to lower block size"),
        (concurrent_replay_of_forks::id(), "Allow slots from different forks to be replayed concurrently #26465"),
        (incremental_snapshot_only_incremental_hash_calculation::id(), "only hash accounts in incremental snapshot during incremental snapshot creation #26799"),
        (vote_state_update_root_fix::id(), "fix root in vote state updates #27361"),
        (return_none_for_zero_lamport_accounts::id(), "return none for zero lamport accounts #27800"),
        (increase_tx_account_lock_limit::id(), "increase tx account lock limit to 128 #27241"),
        (check_syscall_outputs_do_not_overlap::id(), "check syscall outputs do_not overlap #28600"),
        (commission_updates_only_allowed_in_first_half_of_epoch::id(), "validator commission updates are only allowed in the first half of an epoch #29362"),
        (enable_turbine_fanout_experiments::id(), "enable turbine fanout experiments #29393"),
        (disable_turbine_fanout_experiments::id(), "disable turbine fanout experiments #29393"),
        (drop_merkle_shreds::id(), "drop merkle shreds #29711"),
        (keep_merkle_shreds::id(), "keep merkle shreds #29711"),
        (move_serialized_len_ptr_in_cpi::id(), "cpi ignore serialized_len_ptr #29592"),
        (enable_request_heap_frame_ix::id(), "Enable transaction to request heap frame using compute budget instruction #30076"),
        /*************** ADD NEW FEATURES HERE ***************/
    ]
    .iter()
    .cloned()
    .collect();

    /// Unique identifier of the current software's feature set
    pub static ref ID: Hash = {
        let mut hasher = Hasher::default();
        let mut feature_ids = FEATURE_NAMES.keys().collect::<Vec<_>>();
        feature_ids.sort();
        for feature in feature_ids {
            hasher.hash(feature.as_ref());
        }
        hasher.result()
    };
}

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct FullInflationFeaturePair {
    pub vote_id: Pubkey, // Feature that grants the candidate the ability to enable full inflation
    pub enable_id: Pubkey, // Feature to enable full inflation by the candidate
}

lazy_static! {
    /// Set of feature pairs that once enabled will trigger full inflation
    pub static ref FULL_INFLATION_FEATURE_PAIRS: HashSet<FullInflationFeaturePair> = [
        FullInflationFeaturePair {
            vote_id: full_inflation::mainnet::certusone::vote::id(),
            enable_id: full_inflation::mainnet::certusone::enable::id(),
        },
    ]
    .iter()
    .cloned()
    .collect();
}

/// `FeatureSet` holds the set of currently active/inactive runtime features
#[derive(AbiExample, Debug, Clone)]
pub struct FeatureSet {
    pub active: HashMap<Pubkey, Slot>,
    pub inactive: HashSet<Pubkey>,
}
impl Default for FeatureSet {
    fn default() -> Self {
        // All features disabled
        Self {
            active: HashMap::new(),
            inactive: FEATURE_NAMES.keys().cloned().collect(),
        }
    }
}
impl FeatureSet {
    pub fn is_active(&self, feature_id: &Pubkey) -> bool {
        self.active.contains_key(feature_id)
    }

    pub fn activated_slot(&self, feature_id: &Pubkey) -> Option<Slot> {
        self.active.get(feature_id).copied()
    }

    /// List of enabled features that trigger full inflation
    pub fn full_inflation_features_enabled(&self) -> HashSet<Pubkey> {
        let mut hash_set = FULL_INFLATION_FEATURE_PAIRS
            .iter()
            .filter_map(|pair| {
                if self.is_active(&pair.vote_id) && self.is_active(&pair.enable_id) {
                    Some(pair.enable_id)
                } else {
                    None
                }
            })
            .collect::<HashSet<_>>();

        if self.is_active(&full_inflation::devnet_and_testnet::id()) {
            hash_set.insert(full_inflation::devnet_and_testnet::id());
        }
        hash_set
    }

    /// All features enabled, useful for testing
    pub fn all_enabled() -> Self {
        Self {
            active: FEATURE_NAMES.keys().cloned().map(|key| (key, 0)).collect(),
            inactive: HashSet::new(),
        }
    }

    /// Activate a feature
    pub fn activate(&mut self, feature_id: &Pubkey, slot: u64) {
        self.inactive.remove(feature_id);
        self.active.insert(*feature_id, slot);
    }

    /// Deactivate a feature
    pub fn deactivate(&mut self, feature_id: &Pubkey) {
        self.active.remove(feature_id);
        self.inactive.insert(*feature_id);
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_full_inflation_features_enabled_devnet_and_testnet() {
        let mut feature_set = FeatureSet::default();
        assert!(feature_set.full_inflation_features_enabled().is_empty());
        feature_set
            .active
            .insert(full_inflation::devnet_and_testnet::id(), 42);
        assert_eq!(
            feature_set.full_inflation_features_enabled(),
            [full_inflation::devnet_and_testnet::id()]
                .iter()
                .cloned()
                .collect()
        );
    }

    #[test]
    fn test_full_inflation_features_enabled() {
        // Normal sequence: vote_id then enable_id
        let mut feature_set = FeatureSet::default();
        assert!(feature_set.full_inflation_features_enabled().is_empty());
        feature_set
            .active
            .insert(full_inflation::mainnet::certusone::vote::id(), 42);
        assert!(feature_set.full_inflation_features_enabled().is_empty());
        feature_set
            .active
            .insert(full_inflation::mainnet::certusone::enable::id(), 42);
        assert_eq!(
            feature_set.full_inflation_features_enabled(),
            [full_inflation::mainnet::certusone::enable::id()]
                .iter()
                .cloned()
                .collect()
        );

        // Backwards sequence: enable_id and then vote_id
        let mut feature_set = FeatureSet::default();
        assert!(feature_set.full_inflation_features_enabled().is_empty());
        feature_set
            .active
            .insert(full_inflation::mainnet::certusone::enable::id(), 42);
        assert!(feature_set.full_inflation_features_enabled().is_empty());
        feature_set
            .active
            .insert(full_inflation::mainnet::certusone::vote::id(), 42);
        assert_eq!(
            feature_set.full_inflation_features_enabled(),
            [full_inflation::mainnet::certusone::enable::id()]
                .iter()
                .cloned()
                .collect()
        );
    }

    #[test]
    fn test_feature_set_activate_deactivate() {
        let mut feature_set = FeatureSet::default();

        let feature = Pubkey::new_unique();
        assert!(!feature_set.is_active(&feature));
        feature_set.activate(&feature, 0);
        assert!(feature_set.is_active(&feature));
        feature_set.deactivate(&feature);
        assert!(!feature_set.is_active(&feature));
    }
}