Skip to content

Commit

Permalink
Use named parameters for indirect calls (paritytech#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Apr 9, 2024
1 parent 09ed76c commit 6cb2966
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 43 deletions.
7 changes: 5 additions & 2 deletions bridges/modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,15 +1178,18 @@ mod tests {

let direct_initialize_call =
Call::<TestRuntime>::initialize { init_data: init_data.clone() };
let indirect_initialize_call = BridgeGrandpaCall::<TestHeader>::initialize(init_data);
let indirect_initialize_call = BridgeGrandpaCall::<TestHeader>::initialize { init_data };
assert_eq!(direct_initialize_call.encode(), indirect_initialize_call.encode());

let direct_submit_finality_proof_call = Call::<TestRuntime>::submit_finality_proof {
finality_target: Box::new(header.clone()),
justification: justification.clone(),
};
let indirect_submit_finality_proof_call =
BridgeGrandpaCall::<TestHeader>::submit_finality_proof(Box::new(header), justification);
BridgeGrandpaCall::<TestHeader>::submit_finality_proof {
finality_target: Box::new(header),
justification,
};
assert_eq!(
direct_submit_finality_proof_call.encode(),
indirect_submit_finality_proof_call.encode()
Expand Down
20 changes: 10 additions & 10 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions bridges/modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions bridges/primitives/header-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,13 @@ impl<Number: Codec> ConsensusLogReader for GrandpaConsensusLogReader<Number> {
pub enum BridgeGrandpaCall<Header: HeaderT> {
/// `pallet-bridge-grandpa::Call::submit_finality_proof`
#[codec(index = 0)]
submit_finality_proof(Box<Header>, justification::GrandpaJustification<Header>),
submit_finality_proof {
finality_target: Box<Header>,
justification: justification::GrandpaJustification<Header>,
},
/// `pallet-bridge-grandpa::Call::initialize`
#[codec(index = 1)]
initialize(InitializationData<Header>),
initialize { init_data: InitializationData<Header> },
}

/// The `BridgeGrandpaCall` used by a chain.
Expand Down
12 changes: 10 additions & 2 deletions bridges/primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,18 @@ where
pub enum BridgeMessagesCall<AccountId, MessagesProof, MessagesDeliveryProof> {
/// `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)]
Expand Down
10 changes: 5 additions & 5 deletions bridges/primitives/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ impl SubmitParachainHeadsCallBuilder<BridgeHubRococoToBridgeHubWococo>
parachain_heads_proof: ParaHeadsProof,
) -> CallOf<relay_bridge_hub_wococo_client::BridgeHubWococo> {
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,
),
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ impl SubmitParachainHeadsCallBuilder<BridgeHubWococoToBridgeHubRococo>
parachain_heads_proof: ParaHeadsProof,
) -> CallOf<relay_bridge_hub_rococo_client::BridgeHubRococo> {
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,
),
},
)
}
}
Expand Down
15 changes: 10 additions & 5 deletions bridges/relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge {
) -> <Self::Target as Chain>::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)
}
Expand Down Expand Up @@ -176,7 +177,9 @@ impl BridgeInitializer for RococoToBridgeHubWococoCliBridge {
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::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,
},
)
}
}
Expand All @@ -188,7 +191,9 @@ impl BridgeInitializer for WococoToBridgeHubRococoCliBridge {
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::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,
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion bridges/relays/lib-substrate-relay/src/finality/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
}
};
Expand Down
21 changes: 14 additions & 7 deletions bridges/relays/lib-substrate-relay/src/messages_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
}
};
Expand Down Expand Up @@ -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
})
}
}
}
};
Expand Down

0 comments on commit 6cb2966

Please sign in to comment.