Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Restore Rococo <> Wococo bridges (headers + messages) #4452

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,22 +1045,22 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
},
xcm_pallet: Default::default(),
transaction_payment: Default::default(),
// bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
// owner: Some(endowed_accounts[0].clone()),
// ..Default::default()
// },
// bridge_wococo_grandpa: rococo_runtime::BridgeWococoGrandpaConfig {
// owner: Some(endowed_accounts[0].clone()),
// ..Default::default()
// },
// bridge_rococo_messages: rococo_runtime::BridgeRococoMessagesConfig {
// owner: Some(endowed_accounts[0].clone()),
// ..Default::default()
// },
// bridge_wococo_messages: rococo_runtime::BridgeWococoMessagesConfig {
// owner: Some(endowed_accounts[0].clone()),
// ..Default::default()
// },
bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(endowed_accounts[0].clone()),
..Default::default()
},
bridge_wococo_grandpa: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(endowed_accounts[0].clone()),
..Default::default()
},
bridge_rococo_messages: rococo_runtime::BridgeRococoMessagesConfig {
owner: Some(endowed_accounts[0].clone()),
..Default::default()
},
bridge_wococo_messages: rococo_runtime::BridgeWococoMessagesConfig {
owner: Some(endowed_accounts[0].clone()),
..Default::default()
},
}
}

Expand Down Expand Up @@ -1555,22 +1555,22 @@ pub fn rococo_testnet_genesis(
},
xcm_pallet: Default::default(),
transaction_payment: Default::default(),
// bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
// owner: Some(root_key.clone()),
// ..Default::default()
// },
// bridge_wococo_grandpa: rococo_runtime::BridgeWococoGrandpaConfig {
// owner: Some(root_key.clone()),
// ..Default::default()
// },
// bridge_rococo_messages: rococo_runtime::BridgeRococoMessagesConfig {
// owner: Some(root_key.clone()),
// ..Default::default()
// },
// bridge_wococo_messages: rococo_runtime::BridgeWococoMessagesConfig {
// owner: Some(root_key.clone()),
// ..Default::default()
// },
bridge_rococo_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(root_key.clone()),
..Default::default()
},
bridge_wococo_grandpa: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(root_key.clone()),
..Default::default()
},
bridge_rococo_messages: rococo_runtime::BridgeRococoMessagesConfig {
owner: Some(root_key.clone()),
..Default::default()
},
bridge_wococo_messages: rococo_runtime::BridgeWococoMessagesConfig {
owner: Some(root_key.clone()),
..Default::default()
},
}
}

Expand Down
66 changes: 61 additions & 5 deletions runtime/rococo/src/bridge_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
B::ThisChain: ChainWithMessages<AccountId = crate::AccountId>,
B::BridgedChain: ChainWithMessages<Hash = crate::Hash>,
GI: 'static,
crate::Runtime: pallet_bridge_grandpa::Config<GI> + pallet_bridge_messages::Config<B::BridgedMessagesInstance>,
crate::Runtime: pallet_bridge_grandpa::Config<GI>,
<<crate::Runtime as pallet_bridge_grandpa::Config<GI>>::BridgedChain as bp_runtime::Chain>::Hash: From<crate::Hash>,
{
type Error = &'static str;
Expand All @@ -230,7 +230,7 @@ where
B: MessageBridge,
B::BridgedChain: ChainWithMessages<Balance = crate::Balance, Hash = crate::Hash>,
GI: 'static,
crate::Runtime: pallet_bridge_grandpa::Config<GI> + pallet_bridge_messages::Config<B::BridgedMessagesInstance>,
crate::Runtime: pallet_bridge_grandpa::Config<GI>,
<<crate::Runtime as pallet_bridge_grandpa::Config<GI>>::BridgedChain as bp_runtime::Chain>::Hash: From<crate::Hash>,
{
type Error = &'static str;
Expand All @@ -240,10 +240,24 @@ where
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<crate::Balance>>, Self::Error> {
messages_target::verify_messages_proof::<B, crate::Runtime, GI>(proof, messages_count)
messages_target::verify_messages_proof::<B, crate::Runtime, GI>(proof, messages_count).and_then(verify_inbound_messages_lane)
}
}

/// Error that happens when we are receiving incoming message via unexpected lane.
const INBOUND_LANE_DISABLED: &str = "The inbound message lane is disabled.";

/// Verify that lanes of inbound messages are enabled.
fn verify_inbound_messages_lane(
messages: ProvedMessages<Message<crate::Balance>>,
) -> Result<ProvedMessages<Message<crate::Balance>>, &'static str> {
let allowed_incoming_lanes = [[0, 0, 0, 0]];
if messages.keys().any(|lane_id| !allowed_incoming_lanes.contains(lane_id)) {
return Err(INBOUND_LANE_DISABLED)
}
Ok(messages)
}

