@@ -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) ]
@@ -120,7 +120,7 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
120120 _no_votes : MemberCount ,
121121 len : MemberCount ,
122122 ) -> bool {
123- let more_than_majority = yes_votes * 2 > len;
123+ let more_than_majority = yes_votes. saturating_mul ( 2 ) > len;
124124 more_than_majority || prime_vote. unwrap_or ( false )
125125 }
126126}
@@ -547,7 +547,9 @@ pub mod pallet {
547547 Error :: <T , I >:: DurationLowerThanConfiguredMotionDuration
548548 ) ;
549549
550- let threshold = ( T :: GetVotingMembers :: get_count ( ) / 2 ) + 1 ;
550+ let threshold = T :: GetVotingMembers :: get_count ( )
551+ . saturating_div ( 2 )
552+ . saturating_add ( 1 ) ;
551553
552554 let members = Self :: members ( ) ;
553555 let ( proposal_len, active_proposals) =
@@ -718,10 +720,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
718720 } ) ?;
719721
720722 let index = Self :: proposal_count ( ) ;
721- <ProposalCount < T , I > >:: mutate ( |i| * i += 1 ) ;
723+ <ProposalCount < T , I > >:: try_mutate ( |i| {
724+ * i = i
725+ . checked_add ( 1 )
726+ . ok_or ( Error :: < T , I > :: TooManyActiveProposals ) ?;
727+ Ok :: < ( ) , Error < T , I > > ( ( ) )
728+ } ) ?;
722729 <ProposalOf < T , I > >:: insert ( proposal_hash, proposal) ;
723730 let votes = {
724- let end = frame_system:: Pallet :: < T > :: block_number ( ) + duration;
731+ let end = frame_system:: Pallet :: < T > :: block_number ( ) . saturating_add ( duration) ;
725732 Votes {
726733 index,
727734 threshold,
@@ -864,10 +871,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
864871 // default voting strategy.
865872 let default = T :: DefaultVote :: default_vote ( prime_vote, yes_votes, no_votes, seats) ;
866873
867- let abstentions = seats - ( yes_votes + no_votes) ;
874+ let abstentions = seats. saturating_sub ( yes_votes. saturating_add ( no_votes) ) ;
868875 match default {
869- true => yes_votes += abstentions,
870- false => no_votes += abstentions,
876+ true => yes_votes = yes_votes . saturating_add ( abstentions) ,
877+ false => no_votes = no_votes . saturating_add ( abstentions) ,
871878 }
872879 let approved = yes_votes >= voting. threshold ;
873880
@@ -983,7 +990,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
983990 Voting :: < T , I > :: remove ( proposal_hash) ;
984991 let num_proposals = Proposals :: < T , I > :: mutate ( |proposals| {
985992 proposals. retain ( |h| h != & proposal_hash) ;
986- proposals. len ( ) + 1 // calculate weight based on original length
993+ proposals. len ( ) . saturating_add ( 1 ) // calculate weight based on original length
987994 } ) ;
988995 num_proposals as u32
989996 }
@@ -1156,7 +1163,7 @@ impl<
11561163 type Success = ( ) ;
11571164 fn try_origin ( o : O ) -> Result < Self :: Success , O > {
11581165 o. into ( ) . and_then ( |o| match o {
1159- RawOrigin :: Members ( n, m) if n * D > N * m => Ok ( ( ) ) ,
1166+ RawOrigin :: Members ( n, m) if n. saturating_mul ( D ) > N . saturating_mul ( m ) => Ok ( ( ) ) ,
11601167 r => Err ( O :: from ( r) ) ,
11611168 } )
11621169 }
@@ -1181,7 +1188,7 @@ impl<
11811188 type Success = ( ) ;
11821189 fn try_origin ( o : O ) -> Result < Self :: Success , O > {
11831190 o. into ( ) . and_then ( |o| match o {
1184- RawOrigin :: Members ( n, m) if n * D >= N * m => Ok ( ( ) ) ,
1191+ RawOrigin :: Members ( n, m) if n. saturating_mul ( D ) >= N . saturating_mul ( m ) => Ok ( ( ) ) ,
11851192 r => Err ( O :: from ( r) ) ,
11861193 } )
11871194 }
0 commit comments