Skip to content

Commit

Permalink
pass source and target chain ids to account_ownership_proof (parityte…
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 10, 2024
1 parent 076f332 commit 0f4245f
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 115 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Alternative {
"tokenDecimals": 9,
"tokenSymbol": "MLAU",
"bridgeIds": {
"Rialto": bp_runtime::RIALTO_BRIDGE_INSTANCE,
"Rialto": bp_runtime::RIALTO_CHAIN_ID,
}
})
.as_object()
Expand Down
5 changes: 3 additions & 2 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl_runtime_apis! {
/// The byte vector returned by this function should be signed with a Rialto account private key.
/// This way, the owner of `millau_account_id` on Millau proves that the Rialto account private key
/// is also under his control.
pub fn rialto_account_ownership_digest<Call, AccountId, SpecVersion>(
pub fn millau_to_rialto_account_ownership_digest<Call, AccountId, SpecVersion>(
rialto_call: &Call,
millau_account_id: AccountId,
rialto_spec_version: SpecVersion,
Expand All @@ -656,7 +656,8 @@ where
rialto_call,
millau_account_id,
rialto_spec_version,
bp_runtime::MILLAU_BRIDGE_INSTANCE,
bp_runtime::MILLAU_CHAIN_ID,
bp_runtime::RIALTO_CHAIN_ID,
)
}

Expand Down
8 changes: 5 additions & 3 deletions bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bp_messages::{
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_runtime::{InstanceId, RIALTO_BRIDGE_INSTANCE};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge, MessageTransaction};
use codec::{Decode, Encode};
use frame_support::{
Expand Down Expand Up @@ -72,8 +72,6 @@ pub type FromRialtoMessageDispatch = messages::target::FromBridgedChainMessageDi
pub struct WithRialtoMessageBridge;

impl MessageBridge for WithRialtoMessageBridge {
const INSTANCE: InstanceId = RIALTO_BRIDGE_INSTANCE;

const RELAYER_FEE_PERCENT: u32 = 10;

type ThisChain = Millau;
Expand All @@ -90,6 +88,8 @@ impl MessageBridge for WithRialtoMessageBridge {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
const ID: ChainId = MILLAU_CHAIN_ID;

type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
Expand Down Expand Up @@ -141,6 +141,8 @@ impl messages::ThisChainWithMessages for Millau {
pub struct Rialto;

impl messages::ChainWithMessages for Rialto {
const ID: ChainId = RIALTO_CHAIN_ID;

type Hash = bp_rialto::Hash;
type AccountId = bp_rialto::AccountId;
type Signer = bp_rialto::AccountSigner;
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/rialto/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Alternative {
"tokenDecimals": 9,
"tokenSymbol": "RLT",
"bridgeIds": {
"Millau": bp_runtime::MILLAU_BRIDGE_INSTANCE,
"Millau": bp_runtime::MILLAU_CHAIN_ID,
}
})
.as_object()
Expand Down
5 changes: 3 additions & 2 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ impl_runtime_apis! {
/// The byte vector returned by this function should be signed with a Millau account private key.
/// This way, the owner of `rialto_account_id` on Rialto proves that the 'millau' account private key
/// is also under his control.
pub fn millau_account_ownership_digest<Call, AccountId, SpecVersion>(
pub fn rialto_to_millau_account_ownership_digest<Call, AccountId, SpecVersion>(
millau_call: &Call,
rialto_account_id: AccountId,
millau_spec_version: SpecVersion,
Expand All @@ -1040,7 +1040,8 @@ where
millau_call,
rialto_account_id,
millau_spec_version,
bp_runtime::RIALTO_BRIDGE_INSTANCE,
bp_runtime::RIALTO_CHAIN_ID,
bp_runtime::MILLAU_CHAIN_ID,
)
}

Expand Down
8 changes: 5 additions & 3 deletions bridges/bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bp_messages::{
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_runtime::{InstanceId, MILLAU_BRIDGE_INSTANCE};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge, MessageTransaction};
use codec::{Decode, Encode};
use frame_support::{
Expand Down Expand Up @@ -72,8 +72,6 @@ pub type ToMillauMessagesDeliveryProof = messages::source::FromBridgedChainMessa
pub struct WithMillauMessageBridge;

impl MessageBridge for WithMillauMessageBridge {
const INSTANCE: InstanceId = MILLAU_BRIDGE_INSTANCE;

const RELAYER_FEE_PERCENT: u32 = 10;

type ThisChain = Rialto;
Expand All @@ -90,6 +88,8 @@ impl MessageBridge for WithMillauMessageBridge {
pub struct Rialto;

impl messages::ChainWithMessages for Rialto {
const ID: ChainId = RIALTO_CHAIN_ID;

type Hash = bp_rialto::Hash;
type AccountId = bp_rialto::AccountId;
type Signer = bp_rialto::AccountSigner;
Expand Down Expand Up @@ -141,6 +141,8 @@ impl messages::ThisChainWithMessages for Rialto {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
const ID: ChainId = MILLAU_CHAIN_ID;

type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
Expand Down
17 changes: 10 additions & 7 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use bp_messages::{
target_chain::{DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages},
InboundLaneData, LaneId, Message, MessageData, MessageKey, MessageNonce, OutboundLaneData,
};
use bp_runtime::{InstanceId, Size, StorageProofChecker};
use bp_runtime::{ChainId, Size, StorageProofChecker};
use codec::{Decode, Encode};
use frame_support::{traits::Instance, weights::Weight, RuntimeDebug};
use hash_db::Hasher;
Expand All @@ -39,9 +39,6 @@ use sp_trie::StorageProof;

/// Bidirectional message bridge.
pub trait MessageBridge {
/// Instance id of this bridge.
const INSTANCE: InstanceId;

/// Relayer interest (in percents).
const RELAYER_FEE_PERCENT: u32;

Expand All @@ -56,6 +53,9 @@ pub trait MessageBridge {

/// Chain that has `pallet-bridge-messages` and `dispatch` modules.
pub trait ChainWithMessages {
/// Identifier of this chain.
const ID: ChainId;

/// Hash used in the chain.
type Hash: Decode;
/// Accound id on the chain.
Expand Down Expand Up @@ -483,7 +483,8 @@ pub mod target {
fn dispatch(message: DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>) {
let message_id = (message.key.lane_id, message.key.nonce);
pallet_bridge_dispatch::Pallet::<ThisRuntime, ThisDispatchInstance>::dispatch(
B::INSTANCE,
B::BridgedChain::ID,
B::ThisChain::ID,
message_id,
message.data.payload.map_err(drop),
);
Expand Down Expand Up @@ -692,7 +693,6 @@ mod tests {
struct OnThisChainBridge;

impl MessageBridge for OnThisChainBridge {
const INSTANCE: InstanceId = *b"this";
const RELAYER_FEE_PERCENT: u32 = 10;

type ThisChain = ThisChain;
Expand All @@ -708,7 +708,6 @@ mod tests {
struct OnBridgedChainBridge;

impl MessageBridge for OnBridgedChainBridge {
const INSTANCE: InstanceId = *b"brdg";
const RELAYER_FEE_PERCENT: u32 = 20;

type ThisChain = BridgedChain;
Expand Down Expand Up @@ -809,6 +808,8 @@ mod tests {
struct ThisChain;

impl ChainWithMessages for ThisChain {
const ID: ChainId = *b"this";

type Hash = ();
type AccountId = ThisChainAccountId;
type Signer = ThisChainSigner;
Expand Down Expand Up @@ -866,6 +867,8 @@ mod tests {
struct BridgedChain;

impl ChainWithMessages for BridgedChain {
const ID: ChainId = *b"brdg";

type Hash = ();
type AccountId = BridgedChainAccountId;
type Signer = BridgedChainSigner;
Expand Down
Loading

0 comments on commit 0f4245f

Please sign in to comment.