@@ -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+
258260impl < 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