Skip to content

Commit

Permalink
client-legacy: non-comapact proofs macros: generate_receive_message_d…
Browse files Browse the repository at this point in the history
…elivery_proof_call_builder/generate_receive_message_proof_call_builder
  • Loading branch information
bkontur committed Jun 28, 2024
1 parent 8f97283 commit f971d42
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 16 deletions.
117 changes: 117 additions & 0 deletions relay-clients/client-legacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ pub mod non_compact_proofs {
/// Lane id of which messages were delivered and the proof is for.
pub lane: LaneId,
}

impl<BridgedHeaderHash>
From<
bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<
BridgedHeaderHash,
>,
> for FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash>
{
fn from(
value: bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<
BridgedHeaderHash,
>,
) -> Self {
FromBridgedChainMessagesDeliveryProof {
bridged_header_hash: value.bridged_header_hash,
// this is legacy change, we need to get `RawStorageProof` from
// `UnverifiedStorageProof.proof`
storage_proof: value.storage_proof.proof().clone(),
lane: value.lane,
}
}
}
}
pub mod target {
use super::*;
Expand All @@ -71,7 +93,102 @@ pub mod non_compact_proofs {
/// Nonce of the last message being delivered.
pub nonces_end: MessageNonce,
}

impl<BridgedHeaderHash>
From<
bp_messages::target_chain::FromBridgedChainMessagesProof<BridgedHeaderHash>,
> for FromBridgedChainMessagesProof<BridgedHeaderHash>
{
fn from(
value: bp_messages::target_chain::FromBridgedChainMessagesProof<
BridgedHeaderHash,
>,
) -> Self {
FromBridgedChainMessagesProof {
bridged_header_hash: value.bridged_header_hash,
// this is legacy change, we need to get `RawStorageProof` from
// `UnverifiedStorageProof.proof`
storage_proof: value.storage.proof().clone(),
lane: value.lane,
nonces_start: value.nonces_start,
nonces_end: value.nonces_end,
}
}
}
}
}
}

/// Macro that generates `ReceiveMessagesProofCallBuilder` implementation for the case when
/// you only have an access to the mocked version of target chain runtime. In this case you
/// should provide "name" of the call variant for the bridge messages calls and the "name" of
/// the variant for the `receive_messages_proof` call within that first option.
#[rustfmt::skip]
#[macro_export]
macro_rules! generate_receive_message_proof_call_builder {
($pipeline:ident, $mocked_builder:ident, $bridge_messages:path, $receive_messages_proof:path) => {
pub struct $mocked_builder;

impl substrate_relay_helper::messages::ReceiveMessagesProofCallBuilder<$pipeline>
for $mocked_builder
{
fn build_receive_messages_proof_call(
relayer_id_at_source: relay_substrate_client::AccountIdOf<
<$pipeline as substrate_relay_helper::messages::SubstrateMessageLane>::SourceChain
>,
proof: substrate_relay_helper::messages::source::SubstrateMessagesProof<
<$pipeline as substrate_relay_helper::messages::SubstrateMessageLane>::SourceChain
>,
messages_count: u32,
dispatch_weight: bp_messages::Weight,
_trace_call: bool,
) -> relay_substrate_client::CallOf<
<$pipeline as substrate_relay_helper::messages::SubstrateMessageLane>::TargetChain
> {
bp_runtime::paste::item! {
$bridge_messages($receive_messages_proof {
relayer_id_at_bridged_chain: relayer_id_at_source,
// a legacy change - convert between `bp_messages::target_chain::FromBridgedChainMessagesDeliveryProof` and `FromBridgedChainMessagesDeliveryProof` - see `From` impl above
proof: proof.1.into(),
messages_count: messages_count,
dispatch_weight: dispatch_weight,
})
}
}
}
};
}

