@@ -766,68 +766,6 @@ pub mod pallet {
766
766
767
767
#[ pallet:: call]
768
768
impl < T : Config > Pallet < T > {
769
- /// Submit a solution for the signed phase.
770
- ///
771
- /// The dispatch origin fo this call must be __signed__.
772
- ///
773
- /// The solution is potentially queued, based on the claimed score and processed at the end
774
- /// of the signed phase.
775
- ///
776
- /// A deposit is reserved and recorded for the solution. Based on the outcome, the solution
777
- /// might be rewarded, slashed, or get all or a part of the deposit back.
778
- ///
779
- /// # <weight>
780
- /// Queue size must be provided as witness data.
781
- /// # </weight>
782
- #[ pallet:: weight( T :: WeightInfo :: submit( * num_signed_submissions) ) ]
783
- pub fn submit (
784
- origin : OriginFor < T > ,
785
- solution : RawSolution < CompactOf < T > > ,
786
- num_signed_submissions : u32 ,
787
- ) -> DispatchResult {
788
- let who = ensure_signed ( origin) ?;
789
-
790
- // ensure witness data is correct.
791
- ensure ! (
792
- num_signed_submissions >= <SignedSubmissions <T >>:: decode_len( ) . unwrap_or_default( ) as u32 ,
793
- Error :: <T >:: SignedInvalidWitness ,
794
- ) ;
795
-
796
- // ensure solution is timely.
797
- ensure ! ( Self :: current_phase( ) . is_signed( ) , Error :: <T >:: PreDispatchEarlySubmission ) ;
798
-
799
- // NOTE: this is the only case where having separate snapshot would have been better
800
- // because could do just decode_len. But we can create abstractions to do this.
801
-
802
- // build size. Note: this is not needed for weight calc, thus not input.
803
- // unlikely to ever return an error: if phase is signed, snapshot will exist.
804
- let size = Self :: snapshot_metadata ( ) . ok_or ( Error :: < T > :: MissingSnapshotMetadata ) ?;
805
-
806
- ensure ! (
807
- Self :: feasibility_weight_of( & solution, size) < T :: SignedMaxWeight :: get( ) ,
808
- Error :: <T >:: SignedTooMuchWeight ,
809
- ) ;
810
-
811
- // ensure solution claims is better.
812
- let mut signed_submissions = Self :: signed_submissions ( ) ;
813
- let ejected_a_solution = signed_submissions. len ( )
814
- == T :: SignedMaxSubmissions :: get ( ) . saturated_into :: < usize > ( ) ;
815
- let index = Self :: insert_submission ( & who, & mut signed_submissions, solution, size)
816
- . ok_or ( Error :: < T > :: SignedQueueFull ) ?;
817
-
818
- // collect deposit. Thereafter, the function cannot fail.
819
- let deposit = signed_submissions
820
- . get ( index)
821
- . map ( |s| s. deposit )
822
- . ok_or ( Error :: < T > :: InvalidSubmissionIndex ) ?;
823
- T :: Currency :: reserve ( & who, deposit) . map_err ( |_| Error :: < T > :: SignedCannotPayDeposit ) ?;
824
-
825
- // store the new signed submission.
826
- <SignedSubmissions < T > >:: put ( signed_submissions) ;
827
- Self :: deposit_event ( Event :: SolutionStored ( ElectionCompute :: Signed , ejected_a_solution) ) ;
828
- Ok ( ( ) )
829
- }
830
-
831
769
/// Submit a solution for the unsigned phase.
832
770
///
833
771
/// The dispatch origin fo this call must be __none__.
@@ -898,6 +836,68 @@ pub mod pallet {
898
836
<MinimumUntrustedScore < T > >:: set ( maybe_next_score) ;
899
837
Ok ( ( ) )
900
838
}
839
+
840
+ /// Submit a solution for the signed phase.
841
+ ///
842
+ /// The dispatch origin fo this call must be __signed__.
843
+ ///
844
+ /// The solution is potentially queued, based on the claimed score and processed at the end
845
+ /// of the signed phase.
846
+ ///
847
+ /// A deposit is reserved and recorded for the solution. Based on the outcome, the solution
848
+ /// might be rewarded, slashed, or get all or a part of the deposit back.
849
+ ///
850
+ /// # <weight>
851
+ /// Queue size must be provided as witness data.
852
+ /// # </weight>
853
+ #[ pallet:: weight( T :: WeightInfo :: submit( * num_signed_submissions) ) ]
854
+ pub fn submit (
855
+ origin : OriginFor < T > ,
856
+ solution : RawSolution < CompactOf < T > > ,
857
+ num_signed_submissions : u32 ,
858
+ ) -> DispatchResult {
859
+ let who = ensure_signed ( origin) ?;
860
+
861
+ // ensure witness data is correct.
862
+ ensure ! (
863
+ num_signed_submissions >= <SignedSubmissions <T >>:: decode_len( ) . unwrap_or_default( ) as u32 ,
864
+ Error :: <T >:: SignedInvalidWitness ,
865
+ ) ;
866
+
867
+ // ensure solution is timely.
868
+ ensure ! ( Self :: current_phase( ) . is_signed( ) , Error :: <T >:: PreDispatchEarlySubmission ) ;
869
+
870
+ // NOTE: this is the only case where having separate snapshot would have been better
871
+ // because could do just decode_len. But we can create abstractions to do this.
872
+
873
+ // build size. Note: this is not needed for weight calc, thus not input.
874
+ // unlikely to ever return an error: if phase is signed, snapshot will exist.
875
+ let size = Self :: snapshot_metadata ( ) . ok_or ( Error :: < T > :: MissingSnapshotMetadata ) ?;
876
+
877
+ ensure ! (
878
+ Self :: feasibility_weight_of( & solution, size) < T :: SignedMaxWeight :: get( ) ,
879
+ Error :: <T >:: SignedTooMuchWeight ,
880
+ ) ;
881
+
882
+ // ensure solution claims is better.
883
+ let mut signed_submissions = Self :: signed_submissions ( ) ;
884
+ let ejected_a_solution = signed_submissions. len ( )
885
+ == T :: SignedMaxSubmissions :: get ( ) . saturated_into :: < usize > ( ) ;
886
+ let index = Self :: insert_submission ( & who, & mut signed_submissions, solution, size)
887
+ . ok_or ( Error :: < T > :: SignedQueueFull ) ?;
888
+
889
+ // collect deposit. Thereafter, the function cannot fail.
890
+ let deposit = signed_submissions
891
+ . get ( index)
892
+ . map ( |s| s. deposit )
893
+ . ok_or ( Error :: < T > :: InvalidSubmissionIndex ) ?;
894
+ T :: Currency :: reserve ( & who, deposit) . map_err ( |_| Error :: < T > :: SignedCannotPayDeposit ) ?;
895
+
896
+ // store the new signed submission.
897
+ <SignedSubmissions < T > >:: put ( signed_submissions) ;
898
+ Self :: deposit_event ( Event :: SolutionStored ( ElectionCompute :: Signed , ejected_a_solution) ) ;
899
+ Ok ( ( ) )
900
+ }
901
901
}
902
902
903
903
#[ pallet:: event]
0 commit comments