@@ -22,8 +22,8 @@ use sp_api::{ApiExt, ApiRef, ProvideRuntimeApi};
2222use sp_core:: H256 ;
2323use sp_domains:: { ChannelId , DomainsApi } ;
2424use sp_messenger:: messages:: {
25- BlockMessageWithStorageKey , BlockMessagesQuery , BlockMessagesWithStorageKey , ChainId ,
26- ChannelState , ChannelStateWithNonce , CrossDomainMessage , Nonce , Proof ,
25+ BlockMessagesQuery , ChainId , ChannelState , ChannelStateWithNonce , CrossDomainMessage ,
26+ MessageNonceWithStorageKey , MessagesWithStorageKey , Nonce , Proof ,
2727} ;
2828use sp_messenger:: { MessengerApi , RelayerApi } ;
2929use sp_mmr_primitives:: MmrApi ;
@@ -148,29 +148,36 @@ where
148148}
149149
150150fn construct_cross_chain_message_and_submit < CNumber , CHash , Submitter , ProofConstructor > (
151- msgs : Vec < BlockMessageWithStorageKey > ,
151+ msgs : ( ChainId , ChainId , ChannelId , Vec < MessageNonceWithStorageKey > ) ,
152152 proof_constructor : ProofConstructor ,
153153 submitter : Submitter ,
154154) -> Result < ( ) , Error >
155155where
156156 Submitter : Fn ( CrossDomainMessage < CNumber , CHash , H256 > ) -> Result < ( ) , Error > ,
157157 ProofConstructor : Fn ( & [ u8 ] , ChainId ) -> Result < Proof < CNumber , CHash , H256 > , Error > ,
158158{
159+ let ( src_chain_id, dst_chain_id, channel_id, msgs) = msgs;
159160 for msg in msgs {
160- let proof = match proof_constructor ( & msg. storage_key , msg . dst_chain_id ) {
161+ let proof = match proof_constructor ( & msg. storage_key , dst_chain_id) {
161162 Ok ( proof) => proof,
162163 Err ( err) => {
163164 tracing:: error!(
164165 target: LOG_TARGET ,
165166 "Failed to construct storage proof for message: {:?} bound to chain: {:?} with error: {:?}" ,
166- ( msg . channel_id, msg. nonce) ,
167- msg . dst_chain_id,
167+ ( channel_id, msg. nonce) ,
168+ dst_chain_id,
168169 err
169170 ) ;
170171 continue ;
171172 }
172173 } ;
173- let msg = CrossDomainMessage :: from_relayer_msg_with_proof ( msg, proof) ;
174+ let msg = CrossDomainMessage :: from_relayer_msg_with_proof (
175+ src_chain_id,
176+ dst_chain_id,
177+ channel_id,
178+ msg,
179+ proof,
180+ ) ;
174181 let ( dst_domain, msg_id) = ( msg. dst_chain_id , ( msg. channel_id , msg. nonce ) ) ;
175182 if let Err ( err) = submitter ( msg) {
176183 tracing:: error!(
@@ -246,7 +253,7 @@ fn fetch_and_filter_messages<Client, Block, CClient, CBlock>(
246253 fetch_message_at : Block :: Hash ,
247254 consensus_client : & Arc < CClient > ,
248255 self_chain_id : ChainId ,
249- ) -> Result < BlockMessagesWithStorageKey , Error >
256+ ) -> Result < Vec < ( ChainId , ChannelId , MessagesWithStorageKey ) > , Error >
250257where
251258 CBlock : BlockT ,
252259 CClient : AuxStore + HeaderBackend < CBlock > ,
@@ -256,7 +263,7 @@ where
256263{
257264 // return no messages for previous relayer version
258265 if !is_relayer_api_version_available :: < _ , Block , CBlock > ( client, 3 , fetch_message_at) {
259- return Ok ( BlockMessagesWithStorageKey :: default ( ) ) ;
266+ return Ok ( vec ! [ ] ) ;
260267 }
261268
262269 fetch_messages :: < _ , _ , Block , CBlock > (
@@ -379,35 +386,37 @@ where
379386 }
380387 } ;
381388
382- construct_cross_chain_message_and_submit :: < NumberFor < CBlock > , CBlock :: Hash , _ , _ > (
383- block_messages. outbox ,
384- |key, dst_chain_id| {
385- Self :: construct_xdm_proof (
386- consensus_chain_client,
387- domain_client,
388- dst_chain_id,
389- mmr_consensus_block,
390- key,
391- xdm_proof_data. clone ( ) ,
392- )
393- } ,
394- |msg| gossip_outbox_message ( domain_client, msg, gossip_message_sink) ,
395- ) ?;
396-
397- construct_cross_chain_message_and_submit :: < NumberFor < CBlock > , CBlock :: Hash , _ , _ > (
398- block_messages. inbox_responses ,
399- |key, dst_chain_id| {
400- Self :: construct_xdm_proof (
401- consensus_chain_client,
402- domain_client,
403- dst_chain_id,
404- mmr_consensus_block,
405- key,
406- xdm_proof_data. clone ( ) ,
407- )
408- } ,
409- |msg| gossip_inbox_message_response ( domain_client, msg, gossip_message_sink) ,
410- ) ?;
389+ for ( dst_chain_id, channel_id, messages) in block_messages {
390+ construct_cross_chain_message_and_submit :: < NumberFor < CBlock > , CBlock :: Hash , _ , _ > (
391+ ( chain_id, dst_chain_id, channel_id, messages. outbox ) ,
392+ |key, dst_chain_id| {
393+ Self :: construct_xdm_proof (
394+ consensus_chain_client,
395+ domain_client,
396+ dst_chain_id,
397+ mmr_consensus_block,
398+ key,
399+ xdm_proof_data. clone ( ) ,
400+ )
401+ } ,
402+ |msg| gossip_outbox_message ( domain_client, msg, gossip_message_sink) ,
403+ ) ?;
404+
405+ construct_cross_chain_message_and_submit :: < NumberFor < CBlock > , CBlock :: Hash , _ , _ > (
406+ ( chain_id, dst_chain_id, channel_id, messages. inbox_responses ) ,
407+ |key, dst_chain_id| {
408+ Self :: construct_xdm_proof (
409+ consensus_chain_client,
410+ domain_client,
411+ dst_chain_id,
412+ mmr_consensus_block,
413+ key,
414+ xdm_proof_data. clone ( ) ,
415+ )
416+ } ,
417+ |msg| gossip_inbox_message_response ( domain_client, msg, gossip_message_sink) ,
418+ ) ?;
419+ }
411420
412421 Ok ( ( ) )
413422 }
@@ -471,7 +480,7 @@ fn filter_block_messages<Client, Block, CBlock>(
471480 api : & ApiRef < ' _ , Client :: Api > ,
472481 best_hash : Block :: Hash ,
473482 query : BlockMessagesQuery ,
474- messages : & mut BlockMessagesWithStorageKey ,
483+ messages : & mut MessagesWithStorageKey ,
475484) -> Result < ( ) , Error >
476485where
477486 Block : BlockT ,
@@ -486,8 +495,8 @@ where
486495 inbox_responses_from,
487496 } = query;
488497 let maybe_outbox_nonce =
489- api. should_relay_outbox_messages ( best_hash, chain_id, channel_id, outbox_from) ?;
490- let maybe_inbox_response_nonce = api. should_relay_inbox_message_responses (
498+ api. first_outbox_message_nonce_to_relay ( best_hash, chain_id, channel_id, outbox_from) ?;
499+ let maybe_inbox_response_nonce = api. first_inbox_message_response_nonce_to_relay (
491500 best_hash,
492501 chain_id,
493502 channel_id,
@@ -515,7 +524,7 @@ fn fetch_messages<Backend, Client, Block, CBlock>(
515524 client : & Arc < Client > ,
516525 fetch_message_at : Block :: Hash ,
517526 self_chain_id : ChainId ,
518- ) -> Result < BlockMessagesWithStorageKey , Error >
527+ ) -> Result < Vec < ( ChainId , ChannelId , MessagesWithStorageKey ) > , Error >
519528where
520529 Block : BlockT ,
521530 CBlock : BlockT ,
@@ -612,16 +621,9 @@ where
612621 . ok ( ) ?;
613622 }
614623
615- Some ( messages)
624+ Some ( ( dst_chain_id , channel_id , messages) )
616625 } )
617- . fold (
618- BlockMessagesWithStorageKey :: default ( ) ,
619- |mut acc, mut messages| {
620- acc. outbox . append ( & mut messages. outbox ) ;
621- acc. inbox_responses . append ( & mut messages. inbox_responses ) ;
622- acc
623- } ,
624- ) ;
626+ . collect ( ) ;
625627
626628 Ok ( total_messages)
627629}
0 commit comments