@@ -102,6 +102,14 @@ fn get_accumulator_state(bank: &Bank, ring_index: u32) -> Vec<u8> {
102102 account. data ( ) . to_vec ( )
103103}
104104
105+ fn activate_feature ( bank : & mut Bank , feature_id : & Pubkey ) {
106+ let feature = Feature {
107+ activated_at : Some ( 30 ) ,
108+ } ;
109+ bank. store_account ( & feature_id, & feature:: create_account ( & feature, 42 ) ) ;
110+ bank. compute_active_feature_set ( true ) ;
111+ }
112+
105113#[ test]
106114fn test_update_accumulator_sysvar ( ) {
107115 let leader_pubkey = solana_sdk:: pubkey:: new_rand ( ) ;
@@ -193,16 +201,10 @@ fn test_update_accumulator_sysvar() {
193201 assert_eq ! ( wormhole_message_account. data( ) . len( ) , 0 ) ;
194202
195203 // Enable Accumulator Feature (42 = random lamport balance, and the meaning of the universe).
196- let feature_id = feature_set:: enable_accumulator_sysvar:: id ( ) ;
197- let feature = Feature {
198- activated_at : Some ( 30 ) ,
199- } ;
200- bank. store_account ( & feature_id, & feature:: create_account ( & feature, 42 ) ) ;
201- bank. compute_active_feature_set ( true ) ;
202- for _ in 0 ..slots_in_epoch {
203- bank = new_from_parent ( & Arc :: new ( bank) ) ;
204- }
205-
204+ activate_feature ( & mut bank, & feature_set:: enable_accumulator_sysvar:: id ( ) ) ;
205+ for _ in 0 ..slots_in_epoch {
206+ bank = new_from_parent ( & Arc :: new ( bank) ) ;
207+ }
206208 // Feature should now be enabled on the new bank as the epoch has changed.
207209 assert ! ( bank
208210 . feature_set
@@ -482,19 +484,8 @@ fn test_update_accumulator_end_of_block() {
482484 assert_eq ! ( wormhole_message_account. data( ) . len( ) , 0 ) ;
483485
484486 // Enable Accumulator Features (42 = random lamport balance, and the meaning of the universe).
485- let feature_id = feature_set:: enable_accumulator_sysvar:: id ( ) ;
486- let feature = Feature {
487- activated_at : Some ( 30 ) ,
488- } ;
489- bank. store_account ( & feature_id, & feature:: create_account ( & feature, 42 ) ) ;
490-
491- let feature_id = feature_set:: move_accumulator_to_end_of_block:: id ( ) ;
492- let feature = Feature {
493- activated_at : Some ( 30 ) ,
494- } ;
495- bank. store_account ( & feature_id, & feature:: create_account ( & feature, 42 ) ) ;
496-
497- bank. compute_active_feature_set ( true ) ;
487+ activate_feature ( & mut bank, & feature_set:: enable_accumulator_sysvar:: id ( ) ) ;
488+ activate_feature ( & mut bank, & feature_set:: move_accumulator_to_end_of_block:: id ( ) ) ;
498489 for _ in 0 ..slots_in_epoch {
499490 bank = new_from_parent ( & Arc :: new ( bank) ) ;
500491 }
@@ -676,21 +667,6 @@ fn test_update_accumulator_end_of_block() {
676667 ) ;
677668}
678669
679- #[ test]
680- fn test_accumulator_v2_all_v2 ( ) {
681- test_accumulator_v2 ( [ false , false , false , false ] ) ;
682- }
683-
684- #[ test]
685- fn test_accumulator_v2_all_v1 ( ) {
686- test_accumulator_v2 ( [ true , true , true , true ] ) ;
687- }
688-
689- #[ test]
690- fn test_accumulator_v2_mixed ( ) {
691- test_accumulator_v2 ( [ true , true , false , false ] ) ;
692- }
693-
694670fn generate_price ( bank : & Bank , seeds : & [ u8 ] , generate_buffers : bool , publishers : & [ Pubkey ] ) -> ( Pubkey , Vec < Vec < u8 > > ) {
695671 let ( price_feed_key, _bump) = Pubkey :: find_program_address ( & [ seeds] , & ORACLE_PID ) ;
696672 let mut price_feed_account =
@@ -838,6 +814,21 @@ fn check_accumulator_state_matches_messages(bank: &Bank, sequence_tracker_before
838814 ) ;
839815}
840816
817+ #[ test]
818+ fn test_accumulator_v2_all_v2 ( ) {
819+ test_accumulator_v2 ( [ false , false , false , false ] ) ;
820+ }
821+
822+ #[ test]
823+ fn test_accumulator_v2_all_v1 ( ) {
824+ test_accumulator_v2 ( [ true , true , true , true ] ) ;
825+ }
826+
827+ #[ test]
828+ fn test_accumulator_v2_mixed ( ) {
829+ test_accumulator_v2 ( [ true , true , false , false ] ) ;
830+ }
831+
841832fn test_accumulator_v2 ( generate_buffers : [ bool ; 4 ] ) {
842833 let leader_pubkey = solana_sdk:: pubkey:: new_rand ( ) ;
843834 let GenesisConfigInfo {
@@ -926,30 +917,25 @@ fn test_publisher_stake_caps() {
926917 . feature_set
927918 . is_active( & feature_set:: redo_move_accumulator_to_end_of_block:: id( ) ) ) ;
928919
929- let new_m = 1_000_000_000_000 ;
930- let new_z = 3 ;
931-
920+ // We will set the stake cap parameters to this later
921+ let new_m = 1_000_000_000_000 ;
922+ let new_z = 3 ;
923+ // This is an array of tuples where each tuple contains the pubkey of the publisher, the expected cap with default values and the expected cap with the new values.
932924 let mut publishers_with_expected_caps : [ ( Pubkey , u64 , u64 ) ; 4 ] = [
933925 ( solana_sdk:: pubkey:: new_rand ( ) , StakeCapParameters :: default ( ) . m * 5 / 4 , new_m / 3 + new_m / 4 ) ,
934926 ( solana_sdk:: pubkey:: new_rand ( ) , StakeCapParameters :: default ( ) . m * 3 / 4 , new_m / 3 + new_m / 4 ) ,
935927 ( solana_sdk:: pubkey:: new_rand ( ) , StakeCapParameters :: default ( ) . m * 3 / 4 , new_m / 3 + new_m / 4 ) ,
936928 ( solana_sdk:: pubkey:: new_rand ( ) , StakeCapParameters :: default ( ) . m * 5 / 4 , new_m / 3 + new_m / 4 )
937929 ] ;
938930
939- let expected_caps = [ [
940- StakeCapParameters :: default ( ) . m * 5 / 4 ,
941- StakeCapParameters :: default ( ) . m * 3 / 4 ,
942- StakeCapParameters :: default ( ) . m * 2 / 4 ,
943- StakeCapParameters :: default ( ) . m * 1 / 4 ,
944- ] , [ new_m / 3 + new_m / 4 , new_m / 3 + new_m / 4 , new_m / 3 + new_m / 4 , new_m / 3 + new_m / 4 ] ] ;
945-
946931 let prices_with_messages = [
947932 generate_price ( & bank, b"seeds_1" , false , & [ publishers_with_expected_caps[ 0 ] . 0 ] ) ,
948933 generate_price ( & bank, b"seeds_2" , false , & [ publishers_with_expected_caps[ 1 ] . 0 , publishers_with_expected_caps[ 2 ] . 0 ] ) ,
949934 generate_price ( & bank, b"seeds_3" , true , & [ publishers_with_expected_caps[ 3 ] . 0 ] ) ,
950935 generate_price ( & bank, b"seeds_4" , true , & [ publishers_with_expected_caps[ 3 ] . 0 , publishers_with_expected_caps[ 1 ] . 0 , publishers_with_expected_caps[ 0 ] . 0 , publishers_with_expected_caps[ 2 ] . 0 ] )
951936 ] ;
952937
938+ // Publishers are sorted in the publisher stake caps message so we sort them here too
953939 publishers_with_expected_caps. sort_by_key ( |( pk, _, _) | * pk) ;
954940
955941 bank = new_from_parent ( & Arc :: new ( bank) ) ; // Advance slot 1.
@@ -965,23 +951,15 @@ fn test_publisher_stake_caps() {
965951 . collect :: < Vec < _ > > ( ) ;
966952 assert_eq ! ( messages. len( ) , 8 ) ;
967953
968- let feature_id = feature_set:: add_publisher_stake_caps_to_the_accumulator:: id ( ) ;
969- let feature = Feature {
970- activated_at : Some ( 30 ) ,
971- } ;
972- bank. store_account ( & feature_id, & feature:: create_account ( & feature, 42 ) ) ;
954+ // We turn on the feature to add publisher stake caps to the accumulator but it won't be active until next epoch
955+ activate_feature ( & mut bank, & feature_set:: add_publisher_stake_caps_to_the_accumulator:: id ( ) ) ;
973956
974- bank. compute_active_feature_set ( true ) ;
975-
976- // Trigger Aggregation. We freeze instead of new_from_parent so
957+ // Trigger accumulation. We freeze instead of new_from_parent so
977958 // we can keep access to the bank.
978959 let sequence_tracker_before_bank_freeze = get_acc_sequence_tracker ( & bank) ;
979960 bank. freeze ( ) ;
980-
981961 check_accumulator_state_matches_messages ( & bank, & sequence_tracker_before_bank_freeze, & messages) ;
982962
983- // Enable Publisher Stake Caps
984-
985963 for _ in 0 ..slots_in_epoch {
986964 bank = new_from_parent ( & Arc :: new ( bank) ) ;
987965 }
@@ -996,19 +974,22 @@ fn test_publisher_stake_caps() {
996974 result
997975 } ;
998976
999-
977+ // Now the messages contain the publisher caps message
1000978 messages. push ( & publisher_caps_message) ;
979+ assert_eq ! ( messages. len( ) , 9 ) ;
1001980
1002981 let sequence_tracker_before_bank_freeze = get_acc_sequence_tracker ( & bank) ;
1003982 bank. freeze ( ) ;
1004983 check_accumulator_state_matches_messages ( & bank, & sequence_tracker_before_bank_freeze, & messages) ;
984+
1005985 bank = new_from_parent ( & Arc :: new ( bank) ) ;
1006986
1007- // Now store the stake cap parameters
987+ // Now we update the stake cap parameters
1008988 let mut stake_cap_parameters_account = AccountSharedData :: new ( 42 , size_of :: < StakeCapParameters > ( ) , & ORACLE_PID ) ;
1009989 stake_cap_parameters_account. set_data ( StakeCapParameters { _discriminator : 0 , _current_authority : [ 0u8 ; 32 ] , m : new_m, z : new_z } . try_to_vec ( ) . unwrap ( ) ) ;
1010990 bank. store_account ( & STAKE_CAPS_PARAMETERS_ADDR , & stake_cap_parameters_account) ;
1011991
992+
1012993 let publisher_caps_message_with_new_parameters = {
1013994 let mut result = vec ! [ 2 ] ;
1014995 result. extend_from_slice ( & bank. clock ( ) . unix_timestamp . to_be_bytes ( ) ) ;
@@ -1019,8 +1000,10 @@ fn test_publisher_stake_caps() {
10191000 result
10201001 } ;
10211002
1003+ // Update the publisher caps message in the message arrays to match the new parameters
10221004 let last_element_index = messages. len ( ) - 1 ;
10231005 messages[ last_element_index] = & publisher_caps_message_with_new_parameters;
1006+ assert_eq ! ( messages. len( ) , 9 ) ;
10241007
10251008 let sequence_tracker_before_bank_freeze = get_acc_sequence_tracker ( & bank) ;
10261009 bank. freeze ( ) ;
0 commit comments