From f5278e90b3eb0753ecaef0f5c285ae5af9d423e3 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 27 Jan 2023 14:13:25 +0200 Subject: [PATCH] Use named parameters for indirect calls (#1823) --- bridges/modules/grandpa/src/lib.rs | 7 +++++-- bridges/modules/messages/src/lib.rs | 20 +++++++++--------- bridges/modules/parachains/src/lib.rs | 7 +++++-- bridges/primitives/header-chain/src/lib.rs | 7 +++++-- bridges/primitives/messages/src/lib.rs | 12 +++++++++-- bridges/primitives/parachains/src/lib.rs | 10 ++++----- .../rococo_parachains_to_bridge_hub_wococo.rs | 6 +++--- .../wococo_parachains_to_bridge_hub_rococo.rs | 6 +++--- .../bin-substrate/src/cli/init_bridge.rs | 15 ++++++++----- .../src/runtime_wrapper.rs | 2 +- .../lib-substrate-relay/src/finality/mod.rs | 7 ++++++- .../lib-substrate-relay/src/messages_lane.rs | 21 ++++++++++++------- 12 files changed, 77 insertions(+), 43 deletions(-) diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index d3335693adfa7..3cf67349b474a 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -1178,7 +1178,7 @@ mod tests { let direct_initialize_call = Call::::initialize { init_data: init_data.clone() }; - let indirect_initialize_call = BridgeGrandpaCall::::initialize(init_data); + let indirect_initialize_call = BridgeGrandpaCall::::initialize { init_data }; assert_eq!(direct_initialize_call.encode(), indirect_initialize_call.encode()); let direct_submit_finality_proof_call = Call::::submit_finality_proof { @@ -1186,7 +1186,10 @@ mod tests { justification: justification.clone(), }; let indirect_submit_finality_proof_call = - BridgeGrandpaCall::::submit_finality_proof(Box::new(header), justification); + BridgeGrandpaCall::::submit_finality_proof { + finality_target: Box::new(header), + justification, + }; assert_eq!( direct_submit_finality_proof_call.encode(), indirect_submit_finality_proof_call.encode() diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 680518d9dc8b2..ec895955076c0 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -1928,12 +1928,12 @@ mod tests { AccountId, TestMessagesProof, TestMessagesDeliveryProof, - >::receive_messages_proof( - account_id, - message_proof, - 1, - REGULAR_PAYLOAD.declared_weight, - ); + >::receive_messages_proof { + relayer_id_at_bridged_chain: account_id, + proof: message_proof, + messages_count: 1, + dispatch_weight: REGULAR_PAYLOAD.declared_weight, + }; assert_eq!( direct_receive_messages_proof_call.encode(), indirect_receive_messages_proof_call.encode() @@ -1948,10 +1948,10 @@ mod tests { AccountId, TestMessagesProof, TestMessagesDeliveryProof, - >::receive_messages_delivery_proof( - message_delivery_proof, - unrewarded_relayer_state, - ); + >::receive_messages_delivery_proof { + proof: message_delivery_proof, + relayers_state: unrewarded_relayer_state, + }; assert_eq!( direct_receive_messages_delivery_proof_call.encode(), indirect_receive_messages_delivery_proof_call.encode() diff --git a/bridges/modules/parachains/src/lib.rs b/bridges/modules/parachains/src/lib.rs index 06a1f82e7b0b1..e2f2cbf2d499c 100644 --- a/bridges/modules/parachains/src/lib.rs +++ b/bridges/modules/parachains/src/lib.rs @@ -1513,8 +1513,11 @@ mod tests { parachains: parachains.clone(), parachain_heads_proof: proof.clone(), }; - let indirect_submit_parachain_heads_call = - BridgeParachainCall::submit_parachain_heads(relay_header_id, parachains, proof); + let indirect_submit_parachain_heads_call = BridgeParachainCall::submit_parachain_heads { + at_relay_block: relay_header_id, + parachains, + parachain_heads_proof: proof, + }; assert_eq!( direct_submit_parachain_heads_call.encode(), indirect_submit_parachain_heads_call.encode() diff --git a/bridges/primitives/header-chain/src/lib.rs b/bridges/primitives/header-chain/src/lib.rs index dffa7f7dc6e0e..14e9395c03c09 100644 --- a/bridges/primitives/header-chain/src/lib.rs +++ b/bridges/primitives/header-chain/src/lib.rs @@ -176,10 +176,13 @@ impl ConsensusLogReader for GrandpaConsensusLogReader { pub enum BridgeGrandpaCall { /// `pallet-bridge-grandpa::Call::submit_finality_proof` #[codec(index = 0)] - submit_finality_proof(Box
, justification::GrandpaJustification
), + submit_finality_proof { + finality_target: Box
, + justification: justification::GrandpaJustification
, + }, /// `pallet-bridge-grandpa::Call::initialize` #[codec(index = 1)] - initialize(InitializationData
), + initialize { init_data: InitializationData
}, } /// The `BridgeGrandpaCall` used by a chain. diff --git a/bridges/primitives/messages/src/lib.rs b/bridges/primitives/messages/src/lib.rs index 61d475cb46c1b..754349d634eef 100644 --- a/bridges/primitives/messages/src/lib.rs +++ b/bridges/primitives/messages/src/lib.rs @@ -397,10 +397,18 @@ where pub enum BridgeMessagesCall { /// `pallet-bridge-messages::Call::receive_messages_proof` #[codec(index = 2)] - receive_messages_proof(AccountId, MessagesProof, u32, Weight), + receive_messages_proof { + relayer_id_at_bridged_chain: AccountId, + proof: MessagesProof, + messages_count: u32, + dispatch_weight: Weight, + }, /// `pallet-bridge-messages::Call::receive_messages_delivery_proof` #[codec(index = 3)] - receive_messages_delivery_proof(MessagesDeliveryProof, UnrewardedRelayersState), + receive_messages_delivery_proof { + proof: MessagesDeliveryProof, + relayers_state: UnrewardedRelayersState, + }, } #[cfg(test)] diff --git a/bridges/primitives/parachains/src/lib.rs b/bridges/primitives/parachains/src/lib.rs index 6b38d648d79d5..388a995fae6de 100644 --- a/bridges/primitives/parachains/src/lib.rs +++ b/bridges/primitives/parachains/src/lib.rs @@ -157,9 +157,9 @@ impl ParaStoredHeaderDataBuilder for C { pub enum BridgeParachainCall { /// `pallet-bridge-parachains::Call::submit_parachain_heads` #[codec(index = 0)] - submit_parachain_heads( - (RelayBlockNumber, RelayBlockHash), - Vec<(ParaId, ParaHash)>, - ParaHeadsProof, - ), + submit_parachain_heads { + at_relay_block: (RelayBlockNumber, RelayBlockHash), + parachains: Vec<(ParaId, ParaHash)>, + parachain_heads_proof: ParaHeadsProof, + }, } diff --git a/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs index b028253d8a4f6..098aed417c662 100644 --- a/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs +++ b/bridges/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs @@ -51,11 +51,11 @@ impl SubmitParachainHeadsCallBuilder parachain_heads_proof: ParaHeadsProof, ) -> CallOf { relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoParachain( - relay_bridge_hub_wococo_client::runtime::BridgeParachainCall::submit_parachain_heads( - (at_relay_block.0, at_relay_block.1), + relay_bridge_hub_wococo_client::runtime::BridgeParachainCall::submit_parachain_heads { + at_relay_block: (at_relay_block.0, at_relay_block.1), parachains, parachain_heads_proof, - ), + }, ) } } diff --git a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs index f79979ff8328b..683e7705dd6ac 100644 --- a/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs @@ -51,11 +51,11 @@ impl SubmitParachainHeadsCallBuilder parachain_heads_proof: ParaHeadsProof, ) -> CallOf { relay_bridge_hub_rococo_client::runtime::Call::BridgeWococoParachain( - bp_parachains::BridgeParachainCall::submit_parachain_heads( - (at_relay_block.0, at_relay_block.1), + bp_parachains::BridgeParachainCall::submit_parachain_heads { + at_relay_block: (at_relay_block.0, at_relay_block.1), parachains, parachain_heads_proof, - ), + }, ) } } diff --git a/bridges/relays/bin-substrate/src/cli/init_bridge.rs b/bridges/relays/bin-substrate/src/cli/init_bridge.rs index 8f4080b338cee..3e9ddfdb94fd8 100644 --- a/bridges/relays/bin-substrate/src/cli/init_bridge.rs +++ b/bridges/relays/bin-substrate/src/cli/init_bridge.rs @@ -125,9 +125,10 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge { ) -> ::Call { use relay_rialto_parachain_client::runtime; - let initialize_call = runtime::Call::BridgeMillauGrandpa( - runtime::BridgeMillauGrandpaCall::initialize(init_data), - ); + let initialize_call = + runtime::Call::BridgeMillauGrandpa(runtime::BridgeMillauGrandpaCall::initialize { + init_data, + }); let sudo_call = SudoCall::sudo(Box::new(initialize_call)); runtime::Call::Sudo(sudo_call) } @@ -176,7 +177,9 @@ impl BridgeInitializer for RococoToBridgeHubWococoCliBridge { init_data: >::InitializationData, ) -> ::Call { relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoGrandpa( - relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::initialize(init_data), + relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::initialize { + init_data, + }, ) } } @@ -188,7 +191,9 @@ impl BridgeInitializer for WococoToBridgeHubRococoCliBridge { init_data: >::InitializationData, ) -> ::Call { relay_bridge_hub_rococo_client::runtime::Call::BridgeWococoGrandpa( - relay_bridge_hub_rococo_client::runtime::BridgeWococoGrandpaCall::initialize(init_data), + relay_bridge_hub_rococo_client::runtime::BridgeWococoGrandpaCall::initialize { + init_data, + }, ) } } diff --git a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs index 85f77a6377ef7..17cc4cbd4e8f8 100644 --- a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs +++ b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs @@ -96,7 +96,7 @@ mod tests { set_id: 6, operating_mode: BasicOperatingMode::Normal, }; - let call = BridgeRococoGrandpaCall::initialize(init_data); + let call = BridgeRococoGrandpaCall::initialize { init_data }; let tx = Call::BridgeRococoGrandpa(call); // encode call as hex string diff --git a/bridges/relays/lib-substrate-relay/src/finality/mod.rs b/bridges/relays/lib-substrate-relay/src/finality/mod.rs index 5d7b52cd1dec7..f529e20912a3e 100644 --- a/bridges/relays/lib-substrate-relay/src/finality/mod.rs +++ b/bridges/relays/lib-substrate-relay/src/finality/mod.rs @@ -156,7 +156,12 @@ macro_rules! generate_mocked_submit_finality_proof_call_builder { ) -> relay_substrate_client::CallOf< <$pipeline as $crate::finality::SubstrateFinalitySyncPipeline>::TargetChain > { - $bridge_grandpa($submit_finality_proof(Box::new(header.into_inner()), proof)) + bp_runtime::paste::item! { + $bridge_grandpa($submit_finality_proof { + finality_target: Box::new(header.into_inner()), + justification: proof + }) + } } } }; diff --git a/bridges/relays/lib-substrate-relay/src/messages_lane.rs b/bridges/relays/lib-substrate-relay/src/messages_lane.rs index 73d441cfcd381..a0cd9b4375656 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_lane.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_lane.rs @@ -335,12 +335,14 @@ macro_rules! generate_mocked_receive_message_proof_call_builder { ) -> relay_substrate_client::CallOf< <$pipeline as $crate::messages_lane::SubstrateMessageLane>::TargetChain > { - $bridge_messages($receive_messages_proof( - relayer_id_at_source, - proof.1, - messages_count, - dispatch_weight, - )) + bp_runtime::paste::item! { + $bridge_messages($receive_messages_proof { + relayer_id_at_bridged_chain: relayer_id_at_source, + proof: proof.1, + messages_count: messages_count, + dispatch_weight: dispatch_weight, + }) + } } } }; @@ -424,7 +426,12 @@ macro_rules! generate_mocked_receive_message_delivery_proof_call_builder { ) -> relay_substrate_client::CallOf< <$pipeline as $crate::messages_lane::SubstrateMessageLane>::SourceChain > { - $bridge_messages($receive_messages_delivery_proof(proof.1, proof.0)) + bp_runtime::paste::item! { + $bridge_messages($receive_messages_delivery_proof { + proof: proof.1, + relayers_state: proof.0 + }) + } } } };