/// The cost of delivery confirmation transaction.
pub struct GetDeliveryConfirmationTransactionFee;

Expand All @@ -267,10 +281,11 @@ mod at_rococo {
const THIS_CHAIN_ID: ChainId = ROCOCO_CHAIN_ID;
const BRIDGED_CHAIN_ID: ChainId = WOCOCO_CHAIN_ID;
const RELAYER_FEE_PERCENT: u32 = 10;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
bp_wococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;

type ThisChain = RococoAtRococo;
type BridgedChain = WococoAtRococo;
type BridgedMessagesInstance = crate::AtWococoWithRococoMessagesInstance;

fn bridged_balance_to_this_balance(
bridged_balance: bp_wococo::Balance,
Expand Down Expand Up @@ -316,10 +331,11 @@ mod at_wococo {
const THIS_CHAIN_ID: ChainId = WOCOCO_CHAIN_ID;
const BRIDGED_CHAIN_ID: ChainId = ROCOCO_CHAIN_ID;
const RELAYER_FEE_PERCENT: u32 = 10;
const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
bp_rococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;

type ThisChain = WococoAtWococo;
type BridgedChain = RococoAtWococo;
type BridgedMessagesInstance = crate::AtRococoWithWococoMessagesInstance;

fn bridged_balance_to_this_balance(
bridged_balance: bp_rococo::Balance,
Expand Down Expand Up @@ -356,6 +372,7 @@ mod at_wococo {
#[cfg(test)]
mod tests {
use super::*;
use bp_messages::{target_chain::ProvedLaneMessages, MessageData, MessageKey};
use bridge_runtime_common::messages;
use parity_scale_codec::Encode;

Expand All @@ -377,6 +394,7 @@ mod tests {
ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
PAY_INBOUND_DISPATCH_FEE_WEIGHT,
crate::RocksDbWeight::get(),
);

let max_incoming_message_proof_size = bp_rococo::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
Expand Down Expand Up @@ -404,6 +422,7 @@ mod tests {
max_incoming_inbound_lane_data_proof_size,
bp_rococo::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
bp_rococo::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
crate::RocksDbWeight::get(),
);
}

Expand Down Expand Up @@ -440,4 +459,41 @@ mod tests {
extra_bytes_in_transaction,
);
}

fn proved_messages(lane_id: LaneId) -> ProvedMessages<Message<crate::Balance>> {
vec![(
lane_id,
ProvedLaneMessages {
lane_state: None,
messages: vec![Message {
key: MessageKey { lane_id, nonce: 0 },
data: MessageData { payload: vec![], fee: 0 },
}],
},
)]
.into_iter()
.collect()
}

#[test]
fn verify_inbound_messages_lane_succeeds() {
assert_eq!(
verify_inbound_messages_lane(proved_messages([0, 0, 0, 0])),
Ok(proved_messages([0, 0, 0, 0])),
);
}

#[test]
fn verify_inbound_messages_lane_fails() {
assert_eq!(
verify_inbound_messages_lane(proved_messages([0, 0, 0, 1])),
Err(INBOUND_LANE_DISABLED),
);

let proved_messages = proved_messages([0, 0, 0, 0])
.into_iter()
.chain(proved_messages([0, 0, 0, 1]))
.collect();
assert_eq!(verify_inbound_messages_lane(proved_messages), Err(INBOUND_LANE_DISABLED),);
}
}
Loading