1515// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616
1717use crate :: {
18- configuration, inclusion, initializer, paras, paras:: ParaKind , paras_inherent, scheduler,
19- session_info, shared,
18+ configuration,
19+ hrmp:: { HrmpChannel , HrmpChannels } ,
20+ inclusion, initializer, paras,
21+ paras:: ParaKind ,
22+ paras_inherent, scheduler, session_info, shared,
2023} ;
2124use bitvec:: { order:: Lsb0 as BitOrderLsb0 , vec:: BitVec } ;
2225use frame_support:: pallet_prelude:: * ;
2326use primitives:: {
2427 collator_signature_payload, AvailabilityBitfield , BackedCandidate , CandidateCommitments ,
2528 CandidateDescriptor , CandidateHash , CollatorId , CollatorSignature , CommittedCandidateReceipt ,
2629 CompactStatement , CoreIndex , CoreOccupied , DisputeStatement , DisputeStatementSet , GroupIndex ,
27- HeadData , Id as ParaId , IndexedVec , InherentData as ParachainsInherentData ,
30+ HeadData , HrmpChannelId , Id as ParaId , IndexedVec , InherentData as ParachainsInherentData ,
2831 InvalidDisputeStatementKind , OutboundHrmpMessage , PersistedValidationData , SessionIndex ,
2932 SigningContext , UncheckedSigned , ValidDisputeStatementKind , ValidationCode , ValidatorId ,
3033 ValidatorIndex , ValidityAttestation ,
@@ -520,7 +523,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
520523 para_head : head_data. hash ( ) ,
521524 validation_code_hash,
522525 } ,
523- commitments : self . create_candidate_commitments ( head_data, scenario) ,
526+ commitments : self . create_candidate_commitments ( para_id , head_data, scenario) ,
524527 } ;
525528
526529 let candidate_hash = candidate. hash ( ) ;
@@ -615,6 +618,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
615618
616619 fn create_candidate_commitments (
617620 & self ,
621+ para_id : ParaId ,
618622 head_data : HeadData ,
619623 scenario : & BackedCandidateScenario ,
620624 ) -> CandidateCommitments {
@@ -631,13 +635,39 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
631635 } ;
632636
633637 let horizontal_messages = {
634- let unbounded = create_messages (
638+ let unbounded: Vec < _ > = create_messages (
635639 scenario. hrmp ,
636640 config. hrmp_channel_max_message_size ,
637641 config. hrmp_max_message_num_per_candidate ,
638642 )
639- . map ( |m| OutboundHrmpMessage { recipient : Default :: default ( ) , data : m. collect ( ) } )
640643 . collect ( ) ;
644+
645+ for n in 0 ..unbounded. len ( ) {
646+ let channel_id =
647+ HrmpChannelId { sender : para_id, recipient : para_id + n as u32 + 1 } ;
648+ HrmpChannels :: < T > :: insert (
649+ & channel_id,
650+ HrmpChannel {
651+ sender_deposit : 42 ,
652+ recipient_deposit : 42 ,
653+ max_capacity : 10_000_000 ,
654+ max_total_size : 1_000_000_000 ,
655+ max_message_size : 10_000_000 ,
656+ msg_count : 0 ,
657+ total_size : 0 ,
658+ mqc_head : None ,
659+ } ,
660+ ) ;
661+ }
662+
663+ let unbounded = unbounded
664+ . into_iter ( )
665+ . enumerate ( )
666+ . map ( |( n, m) | OutboundHrmpMessage {
667+ recipient : para_id + n as u32 + 1 ,
668+ data : m. collect ( ) ,
669+ } )
670+ . collect ( ) ;
641671 BoundedVec :: truncate_from ( unbounded)
642672 } ;
643673
@@ -732,18 +762,18 @@ fn create_messages(
732762 let max_message_size = if max_message_size == 0 { num_bytes } else { max_message_size } ;
733763 let num_full_messages = if num_bytes == 0 { 0 } else { num_bytes / max_message_size } ;
734764 let last_message_size = if num_bytes == 0 { 0 } else { num_bytes % max_message_size } ;
765+ let last_message =
766+ if last_message_size == 0 { vec ! [ ] } else { vec ! [ ( 0 ..last_message_size) . map( as_byte) ] } ;
767+
735768 assert ! (
736- max_messages == 0 || num_full_messages + 1 <= max_messages,
737- "Too many messages generated!"
769+ max_messages == 0 || num_full_messages + last_message . len ( ) as u32 <= max_messages,
770+ "Too many messages generated. max_messages: {}, num_full_messages: {}, num_bytes: {}, max_message_size: {}, last_message_size: {}" , max_messages , num_full_messages , num_bytes , max_message_size , last_message_size ,
738771 ) ;
739772
740773 fn as_byte ( u : u32 ) -> u8 {
741774 u as u8
742775 }
743776
744- let last_message =
745- if last_message_size == 0 { vec ! [ ] } else { vec ! [ ( 0 ..last_message_size) . map( as_byte) ] } ;
746-
747777 ( 0 ..num_full_messages)
748778 . map ( move |_| ( 0 ..max_message_size) . map ( as_byte) )
749779 . chain ( last_message)
0 commit comments