@@ -13,8 +13,12 @@ use parity_scale_codec::{Decode, Encode};
1313use scale_info:: prelude:: fmt;
1414use sp_consensus_slots:: Slot ;
1515use sp_consensus_subspace:: SignedVote ;
16+ use sp_runtime:: Weight ;
1617use sp_runtime:: traits:: { AsSystemOriginSigner , Dispatchable , NumberFor } ;
17- use sp_runtime:: transaction_validity:: TransactionSource ;
18+ use sp_runtime:: transaction_validity:: {
19+ InvalidTransaction , TransactionSource , TransactionValidityError , UnknownTransaction ,
20+ ValidTransaction ,
21+ } ;
1822use sp_std:: collections:: btree_map:: BTreeMap ;
1923use subspace_core_primitives:: pieces:: PieceOffset ;
2024use subspace_core_primitives:: sectors:: SectorIndex ;
@@ -82,11 +86,14 @@ mod benchmarks {
8286 ( Option < T :: AccountId > , RewardSignature ) ,
8387 > :: default ( ) ) ;
8488
89+ let result;
8590 #[ block]
8691 {
87- SubspaceExtension :: < T > :: do_check_vote ( & signed_vote, TransactionSource :: InBlock )
88- . unwrap ( ) ;
89- }
92+ result =
93+ SubspaceExtension :: < T > :: do_check_vote ( & signed_vote, TransactionSource :: InBlock ) ;
94+ } ;
95+
96+ handle_error ( result) ;
9097 }
9198
9299 #[ benchmark]
@@ -132,11 +139,15 @@ mod benchmarks {
132139 * signed_vote. vote . slot ( ) ,
133140 Some ( reward_address) ,
134141 ) ) ;
142+
143+ let result;
135144 #[ block]
136145 {
137- SubspaceExtension :: < T > :: do_check_vote ( & signed_vote, TransactionSource :: InBlock )
138- . unwrap ( ) ;
139- }
146+ result =
147+ SubspaceExtension :: < T > :: do_check_vote ( & signed_vote, TransactionSource :: InBlock ) ;
148+ } ;
149+
150+ handle_error ( result) ;
140151 }
141152
142153 impl_benchmark_test_suite ! (
@@ -145,3 +156,65 @@ mod benchmarks {
145156 crate :: mock:: Test
146157 ) ;
147158}
159+
160+ fn handle_error ( result : Result < ( ValidTransaction , Weight ) , TransactionValidityError > ) {
161+ // This exhaustive match is required because the production runtime does not generate debug impls.
162+ if let Err ( e) = result {
163+ match e {
164+ TransactionValidityError :: Invalid ( e) => match e {
165+ InvalidTransaction :: Call => {
166+ log:: error!( "Invalid transaction: Call" ) ;
167+ }
168+ InvalidTransaction :: Payment => {
169+ log:: error!( "Invalid transaction: Payment" ) ;
170+ panic ! ( "Invalid transaction: Payment" ) ;
171+ }
172+ InvalidTransaction :: Future => {
173+ log:: error!( "Invalid transaction: Future" ) ;
174+ }
175+ InvalidTransaction :: Stale => {
176+ log:: error!( "Invalid transaction: Stale" ) ;
177+ }
178+ InvalidTransaction :: BadProof => {
179+ log:: error!( "Invalid transaction: BadProof" ) ;
180+ }
181+ InvalidTransaction :: AncientBirthBlock => {
182+ log:: error!( "Invalid transaction: AncientBirthBlock" ) ;
183+ }
184+ InvalidTransaction :: ExhaustsResources => {
185+ log:: error!( "Invalid transaction: ExhaustsResources" ) ;
186+ }
187+ InvalidTransaction :: Custom ( e) => {
188+ log:: error!( "Invalid transaction: Custom({})" , e) ;
189+ }
190+ InvalidTransaction :: BadMandatory => {
191+ log:: error!( "Invalid transaction: BadMandatory" ) ;
192+ }
193+ InvalidTransaction :: MandatoryValidation => {
194+ log:: error!( "Invalid transaction: MandatoryValidation" ) ;
195+ }
196+ InvalidTransaction :: BadSigner => {
197+ log:: error!( "Invalid transaction: BadSigner" ) ;
198+ }
199+ InvalidTransaction :: IndeterminateImplicit => {
200+ log:: error!( "Invalid transaction: IndeterminateImplicit" ) ;
201+ }
202+ InvalidTransaction :: UnknownOrigin => {
203+ log:: error!( "Invalid transaction: UnknownOrigin" ) ;
204+ }
205+ } ,
206+ TransactionValidityError :: Unknown ( e) => match e {
207+ UnknownTransaction :: CannotLookup => {
208+ log:: error!( "Unknown transaction: CannotLookup" ) ;
209+ }
210+ UnknownTransaction :: NoUnsignedValidator => {
211+ log:: error!( "Unknown transaction: NoUnsignedValidator" ) ;
212+ }
213+ UnknownTransaction :: Custom ( e) => {
214+ log:: error!( "Unknown transaction: Custom({})" , e) ;
215+ }
216+ } ,
217+ }
218+ panic ! ( "Error: {e:?}" ) ;
219+ }
220+ }
0 commit comments