@@ -51,8 +51,6 @@ pub mod weights;
5151pub mod weights_ext;
5252
5353pub use weights:: WeightInfo ;
54- #[ cfg( feature = "std" ) ]
55- pub use weights_ext:: check_weight_info_ext_accuracy;
5654pub use weights_ext:: WeightInfoExt ;
5755
5856extern crate alloc;
@@ -68,8 +66,8 @@ use cumulus_primitives_core::{
6866use frame_support:: {
6967 defensive, defensive_assert,
7068 traits:: {
71- BatchFootprint , Defensive , EnqueueMessage , EnsureOrigin , Get , QueueFootprint ,
72- QueueFootprintQuery , QueuePausedQuery ,
69+ Defensive , EnqueueMessage , EnsureOrigin , Get , QueueFootprint , QueueFootprintQuery ,
70+ QueuePausedQuery ,
7371 } ,
7472 weights:: { Weight , WeightMeter } ,
7573 BoundedVec ,
@@ -79,7 +77,7 @@ use polkadot_runtime_common::xcm_sender::PriceForMessageDelivery;
7977use polkadot_runtime_parachains:: { FeeTracker , GetMinFeeFactor } ;
8078use scale_info:: TypeInfo ;
8179use sp_core:: MAX_POSSIBLE_ALLOCATION ;
82- use sp_runtime:: { FixedU128 , RuntimeDebug , WeakBoundedVec } ;
80+ use sp_runtime:: { FixedU128 , RuntimeDebug , SaturatedConversion , WeakBoundedVec } ;
8381use xcm:: { latest:: prelude:: * , VersionedLocation , VersionedXcm , WrapVersion , MAX_XCM_DECODE_DEPTH } ;
8482use xcm_builder:: InspectMessageQueues ;
8583use xcm_executor:: traits:: ConvertOrigin ;
@@ -264,9 +262,13 @@ pub mod pallet {
264262 #[ pallet:: hooks]
265263 impl < T : Config > Hooks < BlockNumberFor < T > > for Pallet < T > {
266264 fn integrity_test ( ) {
265+ assert ! ( !T :: MaxPageSize :: get( ) . is_zero( ) , "MaxPageSize too low" ) ;
266+
267267 let w = Self :: on_idle_weight ( ) ;
268268 assert ! ( w != Weight :: zero( ) ) ;
269269 assert ! ( w. all_lte( T :: BlockWeights :: get( ) . max_block) ) ;
270+
271+ <T :: WeightInfo as WeightInfoExt >:: check_accuracy :: < MaxXcmpMessageLenOf < T > > ( 0.15 ) ;
270272 }
271273
272274 fn on_idle ( _block : BlockNumberFor < T > , limit : Weight ) -> Weight {
@@ -643,39 +645,21 @@ impl<T: Config> Pallet<T> {
643645 drop_threshold,
644646 ) ;
645647
646- // `batches_footprints[n]` contains the footprint of the batch `xcms[0..n]`,
647- // so as `n` increases `batches_footprints[n]` contains the footprint of a bigger batch.
648- let best_batch_idx = batches_footprints. binary_search_by ( |batch_info| {
648+ let best_batch_footprint = batches_footprints. search_best_by ( |batch_info| {
649649 let required_weight = T :: WeightInfo :: enqueue_xcmp_messages (
650- batch_info. new_pages_count ,
651- batch_info. msgs_count ,
652- batch_info. size_in_bytes ,
650+ batches_footprints. first_page_pos . saturated_into ( ) ,
651+ batch_info,
653652 ) ;
654653
655654 match meter. can_consume ( required_weight) {
656655 true => core:: cmp:: Ordering :: Less ,
657656 false => core:: cmp:: Ordering :: Greater ,
658657 }
659658 } ) ;
660- let best_batch_idx = match best_batch_idx {
661- Ok ( last_ok_idx) => {
662- // We should never reach this branch since we never return `Ordering::Equal`.
663- defensive ! ( "Unexpected best_batch_idx found: Ok({})" , last_ok_idx) ;
664- Some ( last_ok_idx)
665- } ,
666- Err ( first_err_idx) => first_err_idx. checked_sub ( 1 ) ,
667- } ;
668- let best_batch_footprint = match best_batch_idx {
669- Some ( best_batch_idx) => batches_footprints. get ( best_batch_idx) . ok_or_else ( || {
670- defensive ! ( "Invalid best_batch_idx: {}" , best_batch_idx) ;
671- } ) ?,
672- None => & BatchFootprint { msgs_count : 0 , size_in_bytes : 0 , new_pages_count : 0 } ,
673- } ;
674659
675660 meter. consume ( T :: WeightInfo :: enqueue_xcmp_messages (
676- best_batch_footprint. new_pages_count ,
677- best_batch_footprint. msgs_count ,
678- best_batch_footprint. size_in_bytes ,
661+ batches_footprints. first_page_pos . saturated_into ( ) ,
662+ best_batch_footprint,
679663 ) ) ;
680664 T :: XcmpQueue :: enqueue_messages (
681665 xcms. iter ( )
0 commit comments