3131include ! ( concat!( env!( "OUT_DIR" ) , "/wasm_binary.rs" ) ) ;
3232
3333pub mod rialto_messages;
34+ pub mod rialto_parachain_messages;
3435
3536use crate :: rialto_messages:: { ToRialtoMessagePayload , WithRialtoMessageBridge } ;
37+ use crate :: rialto_parachain_messages:: { ToRialtoParachainMessagePayload , WithRialtoParachainMessageBridge } ;
3638
3739use beefy_primitives:: { crypto:: AuthorityId as BeefyId , mmr:: MmrLeafVersion , ValidatorSet } ;
3840use bridge_runtime_common:: messages:: {
@@ -403,6 +405,16 @@ impl pallet_bridge_grandpa::Config<WestendGrandpaInstance> for Runtime {
403405 type WeightInfo = pallet_bridge_grandpa:: weights:: RialtoWeight < Runtime > ;
404406}
405407
408+ pub type RialtoParachainGrandpaInstance = pallet_bridge_grandpa:: Instance2 ;
409+ impl pallet_bridge_grandpa:: Config < RialtoParachainGrandpaInstance > for Runtime {
410+ type BridgedChain = bp_rialto_parachain:: RialtoParachain ;
411+ type MaxRequests = MaxRequests ;
412+ type HeadersToKeep = HeadersToKeep ;
413+
414+ // TODO [#391]: Use weights generated for the Millau runtime instead of Rialto ones.
415+ type WeightInfo = pallet_bridge_grandpa:: weights:: RialtoWeight < Runtime > ;
416+ }
417+
406418impl pallet_shift_session_manager:: Config for Runtime { }
407419
408420parameter_types ! {
@@ -416,6 +428,7 @@ parameter_types! {
416428 bp_millau:: MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT as _;
417429 pub const RootAccountForPayments : Option <AccountId > = None ;
418430 pub const RialtoChainId : bp_runtime:: ChainId = bp_runtime:: RIALTO_CHAIN_ID ;
431+ pub const RialtoParachainChainId : bp_runtime:: ChainId = bp_runtime:: RIALTO_PARACHAIN_CHAIN_ID ;
419432}
420433
421434/// Instance of the messages pallet used to relay messages to/from Rialto chain.
@@ -444,7 +457,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
444457 type MessageDeliveryAndDispatchPayment =
445458 pallet_bridge_messages:: instant_payments:: InstantCurrencyPayments <
446459 Runtime ,
447- ( ) ,
460+ WithRialtoMessagesInstance ,
448461 pallet_balances:: Pallet < Runtime > ,
449462 GetDeliveryConfirmationTransactionFee ,
450463 RootAccountForPayments ,
@@ -458,6 +471,45 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
458471 type BridgedChainId = RialtoChainId ;
459472}
460473
474+ /// Instance of the messages pallet used to relay messages to/from RialtoParachain chain.
475+ pub type WithRialtoParachainMessagesInstance = pallet_bridge_messages:: Instance1 ;
476+
477+ impl pallet_bridge_messages:: Config < WithRialtoParachainMessagesInstance > for Runtime {
478+ type Event = Event ;
479+ // TODO: https://github.com/paritytech/parity-bridges-common/issues/390
480+ type WeightInfo = pallet_bridge_messages:: weights:: RialtoWeight < Runtime > ;
481+ type Parameter = rialto_parachain_messages:: MillauToRialtoParachainMessagesParameter ;
482+ type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce ;
483+ type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane ;
484+ type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane ;
485+
486+ type OutboundPayload = crate :: rialto_parachain_messages:: ToRialtoParachainMessagePayload ;
487+ type OutboundMessageFee = Balance ;
488+
489+ type InboundPayload = crate :: rialto_parachain_messages:: FromRialtoParachainMessagePayload ;
490+ type InboundMessageFee = bp_rialto_parachain:: Balance ;
491+ type InboundRelayer = bp_rialto_parachain:: AccountId ;
492+
493+ type AccountIdConverter = bp_millau:: AccountIdConverter ;
494+
495+ type TargetHeaderChain = crate :: rialto_parachain_messages:: RialtoParachain ;
496+ type LaneMessageVerifier = crate :: rialto_parachain_messages:: ToRialtoParachainMessageVerifier ;
497+ type MessageDeliveryAndDispatchPayment =
498+ pallet_bridge_messages:: instant_payments:: InstantCurrencyPayments <
499+ Runtime ,
500+ WithRialtoParachainMessagesInstance ,
501+ pallet_balances:: Pallet < Runtime > ,
502+ GetDeliveryConfirmationTransactionFee ,
503+ RootAccountForPayments ,
504+ > ;
505+ type OnMessageAccepted = ( ) ;
506+ type OnDeliveryConfirmed = ( ) ;
507+
508+ type SourceHeaderChain = crate :: rialto_parachain_messages:: RialtoParachain ;
509+ type MessageDispatch = crate :: rialto_parachain_messages:: FromRialtoParachainMessageDispatch ;
510+ type BridgedChainId = RialtoParachainChainId ;
511+ }
512+
461513parameter_types ! {
462514 pub const TokenSwapMessagesLane : bp_messages:: LaneId = * b"swap" ;
463515}
@@ -531,8 +583,9 @@ construct_runtime!(
531583 // Westend bridge modules.
532584 BridgeWestendGrandpa : pallet_bridge_grandpa:: <Instance1 >:: { Pallet , Call , Config <T >, Storage } ,
533585
534- // Rialto parachains bridge modules.
586+ // RialtoParachain bridge modules.
535587 BridgeRialtoParachains : pallet_bridge_parachains:: { Pallet , Call , Storage } ,
588+ BridgeRialtoParachainMessages : pallet_bridge_messages:: <Instance1 >:: { Pallet , Call , Storage , Event <T >, Config <T >} ,
536589 }
537590) ;
538591
@@ -757,6 +810,22 @@ impl_runtime_apis! {
757810 }
758811 }
759812
813+ impl bp_rialto_parachain:: RialtoParachainFinalityApi <Block > for Runtime {
814+ fn best_finalized( ) -> ( bp_rialto:: BlockNumber , bp_rialto:: Hash ) {
815+ // TODO: this API should be removed in https://github.com/paritytech/parity-bridges-common/issues/1246
816+ // now let's hack something that will work
817+ use codec:: Decode ;
818+ use sp_runtime:: traits:: Header ;
819+ use crate :: rialto_parachain_messages:: RIALTO_PARACHAIN_ID ;
820+ let best_rialto_parachain_head = pallet_bridge_parachains:: Pallet :: <Runtime , WitRialtoParachainsInstance >:: best_parachain_head( RIALTO_PARACHAIN_ID . into( ) )
821+ . and_then( |encoded_header| bp_rialto_parachain:: Header :: decode( & mut & encoded_header. 0 [ ..] ) . ok( ) ) ;
822+ match best_rialto_parachain_head {
823+ Some ( head) => ( * head. number( ) , head. hash( ) ) ,
824+ None => ( Default :: default ( ) , Default :: default ( ) ) ,
825+ }
826+ }
827+ }
828+
760829 impl bp_rialto:: ToRialtoOutboundLaneApi <Block , Balance , ToRialtoMessagePayload > for Runtime {
761830 fn estimate_message_delivery_and_dispatch_fee(
762831 _lane_id: bp_messages:: LaneId ,
@@ -803,6 +872,52 @@ impl_runtime_apis! {
803872 }
804873 }
805874
875+ impl bp_rialto_parachain:: ToRialtoParachainOutboundLaneApi <Block , Balance , ToRialtoParachainMessagePayload > for Runtime {
876+ fn estimate_message_delivery_and_dispatch_fee(
877+ _lane_id: bp_messages:: LaneId ,
878+ payload: ToRialtoParachainMessagePayload ,
879+ ) -> Option <Balance > {
880+ estimate_message_dispatch_and_delivery_fee:: <WithRialtoParachainMessageBridge >(
881+ & payload,
882+ WithRialtoParachainMessageBridge :: RELAYER_FEE_PERCENT ,
883+ ) . ok( )
884+ }
885+
886+ fn message_details(
887+ lane: bp_messages:: LaneId ,
888+ begin: bp_messages:: MessageNonce ,
889+ end: bp_messages:: MessageNonce ,
890+ ) -> Vec <bp_messages:: MessageDetails <Balance >> {
891+ bridge_runtime_common:: messages_api:: outbound_message_details:: <
892+ Runtime ,
893+ WithRialtoParachainMessagesInstance ,
894+ WithRialtoParachainMessageBridge ,
895+ >( lane, begin, end)
896+ }
897+
898+ fn latest_received_nonce( lane: bp_messages:: LaneId ) -> bp_messages:: MessageNonce {
899+ BridgeRialtoParachainMessages :: outbound_latest_received_nonce( lane)
900+ }
901+
902+ fn latest_generated_nonce( lane: bp_messages:: LaneId ) -> bp_messages:: MessageNonce {
903+ BridgeRialtoParachainMessages :: outbound_latest_generated_nonce( lane)
904+ }
905+ }
906+
907+ impl bp_rialto_parachain:: FromRialtoParachainInboundLaneApi <Block > for Runtime {
908+ fn latest_received_nonce( lane: bp_messages:: LaneId ) -> bp_messages:: MessageNonce {
909+ BridgeRialtoParachainMessages :: inbound_latest_received_nonce( lane)
910+ }
911+
912+ fn latest_confirmed_nonce( lane: bp_messages:: LaneId ) -> bp_messages:: MessageNonce {
913+ BridgeRialtoParachainMessages :: inbound_latest_confirmed_nonce( lane)
914+ }
915+
916+ fn unrewarded_relayers_state( lane: bp_messages:: LaneId ) -> bp_messages:: UnrewardedRelayersState {
917+ BridgeRialtoParachainMessages :: inbound_unrewarded_relayers_state( lane)
918+ }
919+ }
920+
806921 #[ cfg( feature = "runtime-benchmarks" ) ]
807922 impl frame_benchmarking:: Benchmark <Block > for Runtime {
808923 fn benchmark_metadata( extra: bool ) -> (
@@ -889,6 +1004,30 @@ where
8891004 )
8901005}
8911006
1007+ /// RialtoParachain account ownership digest from Millau.
1008+ ///
1009+ /// The byte vector returned by this function should be signed with a RialtoParachain account private key.
1010+ /// This way, the owner of `millau_account_id` on Millau proves that the RialtoParachain account private key
1011+ /// is also under his control.
1012+ pub fn millau_to_rialto_parachain_account_ownership_digest < Call , AccountId , SpecVersion > (
1013+ rialto_parachain_call : & Call ,
1014+ millau_account_id : AccountId ,
1015+ rialto_spec_version : SpecVersion ,
1016+ ) -> sp_std:: vec:: Vec < u8 >
1017+ where
1018+ Call : codec:: Encode ,
1019+ AccountId : codec:: Encode ,
1020+ SpecVersion : codec:: Encode ,
1021+ {
1022+ pallet_bridge_dispatch:: account_ownership_digest (
1023+ rialto_parachain_call,
1024+ millau_account_id,
1025+ rialto_spec_version,
1026+ bp_runtime:: MILLAU_CHAIN_ID ,
1027+ bp_runtime:: RIALTO_PARACHAIN_CHAIN_ID ,
1028+ )
1029+ }
1030+
8921031#[ cfg( test) ]
8931032mod tests {
8941033 use super :: * ;
0 commit comments