@@ -73,8 +73,14 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
7373use weights:: { BlockExecutionWeight , ExtrinsicBaseWeight , RocksDbWeight } ;
7474
7575use crate :: {
76- bridge_hub_rococo_config:: { OnBridgeHubRococoBlobDispatcher , WithBridgeHubWococoMessageBridge } ,
77- bridge_hub_wococo_config:: { OnBridgeHubWococoBlobDispatcher , WithBridgeHubRococoMessageBridge } ,
76+ bridge_hub_rococo_config:: {
77+ BridgeRefundBridgeHubWococoMessages , OnBridgeHubRococoBlobDispatcher ,
78+ WithBridgeHubWococoMessageBridge ,
79+ } ,
80+ bridge_hub_wococo_config:: {
81+ BridgeRefundBridgeHubRococoMessages , OnBridgeHubWococoBlobDispatcher ,
82+ WithBridgeHubRococoMessageBridge ,
83+ } ,
7884 constants:: fee:: WeightToFee ,
7985 xcm_config:: XcmRouter ,
8086} ;
@@ -113,6 +119,7 @@ pub type SignedExtra = (
113119 frame_system:: CheckWeight < Runtime > ,
114120 pallet_transaction_payment:: ChargeTransactionPayment < Runtime > ,
115121 BridgeRejectObsoleteHeadersAndMessages ,
122+ ( BridgeRefundBridgeHubRococoMessages , BridgeRefundBridgeHubWococoMessages ) ,
116123) ;
117124
118125/// Unchecked extrinsic type as expected by this runtime.
@@ -398,7 +405,7 @@ impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> for Runtime {
398405 type WeightInfo = weights:: pallet_bridge_grandpa_bridge_wococo_grandpa:: WeightInfo < Runtime > ;
399406}
400407
401- /// Add granda bridge pallet to track Rococo relay chain
408+ /// Add granda bridge pallet to track Rococo relay chain on Wococo BridgeHub
402409pub type BridgeGrandpaRococoInstance = pallet_bridge_grandpa:: Instance2 ;
403410impl pallet_bridge_grandpa:: Config < BridgeGrandpaRococoInstance > for Runtime {
404411 type BridgedChain = bp_rococo:: Rococo ;
@@ -407,17 +414,19 @@ impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> for Runtime {
407414 type WeightInfo = weights:: pallet_bridge_grandpa_bridge_rococo_grandpa:: WeightInfo < Runtime > ;
408415}
409416
410- pub const ROCOCO_BRIDGE_PARA_PALLET_NAME : & str = "Paras" ;
411- pub const WOCOCO_BRIDGE_PARA_PALLET_NAME : & str = "Paras" ;
412417parameter_types ! {
413418 pub const RelayChainHeadersToKeep : u32 = 1024 ;
414419 pub const ParachainHeadsToKeep : u32 = 64 ;
415420 pub const MaxRequests : u32 = 64 ;
416421
417- pub const RococoBridgeParachainPalletName : & ' static str = ROCOCO_BRIDGE_PARA_PALLET_NAME ;
418- pub const WococoBridgeParachainPalletName : & ' static str = WOCOCO_BRIDGE_PARA_PALLET_NAME ;
422+ pub const RococoBridgeParachainPalletName : & ' static str = "Paras" ;
423+ pub const WococoBridgeParachainPalletName : & ' static str = "Paras" ;
419424 pub const MaxRococoParaHeadDataSize : u32 = bp_rococo:: MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE ;
420425 pub const MaxWococoParaHeadDataSize : u32 = bp_wococo:: MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE ;
426+
427+ // TODO:check-parameter - setup initial values https://github.com/paritytech/parity-bridges-common/issues/1677
428+ pub storage DeliveryRewardInBalance : u64 = 1_000_000 ;
429+ pub storage ConfirmationRewardInBalance : u64 = 100_000 ;
421430}
422431
423432/// Add parachain bridge pallet to track Wococo bridge hub parachain
@@ -464,13 +473,15 @@ impl pallet_bridge_messages::Config<WithBridgeHubWococoMessagesInstance> for Run
464473
465474 type InboundPayload = XcmAsPlainPayload ;
466475 type InboundRelayer = AccountId ;
467- // TODO:check-parameter - check delivery
468476 type DeliveryPayments = ( ) ;
469477
470478 type TargetHeaderChain = TargetHeaderChainAdapter < WithBridgeHubWococoMessageBridge > ;
471479 type LaneMessageVerifier = bridge_hub_rococo_config:: ToBridgeHubWococoMessageVerifier ;
472- // TODO:check-parameter - check delivery
473- type DeliveryConfirmationPayments = ( ) ;
480+ type DeliveryConfirmationPayments = pallet_bridge_relayers:: DeliveryConfirmationPaymentsAdapter <
481+ Runtime ,
482+ DeliveryRewardInBalance ,
483+ ConfirmationRewardInBalance ,
484+ > ;
474485
475486 type SourceHeaderChain = SourceHeaderChainAdapter < WithBridgeHubWococoMessageBridge > ;
476487 type MessageDispatch = XcmBlobMessageDispatch <
@@ -498,13 +509,15 @@ impl pallet_bridge_messages::Config<WithBridgeHubRococoMessagesInstance> for Run
498509
499510 type InboundPayload = XcmAsPlainPayload ;
500511 type InboundRelayer = AccountId ;
501- // TODO:check-parameter - check delivery
502512 type DeliveryPayments = ( ) ;
503513
504514 type TargetHeaderChain = TargetHeaderChainAdapter < WithBridgeHubRococoMessageBridge > ;
505515 type LaneMessageVerifier = bridge_hub_wococo_config:: ToBridgeHubRococoMessageVerifier ;
506- // TODO:check-parameter - check delivery
507- type DeliveryConfirmationPayments = ( ) ;
516+ type DeliveryConfirmationPayments = pallet_bridge_relayers:: DeliveryConfirmationPaymentsAdapter <
517+ Runtime ,
518+ DeliveryRewardInBalance ,
519+ ConfirmationRewardInBalance ,
520+ > ;
508521
509522 type SourceHeaderChain = SourceHeaderChainAdapter < WithBridgeHubRococoMessageBridge > ;
510523 type MessageDispatch = XcmBlobMessageDispatch <
@@ -514,6 +527,15 @@ impl pallet_bridge_messages::Config<WithBridgeHubRococoMessagesInstance> for Run
514527 > ;
515528}
516529
530+ /// Allows collect and claim rewards for relayers
531+ impl pallet_bridge_relayers:: Config for Runtime {
532+ type RuntimeEvent = RuntimeEvent ;
533+ type Reward = Balance ;
534+ type PaymentProcedure =
535+ bp_relayers:: PayLaneRewardFromAccount < pallet_balances:: Pallet < Runtime > , AccountId > ;
536+ type WeightInfo = weights:: pallet_bridge_relayers:: WeightInfo < Runtime > ;
537+ }
538+
517539// Create the runtime by composing the FRAME pallets that were previously configured.
518540construct_runtime ! (
519541 pub enum Runtime where
@@ -564,6 +586,8 @@ construct_runtime!(
564586 BridgeRococoGrandpa : pallet_bridge_grandpa:: <Instance2 >:: { Pallet , Call , Storage , Config <T >} = 43 ,
565587 BridgeRococoParachain : pallet_bridge_parachains:: <Instance2 >:: { Pallet , Call , Storage , Event <T >} = 44 ,
566588 BridgeRococoMessages : pallet_bridge_messages:: <Instance2 >:: { Pallet , Call , Storage , Event <T >, Config <T >} = 45 ,
589+
590+ BridgeRelayers : pallet_bridge_relayers:: { Pallet , Call , Storage , Event <T >} = 47 ,
567591 }
568592) ;
569593
@@ -606,6 +630,8 @@ mod benches {
606630 [ pallet_bridge_grandpa, BridgeRococoGrandpa ]
607631 [ pallet_bridge_parachains, BridgeParachainsBench :: <Runtime , BridgeParachainRococoInstance >]
608632 [ pallet_bridge_messages, BridgeMessagesBench :: <Runtime , WithBridgeHubRococoMessagesInstance >]
633+ // Bridge relayer pallets
634+ [ pallet_bridge_relayers, BridgeRelayersBench :: <Runtime >]
609635 ) ;
610636}
611637
@@ -841,6 +867,7 @@ impl_runtime_apis! {
841867
842868 use pallet_bridge_parachains:: benchmarking:: Pallet as BridgeParachainsBench ;
843869 use pallet_bridge_messages:: benchmarking:: Pallet as BridgeMessagesBench ;
870+ use pallet_bridge_relayers:: benchmarking:: Pallet as BridgeRelayersBench ;
844871
845872 let mut list = Vec :: <BenchmarkList >:: new( ) ;
846873 list_benchmarks!( list, extra) ;
@@ -950,9 +977,9 @@ impl_runtime_apis! {
950977 } ;
951978
952979 impl BridgeMessagesConfig <WithBridgeHubWococoMessagesInstance > for Runtime {
953- fn is_relayer_rewarded( _ : & Self :: AccountId ) -> bool {
954- // TODO: implement me properly
955- true
980+ fn is_relayer_rewarded( relayer : & Self :: AccountId ) -> bool {
981+ let bench_lane_id = < Self as BridgeMessagesConfig < WithBridgeHubWococoMessagesInstance >> :: bench_lane_id ( ) ;
982+ pallet_bridge_relayers :: Pallet :: < Runtime > :: relayer_reward ( relayer , & bench_lane_id ) . is_some ( )
956983 }
957984
958985 fn prepare_message_proof(
@@ -977,9 +1004,9 @@ impl_runtime_apis! {
9771004 }
9781005
9791006 impl BridgeMessagesConfig <WithBridgeHubRococoMessagesInstance > for Runtime {
980- fn is_relayer_rewarded( _ : & Self :: AccountId ) -> bool {
981- // TODO: implement me properly
982- true
1007+ fn is_relayer_rewarded( relayer : & Self :: AccountId ) -> bool {
1008+ let bench_lane_id = < Self as BridgeMessagesConfig < WithBridgeHubRococoMessagesInstance >> :: bench_lane_id ( ) ;
1009+ pallet_bridge_relayers :: Pallet :: < Runtime > :: relayer_reward ( relayer , & bench_lane_id ) . is_some ( )
9831010 }
9841011
9851012 fn prepare_message_proof(
@@ -1008,6 +1035,10 @@ impl_runtime_apis! {
10081035 Config as BridgeParachainsConfig ,
10091036 Pallet as BridgeParachainsBench ,
10101037 } ;
1038+ use pallet_bridge_relayers:: benchmarking:: {
1039+ Pallet as BridgeRelayersBench ,
1040+ Config as BridgeRelayersConfig ,
1041+ } ;
10111042
10121043 impl BridgeParachainsConfig <BridgeParachainWococoInstance > for Runtime {
10131044 fn parachains( ) -> Vec <bp_polkadot_core:: parachains:: ParaId > {
@@ -1057,6 +1088,20 @@ impl_runtime_apis! {
10571088 }
10581089 }
10591090
1091+ impl BridgeRelayersConfig for Runtime {
1092+ fn prepare_environment(
1093+ lane: bp_messages:: LaneId ,
1094+ reward: Balance ,
1095+ ) {
1096+ use frame_support:: traits:: fungible:: Mutate ;
1097+ let lane_rewards_account = bp_relayers:: PayLaneRewardFromAccount :: <
1098+ Balances ,
1099+ AccountId
1100+ >:: lane_rewards_account( lane) ;
1101+ Balances :: mint_into( & lane_rewards_account, reward) . unwrap( ) ;
1102+ }
1103+ }
1104+
10601105 let whitelist: Vec <TrackedStorageKey > = vec![
10611106 // Block Number
10621107 hex_literal:: hex!( "26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac" ) . to_vec( ) . into( ) ,
@@ -1111,37 +1156,48 @@ cumulus_pallet_parachain_system::register_validate_block! {
11111156#[ cfg( test) ]
11121157mod tests {
11131158 use super :: * ;
1114- use bridge_runtime_common:: integrity:: check_additional_signed;
1159+ use bp_runtime:: TransactionEra ;
1160+ use bridge_hub_test_utils:: test_header;
11151161 use codec:: Encode ;
1116- use sp_runtime:: generic:: Era ;
11171162
11181163 #[ test]
1119- fn ensure_signed_extension_definition_is_correct ( ) {
1164+ fn ensure_signed_extension_definition_is_compatible_with_relay ( ) {
11201165 let payload: SignedExtra = (
11211166 frame_system:: CheckNonZeroSender :: new ( ) ,
11221167 frame_system:: CheckSpecVersion :: new ( ) ,
11231168 frame_system:: CheckTxVersion :: new ( ) ,
11241169 frame_system:: CheckGenesis :: new ( ) ,
1125- frame_system:: CheckEra :: from ( Era :: Immortal ) ,
1170+ frame_system:: CheckEra :: from ( sp_runtime :: generic :: Era :: Immortal ) ,
11261171 frame_system:: CheckNonce :: from ( 10 ) ,
11271172 frame_system:: CheckWeight :: new ( ) ,
11281173 pallet_transaction_payment:: ChargeTransactionPayment :: from ( 10 ) ,
11291174 BridgeRejectObsoleteHeadersAndMessages { } ,
1175+ (
1176+ BridgeRefundBridgeHubRococoMessages :: default ( ) ,
1177+ BridgeRefundBridgeHubWococoMessages :: default ( ) ,
1178+ ) ,
11301179 ) ;
11311180
1132- let bhr_indirect_payload = bp_bridge_hub_rococo:: SignedExtension :: new (
1133- ( ( ) , ( ) , ( ) , ( ) , Era :: Immortal , 10 . into ( ) , ( ) , 10 . into ( ) , ( ) ) ,
1134- None ,
1135- ) ;
1181+ let bhr_indirect_payload =
1182+ bp_bridge_hub_rococo:: rewarding_bridge_signed_extension:: from_params (
1183+ 10 ,
1184+ 10 ,
1185+ TransactionEra :: Immortal ,
1186+ test_header :: < bridge_hub_test_utils:: RelayBlockHeader > ( 1 ) . hash ( ) ,
1187+ 10 ,
1188+ 10 ,
1189+ ) ;
11361190 assert_eq ! ( payload. encode( ) , bhr_indirect_payload. encode( ) ) ;
11371191
1138- let bhw_indirect_payload = bp_bridge_hub_wococo:: SignedExtension :: new (
1139- ( ( ) , ( ) , ( ) , ( ) , Era :: Immortal , 10 . into ( ) , ( ) , 10 . into ( ) , ( ) ) ,
1140- None ,
1141- ) ;
1192+ let bhw_indirect_payload =
1193+ bp_bridge_hub_wococo:: rewarding_bridge_signed_extension:: from_params (
1194+ 10 ,
1195+ 10 ,
1196+ TransactionEra :: Immortal ,
1197+ test_header :: < bridge_hub_test_utils:: RelayBlockHeader > ( 1 ) . hash ( ) ,
1198+ 10 ,
1199+ 10 ,
1200+ ) ;
11421201 assert_eq ! ( payload. encode( ) , bhw_indirect_payload. encode( ) ) ;
1143-
1144- check_additional_signed :: < SignedExtra , bp_bridge_hub_rococo:: SignedExtension > ( ) ;
1145- check_additional_signed :: < SignedExtra , bp_bridge_hub_wococo:: SignedExtension > ( ) ;
11461202 }
11471203}
0 commit comments