1515// See the License for the specific language governing permissions and
1616// limitations under the License.
1717
18- use crate :: { limits:: BlockWeights , Config , Pallet } ;
18+ use crate :: { limits:: BlockWeights , Config , Pallet , LOG_TARGET } ;
1919use codec:: { Decode , Encode } ;
2020use frame_support:: {
2121 dispatch:: { DispatchInfo , PostDispatchInfo } ,
5050 ) -> Result < ( ) , TransactionValidityError > {
5151 let max = T :: BlockWeights :: get ( ) . get ( info. class ) . max_extrinsic ;
5252 match max {
53- Some ( max) if info. weight . any_gt ( max) =>
54- Err ( InvalidTransaction :: ExhaustsResources . into ( ) ) ,
53+ Some ( max) if info. weight . any_gt ( max) => {
54+ log:: debug!(
55+ target: LOG_TARGET ,
56+ "Extrinsic {} is greater than the max extrinsic {}" ,
57+ info. weight,
58+ max,
59+ ) ;
60+
61+ Err ( InvalidTransaction :: ExhaustsResources . into ( ) )
62+ } ,
5563 _ => Ok ( ( ) ) ,
5664 }
5765 }
7987 let added_len = len as u32 ;
8088 let next_len = current_len. saturating_add ( added_len) ;
8189 if next_len > * length_limit. max . get ( info. class ) {
90+ log:: debug!(
91+ target: LOG_TARGET ,
92+ "Exceeded block length limit: {} > {}" ,
93+ next_len,
94+ length_limit. max. get( info. class) ,
95+ ) ;
96+
8297 Err ( InvalidTransaction :: ExhaustsResources . into ( ) )
8398 } else {
8499 Ok ( next_len)
@@ -137,17 +152,28 @@ where
137152 if limit_per_class. max_total . is_none ( ) && limit_per_class. reserved . is_none ( ) {
138153 all_weight. accrue ( extrinsic_weight, info. class )
139154 } else {
140- all_weight
141- . checked_accrue ( extrinsic_weight, info. class )
142- . map_err ( |_| InvalidTransaction :: ExhaustsResources ) ?;
155+ all_weight. checked_accrue ( extrinsic_weight, info. class ) . map_err ( |_| {
156+ log:: debug!(
157+ target: LOG_TARGET ,
158+ "All weight checked add overflow." ,
159+ ) ;
160+
161+ InvalidTransaction :: ExhaustsResources
162+ } ) ?;
143163 }
144164
145165 let per_class = * all_weight. get ( info. class ) ;
146166
147167 // Check if we don't exceed per-class allowance
148168 match limit_per_class. max_total {
149- Some ( max) if per_class. any_gt ( max) =>
150- return Err ( InvalidTransaction :: ExhaustsResources . into ( ) ) ,
169+ Some ( max) if per_class. any_gt ( max) => {
170+ log:: debug!(
171+ target: LOG_TARGET ,
172+ "Exceeded the per-class allowance." ,
173+ ) ;
174+
175+ return Err ( InvalidTransaction :: ExhaustsResources . into ( ) )
176+ } ,
151177 // There is no `max_total` limit (`None`),
152178 // or we are below the limit.
153179 _ => { } ,
@@ -158,8 +184,14 @@ where
158184 if all_weight. total ( ) . any_gt ( maximum_weight. max_block ) {
159185 match limit_per_class. reserved {
160186 // We are over the limit in reserved pool.
161- Some ( reserved) if per_class. any_gt ( reserved) =>
162- return Err ( InvalidTransaction :: ExhaustsResources . into ( ) ) ,
187+ Some ( reserved) if per_class. any_gt ( reserved) => {
188+ log:: debug!(
189+ target: LOG_TARGET ,
190+ "Total block weight is exceeded." ,
191+ ) ;
192+
193+ return Err ( InvalidTransaction :: ExhaustsResources . into ( ) )
194+ } ,
163195 // There is either no limit in reserved pool (`None`),
164196 // or we are below the limit.
165197 _ => { } ,
@@ -233,6 +265,18 @@ where
233265 } )
234266 }
235267
268+ log:: trace!(
269+ target: LOG_TARGET ,
270+ "Used block weight: {:?}" ,
271+ crate :: BlockWeight :: <T >:: get( ) ,
272+ ) ;
273+
274+ log:: trace!(
275+ target: LOG_TARGET ,
276+ "Used block length: {:?}" ,
277+ Pallet :: <T >:: all_extrinsics_len( ) ,
278+ ) ;
279+
236280 Ok ( ( ) )
237281 }
238282}
0 commit comments