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

Commit

Permalink
REVERT ME: demo that Drop impl doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
coriolinus committed Jun 9, 2021
1 parent 7f4a837 commit 3317a4b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ frame_benchmarking::benchmarks! {
let signed_submission = SignedSubmission { solution, ..Default::default() };
signed_submissions.insert(signed_submission);
}
signed_submissions.put();
drop(signed_submissions);

let caller = frame_benchmarking::whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance() * 10u32.into());
Expand Down
1 change: 0 additions & 1 deletion frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ pub mod pallet {
.map_err(|_| Error::<T>::SignedCannotPayDeposit)?;
}

signed_submissions.put();
Self::deposit_event(Event::SolutionStored(ElectionCompute::Signed, ejected_a_solution));
Ok(())
}
Expand Down
30 changes: 15 additions & 15 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ impl<T: Config> SignedSubmissions<T> {
}
}

/// Put the signed submissions back into storage.
pub fn put(self) {
SignedSubmissionIndices::<T>::put(self.indices);
SignedSubmissionNextIndex::<T>::put(self.next_idx);
for key in self.deletion_overlay {
SignedSubmissionsMap::<T>::remove(key);
}
for (key, value) in self.insertion_overlay {
SignedSubmissionsMap::<T>::insert(key, value);
}
}

/// Get the submission at a particular index.
fn map_get(&self, idx: u32) -> Option<SignedSubmissionOf<T>> {
self.insertion_overlay
Expand Down Expand Up @@ -166,7 +154,7 @@ impl<T: Config> SignedSubmissions<T> {
/// arbitrary order
pub fn drain(&mut self) -> impl '_ + Iterator<Item = SignedSubmissionOf<T>> {
self.indices.clear();
SignedSubmissionNextIndex::<T>::kill();
self.next_idx = 0;
let insertion_overlay = sp_std::mem::take(&mut self.insertion_overlay);
SignedSubmissionsMap::<T>::drain()
.filter(move |(k, _v)| !self.deletion_overlay.contains(k))
Expand Down Expand Up @@ -255,6 +243,20 @@ impl<T: Config> Deref for SignedSubmissions<T> {
}
}

impl<T: Config> Drop for SignedSubmissions<T> {
fn drop(&mut self) {
SignedSubmissionIndices::<T>::put(sp_std::mem::take(&mut self.indices));
SignedSubmissionNextIndex::<T>::put(self.next_idx);

for key in self.deletion_overlay.iter().copied() {
SignedSubmissionsMap::<T>::remove(key);
}
for (key, value) in sp_std::mem::take(&mut self.insertion_overlay) {
SignedSubmissionsMap::<T>::insert(key, value);
}
}
}

impl<T: Config> Pallet<T> {
/// `Self` accessor for `SignedSubmission<T>`.
pub fn signed_submissions() -> SignedSubmissions<T> {
Expand Down Expand Up @@ -321,8 +323,6 @@ impl<T: Config> Pallet<T> {
debug_assert!(_remaining.is_zero());
}

all_submissions.put();

log!(debug, "closed signed phase, found solution? {}, discarded {}", found_solution, discarded);
(found_solution, weight)
}
Expand Down

0 comments on commit 3317a4b

Please sign in to comment.