/// Macro that generates `ReceiveMessagesDeliveryProofCallBuilder` implementation for the case when
/// you only have an access to the mocked version of source chain runtime. In this case you
/// should provide "name" of the call variant for the bridge messages calls and the "name" of
/// the variant for the `receive_messages_delivery_proof` call within that first option.
#[rustfmt::skip]
#[macro_export]
macro_rules! generate_receive_message_delivery_proof_call_builder {
($pipeline:ident, $mocked_builder:ident, $bridge_messages:path, $receive_messages_delivery_proof:path) => {
pub struct $mocked_builder;

impl substrate_relay_helper::messages::ReceiveMessagesDeliveryProofCallBuilder<$pipeline>
for $mocked_builder
{
fn build_receive_messages_delivery_proof_call(
proof: substrate_relay_helper::messages::target::SubstrateMessagesDeliveryProof<
<$pipeline as substrate_relay_helper::messages::SubstrateMessageLane>::TargetChain
>,
_trace_call: bool,
) -> relay_substrate_client::CallOf<
<$pipeline as substrate_relay_helper::messages::SubstrateMessageLane>::SourceChain
> {
bp_runtime::paste::item! {
$bridge_messages($receive_messages_delivery_proof {
// a legacy change - convert between `bp_messages::source_chain::FromBridgedChainMessagesProof` and `FromBridgedChainMessagesProof` - see `From` impl above
proof: proof.1.into(),
relayers_state: proof.0
})
}
}
}
};
}
}
2 changes: 1 addition & 1 deletion substrate-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ relay-bridge-hub-polkadot-client = { path = "../relay-clients/client-bridge-hub-
relay-bridge-hub-rococo-client = { path = "../relay-clients/client-bridge-hub-rococo" }
relay-bridge-hub-westend-client = { path = "../relay-clients/client-bridge-hub-westend" }
relay-kusama-client = { path = "../relay-clients/client-kusama" }
relay-legacy-client = { path = "../relay-clients/client-legacy" }
relay-polkadot-client = { path = "../relay-clients/client-polkadot" }
relay-polkadot-bulletin-client = { path = "../relay-clients/client-polkadot-bulletin" }
relay-rococo-client = { path = "../relay-clients/client-rococo" }
Expand All @@ -54,7 +55,6 @@ relay-westend-client = { path = "../relay-clients/client-westend" }
substrate-relay-helper = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }

# Substrate Dependencies

frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ impl MessagesCliBridge for BridgeHubKusamaToBridgeHubPolkadotMessagesCliBridge {
type MessagesLane = BridgeHubKusamaMessagesToBridgeHubPolkadotMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when BridgeHubPolkadot supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubKusamaMessagesToBridgeHubPolkadotMessageLane,
BridgeHubKusamaMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_polkadot_client::RuntimeCall::BridgeKusamaMessages,
relay_bridge_hub_polkadot_client::BridgeKusamaMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when BridgeHubKusama supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
BridgeHubKusamaMessagesToBridgeHubPolkadotMessageLane,
BridgeHubKusamaMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_bridge_hub_kusama_client::RuntimeCall::BridgePolkadotMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ impl MessagesCliBridge for BridgeHubPolkadotToBridgeHubKusamaMessagesCliBridge {
type MessagesLane = BridgeHubPolkadotMessagesToBridgeHubKusamaMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when BridgeHubKusama supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubPolkadotMessagesToBridgeHubKusamaMessageLane,
BridgeHubPolkadotMessagesToBridgeHubKusamaMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_kusama_client::RuntimeCall::BridgePolkadotMessages,
relay_bridge_hub_kusama_client::BridgeMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when BridgeHubPolkadot supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
BridgeHubPolkadotMessagesToBridgeHubKusamaMessageLane,
BridgeHubPolkadotMessagesToBridgeHubKusamaMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_bridge_hub_polkadot_client::RuntimeCall::BridgeKusamaMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ impl MessagesCliBridge for BridgeHubPolkadotToPolkadotBulletinMessagesCliBridge
type MessagesLane = BridgeHubPolkadotMessagesToPolkadotBulletinMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when PolkadotBulletin supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLane,
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLaneReceiveMessagesProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
relay_polkadot_bulletin_client::BridgePolkadotMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when BridgeHubPolkadot supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLane,
BridgeHubPolkadotMessagesToPolkadotBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder,
// TODO: https://github.com/paritytech/parity-bridges-common/issues/2547 - use BridgePolkadotBulletinMessages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ impl MessagesCliBridge for PolkadotBulletinToBridgeHubPolkadotMessagesCliBridge
type MessagesLane = PolkadotBulletinMessagesToBridgeHubPolkadotMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when BridgeHubPolkadot supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLane,
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesProofCallBuilder,
// TODO: https://github.com/paritytech/parity-bridges-common/issues/2547 - use BridgePolkadotBulletinMessages
relay_bridge_hub_polkadot_client::RuntimeCall::BridgeKusamaMessages,
relay_bridge_hub_polkadot_client::BridgePolkadotBulletinMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when PolkadotBulletin supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLane,
PolkadotBulletinMessagesToBridgeHubPolkadotMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ impl MessagesCliBridge for BridgeHubRococoToRococoBulletinMessagesCliBridge {
type MessagesLane = BridgeHubRococoMessagesToRococoBulletinMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when PolkadotBulletin supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubRococoMessagesToRococoBulletinMessageLane,
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ impl MessagesCliBridge for RococoBulletinToBridgeHubRococoMessagesCliBridge {
type MessagesLane = RococoBulletinMessagesToBridgeHubRococoMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when PolkadotBulletin supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
RococoBulletinMessagesToBridgeHubRococoMessageLane,
RococoBulletinMessagesToBridgeHubRococoMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_rococo_client::RuntimeCall::BridgePolkadotBulletinMessages,
relay_bridge_hub_rococo_client::BridgeBulletinMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when PolkadotBulletin supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
RococoBulletinMessagesToBridgeHubRococoMessageLane,
RococoBulletinMessagesToBridgeHubRococoMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_polkadot_bulletin_client::RuntimeCall::BridgePolkadotMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ impl MessagesCliBridge for BridgeHubRococoToBridgeHubWestendMessagesCliBridge {
type MessagesLane = BridgeHubRococoMessagesToBridgeHubWestendMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when BridgeHubWestend supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubRococoMessagesToBridgeHubWestendMessageLane,
BridgeHubRococoMessagesToBridgeHubWestendMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_westend_client::RuntimeCall::BridgeRococoMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ impl MessagesCliBridge for BridgeHubWestendToBridgeHubRococoMessagesCliBridge {
type MessagesLane = BridgeHubWestendMessagesToBridgeHubRococoMessageLane;
}

substrate_relay_helper::generate_receive_message_proof_call_builder!(
// TODO: uncomment when BridgeHubWestend supports the compact proofs
// substrate_relay_helper::generate_receive_message_proof_call_builder!(
relay_legacy_client::generate_receive_message_proof_call_builder!(
BridgeHubWestendMessagesToBridgeHubRococoMessageLane,
BridgeHubWestendMessagesToBridgeHubRococoMessageLaneReceiveMessagesProofCallBuilder,
relay_bridge_hub_rococo_client::RuntimeCall::BridgeWestendMessages,
relay_bridge_hub_rococo_client::BridgeMessagesCall::receive_messages_proof
);

substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
// TODO: uncomment when BridgeHubWestend supports the compact proofs
// substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
relay_legacy_client::generate_receive_message_delivery_proof_call_builder!(
BridgeHubWestendMessagesToBridgeHubRococoMessageLane,
BridgeHubWestendMessagesToBridgeHubRococoMessageLaneReceiveMessagesDeliveryProofCallBuilder,
relay_bridge_hub_westend_client::RuntimeCall::BridgeRococoMessages,
Expand Down
2 changes: 1 addition & 1 deletion substrate-relay/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Command {
Ok(signals) => signals,
Err(e) => {
log::error!(target: LOG_TARGET, "Could not register exit signals: {}", e);
return
return;
},
};
let run = self.do_run().fuse();
Expand Down

0 comments on commit f971d42

Please sign in to comment.