Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit c360e4b

Browse files
gavofyorkniklasad1
authored andcommitted
Timeout only if the referendum is not queued (#14106)
* Timeout only if the referendum is not queued * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: command-bot <>
1 parent b2d5b9b commit c360e4b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

frame/referenda/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use frame_support::{
7979
};
8080
use scale_info::TypeInfo;
8181
use sp_runtime::{
82-
traits::{AtLeast32BitUnsigned, Dispatchable, One, Saturating, Zero},
82+
traits::{AtLeast32BitUnsigned, Bounded, Dispatchable, One, Saturating, Zero},
8383
DispatchError, Perbill,
8484
};
8585
use 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

frame/referenda/src/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ fn queueing_works() {
190190
set_balance_proposal_bounded(i),
191191
DispatchTime::After(0),
192192
));
193+
}
194+
for i in [1, 2, 4] {
193195
assert_ok!(Referenda::place_decision_deposit(RuntimeOrigin::signed(i), i as u32));
194196
// TODO: decision deposit after some initial votes with a non-highest voted coming
195197
// first.

0 commit comments

Comments
 (0)