@@ -287,37 +287,34 @@ pub fn is_valid_skip(
287287 target_block_commit : & Commit ,
288288) -> bool {
289289 let threshold = 2_f64 / 3_f64 ;
290+
290291 let mut shared_voting_power = 0_u64 ;
291- let target_block_total_voting_power = target_validator_set. total_voting_power ( ) . value ( ) ;
292- let start_block_validators = start_validator_set. validators ( ) ;
293- let mut start_block_idx = 0 ;
294- let start_block_num_validators = start_block_validators. len ( ) ;
295-
296- // Exit if the threshold is met.
297- while ( target_block_total_voting_power as f64 ) * threshold > shared_voting_power as f64
298- && start_block_idx < start_block_num_validators
299- {
300- if let Some ( target_block_validator) =
301- target_validator_set. validator ( start_block_validators[ start_block_idx] . address )
302- {
303- // Confirm that the validator has signed on target_block.
304- for sig in target_block_commit. signatures . iter ( ) {
305- if !sig. is_commit ( ) {
306- continue ;
307- }
308-
309- if let Some ( validator_address) = sig. validator_address ( ) {
310- if validator_address == target_block_validator. address {
311- // Add the shared voting power to the validator
312- shared_voting_power += target_block_validator. power . value ( ) ;
313- }
314- }
292+ let mut target_shared_voting_power = 0_u64 ;
293+
294+ for sig in target_block_commit. signatures . iter ( ) {
295+ if !sig. is_commit ( ) {
296+ continue ;
297+ }
298+
299+ if let Some ( validator_address) = sig. validator_address ( ) {
300+ if let Some ( trusted_validator) = start_validator_set. validator ( validator_address) {
301+ shared_voting_power += trusted_validator. power ( ) ;
302+ }
303+
304+ if let Some ( target_validator) = target_validator_set. validator ( validator_address) {
305+ target_shared_voting_power += target_validator. power ( ) ;
315306 }
316307 }
317- start_block_idx += 1 ;
318308 }
319309
320- ( target_block_total_voting_power as f64 ) * threshold <= shared_voting_power as f64
310+ let start_meets_threshold = ( start_validator_set. total_voting_power ( ) . value ( ) as f64 )
311+ * threshold
312+ <= shared_voting_power as f64 ;
313+ let target_meets_threshold = ( target_validator_set. total_voting_power ( ) . value ( ) as f64 )
314+ * threshold
315+ <= target_shared_voting_power as f64 ;
316+
317+ start_meets_threshold && target_meets_threshold
321318}
322319
323320/// Fetches a header hash for a specific block height.
0 commit comments