@@ -79,7 +79,7 @@ use frame_support::{
7979} ;
8080use scale_info:: TypeInfo ;
8181use sp_runtime:: {
82- traits:: { AtLeast32BitUnsigned , Dispatchable , One , Saturating , Zero } ,
82+ traits:: { AtLeast32BitUnsigned , Bounded , Dispatchable , One , Saturating , Zero } ,
8383 DispatchError , Perbill ,
8484} ;
8585use sp_std:: { fmt:: Debug , prelude:: * } ;
@@ -1054,9 +1054,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
10541054 Some ( x) => x,
10551055 None => return ( ReferendumInfo :: Ongoing ( status) , false , ServiceBranch :: Fail ) ,
10561056 } ;
1057+ // Default the alarm to the end of the world.
10571058 let timeout = status. submitted + T :: UndecidingTimeout :: get ( ) ;
1058- // Default the alarm to the submission timeout.
1059- let mut alarm = timeout;
1059+ let mut alarm = T :: BlockNumber :: max_value ( ) ;
10601060 let branch;
10611061 match & mut status. deciding {
10621062 None => {
@@ -1097,11 +1097,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
10971097 ServiceBranch :: Preparing
10981098 }
10991099 } else {
1100+ alarm = timeout;
11001101 ServiceBranch :: NoDeposit
11011102 }
11021103 }
11031104 // If we didn't move into being decided, then check the timeout.
1104- if status. deciding . is_none ( ) && now >= timeout {
1105+ if status. deciding . is_none ( ) && now >= timeout && !status . in_queue {
11051106 // Too long without being decided - end it.
11061107 Self :: ensure_no_alarm ( & mut status) ;
11071108 Self :: deposit_event ( Event :: < T , I > :: TimedOut { index, tally : status. tally } ) ;
@@ -1186,7 +1187,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
11861187 } ,
11871188 }
11881189
1189- let dirty_alarm = Self :: ensure_alarm_at ( & mut status, index, alarm) ;
1190+ let dirty_alarm = if alarm < T :: BlockNumber :: max_value ( ) {
1191+ Self :: ensure_alarm_at ( & mut status, index, alarm)
1192+ } else {
1193+ Self :: ensure_no_alarm ( & mut status)
1194+ } ;
11901195 ( ReferendumInfo :: Ongoing ( status) , dirty_alarm || dirty, branch)
11911196 }
11921197
@@ -1210,10 +1215,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
12101215 }
12111216
12121217 /// Cancel the alarm in `status`, if one exists.
1213- fn ensure_no_alarm ( status : & mut ReferendumStatusOf < T , I > ) {
1218+ fn ensure_no_alarm ( status : & mut ReferendumStatusOf < T , I > ) -> bool {
12141219 if let Some ( ( _, last_alarm) ) = status. alarm . take ( ) {
12151220 // Incorrect alarm - cancel it.
12161221 let _ = T :: Scheduler :: cancel ( last_alarm) ;
1222+ true
1223+ } else {
1224+ false
12171225 }
12181226 }
12191227
0 commit comments