@@ -54,7 +54,7 @@ use frame_support::{
5454use scale_info:: TypeInfo ;
5555use sp_io:: storage;
5656use sp_runtime:: traits:: Dispatchable ;
57- use sp_runtime:: { traits:: Hash , RuntimeDebug } ;
57+ use sp_runtime:: { traits:: Hash , RuntimeDebug , Saturating } ;
5858use sp_std:: { marker:: PhantomData , prelude:: * , result} ;
5959
6060#[ cfg( test) ]
@@ -119,7 +119,7 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
119119 _no_votes : MemberCount ,
120120 len : MemberCount ,
121121 ) -> bool {
122- let more_than_majority = yes_votes * 2 > len;
122+ let more_than_majority = yes_votes. saturating_mul ( 2 ) > len;
123123 more_than_majority || prime_vote. unwrap_or ( false )
124124 }
125125}
@@ -545,7 +545,9 @@ pub mod pallet {
545545 Error :: <T , I >:: DurationLowerThanConfiguredMotionDuration
546546 ) ;
547547
548- let threshold = ( T :: GetVotingMembers :: get_count ( ) / 2 ) + 1 ;
548+ let threshold = T :: GetVotingMembers :: get_count ( )
549+ . saturating_div ( 2 )
550+ . saturating_add ( 1 ) ;
549551
550552 let members = Self :: members ( ) ;
551553 let ( proposal_len, active_proposals) =
@@ -716,10 +718,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
716718 } ) ?;
717719
718720 let index = Self :: proposal_count ( ) ;
719- <ProposalCount < T , I > >:: mutate ( |i| * i += 1 ) ;
721+ <ProposalCount < T , I > >:: try_mutate ( |i| {
722+ * i = i
723+ . checked_add ( 1 )
724+ . ok_or ( Error :: < T , I > :: TooManyActiveProposals ) ?;
725+ Ok :: < ( ) , Error < T , I > > ( ( ) )
726+ } ) ?;
720727 <ProposalOf < T , I > >:: insert ( proposal_hash, proposal) ;
721728 let votes = {
722- let end = frame_system:: Pallet :: < T > :: block_number ( ) + duration;
729+ let end = frame_system:: Pallet :: < T > :: block_number ( ) . saturating_add ( duration) ;
723730 Votes {
724731 index,
725732 threshold,
@@ -862,10 +869,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
862869 // default voting strategy.
863870 let default = T :: DefaultVote :: default_vote ( prime_vote, yes_votes, no_votes, seats) ;
864871
865- let abstentions = seats - ( yes_votes + no_votes) ;
872+ let abstentions = seats. saturating_sub ( yes_votes. saturating_add ( no_votes) ) ;
866873 match default {
867- true => yes_votes += abstentions,
868- false => no_votes += abstentions,
874+ true => yes_votes = yes_votes . saturating_add ( abstentions) ,
875+ false => no_votes = no_votes . saturating_add ( abstentions) ,
869876 }
870877 let approved = yes_votes >= voting. threshold ;
871878
@@ -981,7 +988,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
981988 Voting :: < T , I > :: remove ( proposal_hash) ;
982989 let num_proposals = Proposals :: < T , I > :: mutate ( |proposals| {
983990 proposals. retain ( |h| h != & proposal_hash) ;
984- proposals. len ( ) + 1 // calculate weight based on original length
991+ proposals. len ( ) . saturating_add ( 1 ) // calculate weight based on original length
985992 } ) ;
986993 num_proposals as u32
987994 }
@@ -1154,7 +1161,7 @@ impl<
11541161 type Success = ( ) ;
11551162 fn try_origin ( o : O ) -> Result < Self :: Success , O > {
11561163 o. into ( ) . and_then ( |o| match o {
1157- RawOrigin :: Members ( n, m) if n * D > N * m => Ok ( ( ) ) ,
1164+ RawOrigin :: Members ( n, m) if n. saturating_mul ( D ) > N . saturating_mul ( m ) => Ok ( ( ) ) ,
11581165 r => Err ( O :: from ( r) ) ,
11591166 } )
11601167 }
@@ -1179,7 +1186,7 @@ impl<
11791186 type Success = ( ) ;
11801187 fn try_origin ( o : O ) -> Result < Self :: Success , O > {
11811188 o. into ( ) . and_then ( |o| match o {
1182- RawOrigin :: Members ( n, m) if n * D >= N * m => Ok ( ( ) ) ,
1189+ RawOrigin :: Members ( n, m) if n. saturating_mul ( D ) >= N . saturating_mul ( m ) => Ok ( ( ) ) ,
11831190 r => Err ( O :: from ( r) ) ,
11841191 } )
11851192 }
0 commit comments