@@ -228,7 +228,9 @@ impl EpochManager {
228228 let total_block_producer_stake: u128 = epoch_info
229229 . block_producers_settlement
230230 . iter ( )
231- . map ( |id| epoch_info. validators [ * id as usize ] . stake )
231+ . collect :: < HashSet < _ > > ( )
232+ . iter ( )
233+ . map ( |& id| epoch_info. validators [ * id as usize ] . stake )
232234 . sum ( ) ;
233235
234236 let next_version = if let Some ( ( & version, stake) ) =
@@ -2934,4 +2936,37 @@ mod tests {
29342936 PROTOCOL_VERSION
29352937 ) ;
29362938 }
2939+
2940+ #[ test]
2941+ fn test_protocol_version_switch_with_many_seats ( ) {
2942+ let store = create_test_store ( ) ;
2943+ let mut config = epoch_config ( 10 , 1 , 4 , 0 , 90 , 60 , 0 ) ;
2944+ config. num_block_producer_seats_per_shard = vec ! [ 10 ] ;
2945+ let amount_staked = 1_000_000 ;
2946+ let validators = vec ! [ stake( "test1" , amount_staked) , stake( "test2" , amount_staked / 5 ) ] ;
2947+ let mut epoch_manager = EpochManager :: new (
2948+ store. clone ( ) ,
2949+ config. clone ( ) ,
2950+ 0 ,
2951+ default_reward_calculator ( ) ,
2952+ validators. clone ( ) ,
2953+ )
2954+ . unwrap ( ) ;
2955+ let h = hash_range ( 50 ) ;
2956+ record_block ( & mut epoch_manager, CryptoHash :: default ( ) , h[ 0 ] , 0 , vec ! [ ] ) ;
2957+ let mut block_info1 = block_info ( 1 , 1 , h[ 0 ] , h[ 0 ] , h[ 0 ] , vec ! [ ] , DEFAULT_TOTAL_SUPPLY ) ;
2958+ block_info1. latest_protocol_version = 0 ;
2959+ epoch_manager. record_block_info ( & h[ 1 ] , block_info1, [ 0 ; 32 ] ) . unwrap ( ) ;
2960+ for i in 2 ..32 {
2961+ record_block ( & mut epoch_manager, h[ i - 1 ] , h[ i] , i as u64 , vec ! [ ] ) ;
2962+ }
2963+ assert_eq ! (
2964+ epoch_manager. get_epoch_info( & EpochId ( h[ 10 ] ) ) . unwrap( ) . protocol_version,
2965+ PROTOCOL_VERSION
2966+ ) ;
2967+ assert_eq ! (
2968+ epoch_manager. get_epoch_info( & EpochId ( h[ 20 ] ) ) . unwrap( ) . protocol_version,
2969+ PROTOCOL_VERSION
2970+ ) ;
2971+ }
29372972}
0 commit comments