@@ -842,7 +842,12 @@ pub mod pallet {
842842
843843 <NextExternal < T > >:: kill ( ) ;
844844 let now = <frame_system:: Pallet < T > >:: block_number ( ) ;
845- Self :: inject_referendum ( now + voting_period, proposal_hash, threshold, delay) ;
845+ Self :: inject_referendum (
846+ now. saturating_add ( voting_period) ,
847+ proposal_hash,
848+ threshold,
849+ delay,
850+ ) ;
846851 Ok ( ( ) )
847852 }
848853
@@ -871,7 +876,8 @@ pub mod pallet {
871876 existing_vetoers. binary_search ( & who) . err ( ) . ok_or ( Error :: < T > :: AlreadyVetoed ) ?;
872877
873878 existing_vetoers. insert ( insert_position, who. clone ( ) ) ;
874- let until = <frame_system:: Pallet < T > >:: block_number ( ) + T :: CooloffPeriod :: get ( ) ;
879+ let until =
880+ <frame_system:: Pallet < T > >:: block_number ( ) . saturating_add ( T :: CooloffPeriod :: get ( ) ) ;
875881 <Blacklist < T > >:: insert ( & proposal_hash, ( until, existing_vetoers) ) ;
876882
877883 Self :: deposit_event ( Event :: < T > :: Vetoed { who, proposal_hash, until } ) ;
@@ -1089,7 +1095,10 @@ pub mod pallet {
10891095 let now = <frame_system:: Pallet < T > >:: block_number ( ) ;
10901096 let ( voting, enactment) = ( T :: VotingPeriod :: get ( ) , T :: EnactmentPeriod :: get ( ) ) ;
10911097 let additional = if who == provider { Zero :: zero ( ) } else { enactment } ;
1092- ensure ! ( now >= since + voting + additional, Error :: <T >:: TooEarly ) ;
1098+ ensure ! (
1099+ now >= since. saturating_add( voting) . saturating_add( additional) ,
1100+ Error :: <T >:: TooEarly
1101+ ) ;
10931102 ensure ! ( expiry. map_or( true , |e| now > e) , Error :: <T >:: Imminent ) ;
10941103
10951104 let res =
@@ -1282,7 +1291,7 @@ impl<T: Config> Pallet<T> {
12821291 /// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal
12831292 /// index.
12841293 pub fn backing_for ( proposal : PropIndex ) -> Option < BalanceOf < T > > {
1285- Self :: deposit_of ( proposal) . map ( |( l, d) | d * ( l. len ( ) as u32 ) . into ( ) )
1294+ Self :: deposit_of ( proposal) . map ( |( l, d) | d. saturating_mul ( ( l. len ( ) as u32 ) . into ( ) ) )
12861295 }
12871296
12881297 /// Get all referenda ready for tally at block `n`.
@@ -1318,7 +1327,7 @@ impl<T: Config> Pallet<T> {
13181327 delay : T :: BlockNumber ,
13191328 ) -> ReferendumIndex {
13201329 <Pallet < T > >:: inject_referendum (
1321- <frame_system:: Pallet < T > >:: block_number ( ) + T :: VotingPeriod :: get ( ) ,
1330+ <frame_system:: Pallet < T > >:: block_number ( ) . saturating_add ( T :: VotingPeriod :: get ( ) ) ,
13221331 proposal_hash,
13231332 threshold,
13241333 delay,
@@ -1424,7 +1433,9 @@ impl<T: Config> Pallet<T> {
14241433 } ,
14251434 Some ( ReferendumInfo :: Finished { end, approved } ) => {
14261435 if let Some ( ( lock_periods, balance) ) = votes[ i] . 1 . locked_if ( approved) {
1427- let unlock_at = end + T :: VoteLockingPeriod :: get ( ) * lock_periods. into ( ) ;
1436+ let unlock_at = end. saturating_add (
1437+ T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods. into ( ) ) ,
1438+ ) ;
14281439 let now = frame_system:: Pallet :: < T > :: block_number ( ) ;
14291440 if now < unlock_at {
14301441 ensure ! (
@@ -1513,9 +1524,16 @@ impl<T: Config> Pallet<T> {
15131524 } ;
15141525 sp_std:: mem:: swap ( & mut old, voting) ;
15151526 match old {
1516- Voting :: Delegating { balance, target, conviction, delegations, prior, .. } => {
1527+ Voting :: Delegating {
1528+ balance, target, conviction, delegations, mut prior, ..
1529+ } => {
15171530 // remove any delegation votes to our current target.
15181531 Self :: reduce_upstream_delegation ( & target, conviction. votes ( balance) ) ;
1532+ let now = frame_system:: Pallet :: < T > :: block_number ( ) ;
1533+ let lock_periods = conviction. lock_periods ( ) . into ( ) ;
1534+ let unlock_block = now
1535+ . saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
1536+ prior. accumulate ( unlock_block, balance) ;
15191537 voting. set_common ( delegations, prior) ;
15201538 } ,
15211539 Voting :: Direct { votes, delegations, prior } => {
@@ -1548,7 +1566,9 @@ impl<T: Config> Pallet<T> {
15481566 Self :: reduce_upstream_delegation ( & target, conviction. votes ( balance) ) ;
15491567 let now = frame_system:: Pallet :: < T > :: block_number ( ) ;
15501568 let lock_periods = conviction. lock_periods ( ) . into ( ) ;
1551- prior. accumulate ( now + T :: VoteLockingPeriod :: get ( ) * lock_periods, balance) ;
1569+ let unlock_block = now
1570+ . saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
1571+ prior. accumulate ( unlock_block, balance) ;
15521572 voting. set_common ( delegations, prior) ;
15531573
15541574 Ok ( votes)
@@ -1607,7 +1627,7 @@ impl<T: Config> Pallet<T> {
16071627 LastTabledWasExternal :: < T > :: put ( true ) ;
16081628 Self :: deposit_event ( Event :: < T > :: ExternalTabled ) ;
16091629 Self :: inject_referendum (
1610- now + T :: VotingPeriod :: get ( ) ,
1630+ now. saturating_add ( T :: VotingPeriod :: get ( ) ) ,
16111631 proposal,
16121632 threshold,
16131633 T :: EnactmentPeriod :: get ( ) ,
@@ -1639,7 +1659,7 @@ impl<T: Config> Pallet<T> {
16391659 depositors,
16401660 } ) ;
16411661 Self :: inject_referendum (
1642- now + T :: VotingPeriod :: get ( ) ,
1662+ now. saturating_add ( T :: VotingPeriod :: get ( ) ) ,
16431663 proposal,
16441664 VoteThreshold :: SuperMajorityApprove ,
16451665 T :: EnactmentPeriod :: get ( ) ,
@@ -1693,7 +1713,7 @@ impl<T: Config> Pallet<T> {
16931713 if status. delay . is_zero ( ) {
16941714 let _ = Self :: do_enact_proposal ( status. proposal_hash , index) ;
16951715 } else {
1696- let when = now + status. delay ;
1716+ let when = now. saturating_add ( status. delay ) ;
16971717 // Note that we need the preimage now.
16981718 Preimages :: < T > :: mutate_exists (
16991719 & status. proposal_hash ,
0 commit comments