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

Commit 3317a4b

Browse files
committed
REVERT ME: demo that Drop impl doesn't work
1 parent 7f4a837 commit 3317a4b

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

frame/election-provider-multi-phase/src/benchmarking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ frame_benchmarking::benchmarks! {
282282
let signed_submission = SignedSubmission { solution, ..Default::default() };
283283
signed_submissions.insert(signed_submission);
284284
}
285-
signed_submissions.put();
285+
drop(signed_submissions);
286286

287287
let caller = frame_benchmarking::whitelisted_caller();
288288
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance() * 10u32.into());

frame/election-provider-multi-phase/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,6 @@ pub mod pallet {
900900
.map_err(|_| Error::<T>::SignedCannotPayDeposit)?;
901901
}
902902

903-
signed_submissions.put();
904903
Self::deposit_event(Event::SolutionStored(ElectionCompute::Signed, ejected_a_solution));
905904
Ok(())
906905
}

frame/election-provider-multi-phase/src/signed.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ impl<T: Config> SignedSubmissions<T> {
123123
}
124124
}
125125

126-
/// Put the signed submissions back into storage.
127-
pub fn put(self) {
128-
SignedSubmissionIndices::<T>::put(self.indices);
129-
SignedSubmissionNextIndex::<T>::put(self.next_idx);
130-
for key in self.deletion_overlay {
131-
SignedSubmissionsMap::<T>::remove(key);
132-
}
133-
for (key, value) in self.insertion_overlay {
134-
SignedSubmissionsMap::<T>::insert(key, value);
135-
}
136-
}
137-
138126
/// Get the submission at a particular index.
139127
fn map_get(&self, idx: u32) -> Option<SignedSubmissionOf<T>> {
140128
self.insertion_overlay
@@ -166,7 +154,7 @@ impl<T: Config> SignedSubmissions<T> {
166154
/// arbitrary order
167155
pub fn drain(&mut self) -> impl '_ + Iterator<Item = SignedSubmissionOf<T>> {
168156
self.indices.clear();
169-
SignedSubmissionNextIndex::<T>::kill();
157+
self.next_idx = 0;
170158
let insertion_overlay = sp_std::mem::take(&mut self.insertion_overlay);
171159
SignedSubmissionsMap::<T>::drain()
172160
.filter(move |(k, _v)| !self.deletion_overlay.contains(k))
@@ -255,6 +243,20 @@ impl<T: Config> Deref for SignedSubmissions<T> {
255243
}
256244
}
257245

246+
impl<T: Config> Drop for SignedSubmissions<T> {
247+
fn drop(&mut self) {
248+
SignedSubmissionIndices::<T>::put(sp_std::mem::take(&mut self.indices));
249+
SignedSubmissionNextIndex::<T>::put(self.next_idx);
250+
251+
for key in self.deletion_overlay.iter().copied() {
252+
SignedSubmissionsMap::<T>::remove(key);
253+
}
254+
for (key, value) in sp_std::mem::take(&mut self.insertion_overlay) {
255+
SignedSubmissionsMap::<T>::insert(key, value);
256+
}
257+
}
258+
}
259+
258260
impl<T: Config> Pallet<T> {
259261
/// `Self` accessor for `SignedSubmission<T>`.
260262
pub fn signed_submissions() -> SignedSubmissions<T> {
@@ -321,8 +323,6 @@ impl<T: Config> Pallet<T> {
321323
debug_assert!(_remaining.is_zero());
322324
}
323325

324-
all_submissions.put();
325-
326326
log!(debug, "closed signed phase, found solution? {}, discarded {}", found_solution, discarded);
327327
(found_solution, weight)
328328
}

0 commit comments

Comments
 (0)