@@ -7,13 +7,19 @@ use masp_primitives::ff::PrimeField;
7
7
use masp_primitives:: sapling:: Node ;
8
8
use masp_primitives:: transaction:: components:: I128Sum ;
9
9
use namada_core:: borsh:: BorshSerializeExt ;
10
+ use namada_core:: chain:: BlockHeight ;
10
11
use namada_core:: dec:: Dec ;
11
12
use namada_core:: hash:: Hash ;
12
13
use namada_core:: masp:: { Precision , encode_asset_type} ;
13
14
use namada_core:: storage:: Key ;
15
+ use namada_core:: time:: MIN_UTC ;
14
16
use namada_macros:: BorshDeserializer ;
15
17
use namada_migrations:: REGISTER_DESERIALIZERS ;
16
- use namada_parameters:: storage:: get_tx_allowlist_storage_key;
18
+ use namada_parameters:: EpochDuration ;
19
+ use namada_parameters:: storage:: {
20
+ get_epoch_duration_storage_key, get_epochs_per_year_key,
21
+ get_masp_epoch_multiplier_key, get_tx_allowlist_storage_key,
22
+ } ;
17
23
use namada_sdk:: address:: Address ;
18
24
use namada_sdk:: ibc:: trace:: ibc_token;
19
25
use namada_sdk:: masp_primitives:: asset_type:: AssetType ;
@@ -734,6 +740,63 @@ pub fn shielded_reward_parameters_migration(
734
740
}
735
741
}
736
742
743
+ /// Demonstrate accelerating epochs
744
+ pub fn accelerate_epoch_migration ( updates : & mut Vec < migrations:: DbUpdateType > ) {
745
+ // Set the number of epochs per year to the specified constant
746
+ const EPOCHS_PER_YEAR : u64 = 175200 ;
747
+ let epochs_per_year_key = get_epochs_per_year_key ( ) ;
748
+ updates. push ( migrations:: DbUpdateType :: Add {
749
+ key : epochs_per_year_key,
750
+ cf : DbColFam :: SUBSPACE ,
751
+ value : EPOCHS_PER_YEAR . into ( ) ,
752
+ force : false ,
753
+ } ) ;
754
+ // Set the MASP epoch multiplier to the specified constant
755
+ const MASP_EPOCH_MULTIPLIER : u64 = 2 ;
756
+ let masp_epoch_multiplier_key = get_masp_epoch_multiplier_key ( ) ;
757
+ updates. push ( migrations:: DbUpdateType :: Add {
758
+ key : masp_epoch_multiplier_key,
759
+ cf : DbColFam :: SUBSPACE ,
760
+ value : MASP_EPOCH_MULTIPLIER . into ( ) ,
761
+ force : false ,
762
+ } ) ;
763
+ // Set the epoch duration to the specified constant
764
+ const MIN_NUM_OF_BLOCKS : u64 = 4 ;
765
+ let epy_i64 = i64:: try_from ( EPOCHS_PER_YEAR )
766
+ . expect ( "`epochs_per_year` must not exceed `i64::MAX`" ) ;
767
+ #[ allow( clippy:: arithmetic_side_effects) ]
768
+ let min_duration: i64 = 60 * 60 * 24 * 365 / epy_i64;
769
+ let epoch_duration = EpochDuration {
770
+ min_num_of_blocks : MIN_NUM_OF_BLOCKS ,
771
+ min_duration : namada_sdk:: time:: Duration :: seconds ( min_duration) . into ( ) ,
772
+ } ;
773
+ let epoch_duration_key = get_epoch_duration_storage_key ( ) ;
774
+ updates. push ( migrations:: DbUpdateType :: Add {
775
+ key : epoch_duration_key,
776
+ cf : DbColFam :: SUBSPACE ,
777
+ value : epoch_duration. into ( ) ,
778
+ force : false ,
779
+ } ) ;
780
+ // Set the next epoch's block height to zero in order to force transition
781
+ updates. push ( migrations:: DbUpdateType :: Add {
782
+ key : migrations:: NEXT_EPOCH_MIN_START_HEIGHT_KEY
783
+ . parse ( )
784
+ . expect ( "unable to construct conversion state key" ) ,
785
+ cf : DbColFam :: STATE ,
786
+ value : BlockHeight ( 0 ) . into ( ) ,
787
+ force : false ,
788
+ } ) ;
789
+ // Set the next epoch's start time to a minimum in order to force transition
790
+ updates. push ( migrations:: DbUpdateType :: Add {
791
+ key : migrations:: NEXT_EPOCH_MIN_START_TIME_KEY
792
+ . parse ( )
793
+ . expect ( "unable to construct conversion state key" ) ,
794
+ cf : DbColFam :: STATE ,
795
+ value : MIN_UTC . into ( ) ,
796
+ force : false ,
797
+ } ) ;
798
+ }
799
+
737
800
/// Generate various migrations
738
801
pub fn main ( ) {
739
802
// Write an example migration that updates minted balances
@@ -796,4 +859,13 @@ pub fn main() {
796
859
serde_json:: to_string ( & reward_parameter_changes) . unwrap ( ) ,
797
860
)
798
861
. unwrap ( ) ;
862
+ // Write an example migration that accelerates epochs
863
+ let mut accelerate_epochs_changes =
864
+ migrations:: DbChanges { changes : vec ! [ ] } ;
865
+ accelerate_epoch_migration ( & mut accelerate_epochs_changes. changes ) ;
866
+ std:: fs:: write (
867
+ "accelerate_epochs_migration.json" ,
868
+ serde_json:: to_string ( & accelerate_epochs_changes) . unwrap ( ) ,
869
+ )
870
+ . unwrap ( ) ;
799
871
}
0 commit comments