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

Integrate Ethereum::message_transact call from dispatch module #1267

Merged
merged 48 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
741f8f2
A copy-paste version
boundless-forest Jun 8, 2022
f47095b
Adapt for other two places
boundless-forest Jun 9, 2022
854fccc
Simplify the implementation
boundless-forest Jun 9, 2022
eb9b24f
Add evm support
boundless-forest Jun 9, 2022
e874faa
Fix
boundless-forest Jun 9, 2022
3852856
Test updated trait
boundless-forest Jun 9, 2022
bffa1b7
Get the matched value, Thanks Xavier
boundless-forest Jun 9, 2022
5c67cff
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
boundless-forest Jun 10, 2022
d3597b0
Fix compile
boundless-forest Jun 10, 2022
7435077
Impl call filter and into dispatch origin for pangoro
boundless-forest Jun 10, 2022
482a61a
That's a hard one to write
boundless-forest Jun 10, 2022
1c5a8bc
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
boundless-forest Jun 13, 2022
fe4b2d0
Code clean for pangoro mess
boundless-forest Jun 13, 2022
06c5bc6
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
boundless-forest Jun 13, 2022
3449c91
Adapt for pangolin runtime, compile is ok
boundless-forest Jun 13, 2022
b45c2f4
Fix tx validation check
boundless-forest Jun 13, 2022
3ae8454
Fix tx
boundless-forest Jun 13, 2022
2be2623
Fix tx
boundless-forest Jun 13, 2022
885653d
Use patch to dev
boundless-forest Jun 14, 2022
5c48a90
Revert changes
boundless-forest Jun 14, 2022
0d82220
A new version
boundless-forest Jun 14, 2022
1104a1c
Fix compile
boundless-forest Jun 14, 2022
9d3b3c3
Fix tests
boundless-forest Jun 14, 2022
1e39805
Remove useless imports
boundless-forest Jun 14, 2022
7bd2478
Optimal pre_dispatch
boundless-forest Jun 14, 2022
dff1ac9
Add weight check test
boundless-forest Jun 14, 2022
e1dddbc
Rename
boundless-forest Jun 14, 2022
c8618cb
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
boundless-forest Jun 16, 2022
dbf382c
Adapt for changes
boundless-forest Jun 16, 2022
07a8452
Code clean
boundless-forest Jun 16, 2022
8784a2c
Add more test
boundless-forest Jun 16, 2022
1f8e5e0
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
hackfisher Jun 16, 2022
a631b79
Merge branch 'main' into bear-eth-transact
boundless-forest Jun 16, 2022
f2d684d
Forbid payable call
boundless-forest Jun 16, 2022
62ad6e2
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
hackfisher Jun 16, 2022
45c5343
Merge branch 'main' into bear-move-FromBridgedChainMessageDispatch
hackfisher Jun 17, 2022
3315f11
Adapt new trait
boundless-forest Jun 17, 2022
313f6e3
Add todo
boundless-forest Jun 17, 2022
f738983
Add message transact dispatch all, only used by message layer (#1296)
hackfisher Jun 17, 2022
6a59c89
Fix gas limit, and change call from transact to message_transact
hackfisher Jun 17, 2022
ba7b13c
add missing changes
hackfisher Jun 17, 2022
65f210f
check_receiving_before_dispatch and update todos
hackfisher Jun 17, 2022
05ef8d5
Fix dispatch in pangoro runtime
boundless-forest Jun 19, 2022
f7d1e5d
Fix dispatch in pangolin runtime
boundless-forest Jun 19, 2022
af82891
Fix tests
boundless-forest Jun 19, 2022
1f4fad1
Add comments
boundless-forest Jun 19, 2022
e4349b4
Update lock file
boundless-forest Jun 19, 2022
57344c1
fix check (#1297)
hackfisher Jun 20, 2022
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
89 changes: 86 additions & 3 deletions node/runtime/pangolin/src/bridges_message/pangolin_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use frame_support::{
RuntimeDebug,
};
use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128};
use sp_std::ops::RangeInclusive;
use sp_std::{marker::PhantomData, ops::RangeInclusive};
// --- darwinia-network ---
use crate::*;
use bp_messages::{source_chain::*, target_chain::*, *};
use bp_rococo::parachains::ParaId;
use bp_runtime::{ChainId, *};
use bp_runtime::{messages::*, ChainId, *};
use bridge_runtime_common::{
lanes::*,
messages::{
Expand Down Expand Up @@ -68,7 +68,7 @@ pub type ToPangolinParachainMessageVerifier = FromThisChainMessageVerifier<
pub type FromPangolinParachainEncodedCall = FromBridgedChainEncodedMessageCall<Call>;

/// Call-dispatch based message dispatch for PangolinParachain -> Pangolin messages.
pub type FromPangolinParachainMessageDispatch = FromBridgedChainMessageDispatch<
pub type FromPangolinParachainMessageDispatch = DarwiniaFromBridgedChainMessageDispatch<
WithPangolinParachainMessageBridge,
Runtime,
Ring,
Expand Down Expand Up @@ -272,3 +272,86 @@ impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for PangolinParacha
>(ParaId(PANGOLIN_PARACHAIN_ID), proof, messages_count)
}
}

/// Dispatching Bridged -> This chain messages.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct DarwiniaFromBridgedChainMessageDispatch<
B,
ThisRuntime,
ThisCurrency,
ThisDispatchInstance,
> {
_marker: PhantomData<(B, ThisRuntime, ThisCurrency, ThisDispatchInstance)>,
}

use bridge_runtime_common::messages::AccountIdOf;
use frame_support::{
traits::{Currency, ExistenceRequirement},
weights::WeightToFeePolynomial,
};
use sp_runtime::{traits::Saturating, FixedPointOperand};
// use bp_message_dispatch::MessageDispatch;
use bp_message_dispatch::MessageDispatch as _;
use bp_runtime::messages::MessageDispatchResult;

impl<B: MessageBridge, ThisRuntime, ThisCurrency, ThisDispatchInstance>
MessageDispatch<AccountIdOf<ThisChain<B>>, BalanceOf<BridgedChain<B>>>
for DarwiniaFromBridgedChainMessageDispatch<B, ThisRuntime, ThisCurrency, ThisDispatchInstance>
where
BalanceOf<ThisChain<B>>: Saturating + FixedPointOperand,
ThisDispatchInstance: 'static,
ThisRuntime: pallet_bridge_dispatch::Config<
ThisDispatchInstance,
BridgeMessageId = (LaneId, MessageNonce),
> + pallet_transaction_payment::Config,
<ThisRuntime as pallet_transaction_payment::Config>::OnChargeTransaction:
pallet_transaction_payment::OnChargeTransaction<
ThisRuntime,
Balance = BalanceOf<ThisChain<B>>,
>,
ThisCurrency: Currency<AccountIdOf<ThisChain<B>>, Balance = BalanceOf<ThisChain<B>>>,
pallet_bridge_dispatch::Pallet<ThisRuntime, ThisDispatchInstance>:
bp_message_dispatch::MessageDispatch<
AccountIdOf<ThisChain<B>>,
(LaneId, MessageNonce),
Message = FromBridgedChainMessagePayload<B>,
>,
{
type DispatchPayload = FromBridgedChainMessagePayload<B>;

fn dispatch_weight(
message: &DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
) -> frame_support::weights::Weight {
message.data.payload.as_ref().map(|payload| payload.weight).unwrap_or(0)
}

fn dispatch(
relayer_account: &AccountIdOf<ThisChain<B>>,
message: DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
) -> MessageDispatchResult {
let message_id = (message.key.lane_id, message.key.nonce);
pallet_bridge_dispatch::Pallet::<ThisRuntime, ThisDispatchInstance>::dispatch(
B::BRIDGED_CHAIN_ID,
B::THIS_CHAIN_ID,
message_id,
message.data.payload.map_err(drop),
|dispatch_origin, dispatch_weight| {
let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight);
let fee_multiplier =
pallet_transaction_payment::Pallet::<ThisRuntime>::next_fee_multiplier();
let adjusted_weight_fee = fee_multiplier.saturating_mul_int(unadjusted_weight_fee);
if !adjusted_weight_fee.is_zero() {
ThisCurrency::transfer(
dispatch_origin,
relayer_account,
adjusted_weight_fee,
ExistenceRequirement::AllowDeath,
)
.map_err(drop)
} else {
Ok(())
}
},
)
}
}
95 changes: 92 additions & 3 deletions node/runtime/pangolin/src/bridges_message/pangoro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_support::{
RuntimeDebug,
};
use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128};
use sp_std::{convert::TryFrom, ops::RangeInclusive};
use sp_std::{convert::TryFrom, marker::PhantomData, ops::RangeInclusive};
// --- darwinia-network ---
use crate::*;
use bp_message_dispatch::CallOrigin;
Expand Down Expand Up @@ -64,8 +64,14 @@ pub type ToPangoroMessageVerifier =
pub type FromPangoroEncodedCall = FromBridgedChainEncodedMessageCall<Call>;

/// Call-dispatch based message dispatch for Pangoro -> Pangolin messages.
pub type FromPangoroMessageDispatch =
FromBridgedChainMessageDispatch<WithPangoroMessageBridge, Runtime, Ring, WithPangoroDispatch>;
// pub type FromPangoroMessageDispatch =
// FromBridgedChainMessageDispatch<WithPangoroMessageBridge, Runtime, Ring, WithPangoroDispatch>;
pub type FromPangoroMessageDispatch = DarwiniaFromBridgedChainMessageDispatch<
WithPangoroMessageBridge,
Runtime,
Ring,
WithPangoroDispatch,
>;

/// The s2s backing pallet index in the pangoro chain runtime.
pub const PANGORO_S2S_BACKING_PALLET_INDEX: u8 = 20;
Expand Down Expand Up @@ -301,3 +307,86 @@ impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Pangoro {
)
}
}

/// Dispatching Bridged -> This chain messages.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct DarwiniaFromBridgedChainMessageDispatch<
B,
ThisRuntime,
ThisCurrency,
ThisDispatchInstance,
> {
_marker: PhantomData<(B, ThisRuntime, ThisCurrency, ThisDispatchInstance)>,
}

use bridge_runtime_common::messages::AccountIdOf;
use frame_support::{
traits::{Currency, ExistenceRequirement},
weights::WeightToFeePolynomial,
};
use sp_runtime::{traits::Saturating, FixedPointOperand};
// use bp_message_dispatch::MessageDispatch;
use bp_message_dispatch::MessageDispatch as _;
use bp_messages::target_chain::MessageDispatch;

impl<B: MessageBridge, ThisRuntime, ThisCurrency, ThisDispatchInstance>
MessageDispatch<AccountIdOf<ThisChain<B>>, BalanceOf<BridgedChain<B>>>
for DarwiniaFromBridgedChainMessageDispatch<B, ThisRuntime, ThisCurrency, ThisDispatchInstance>
where
BalanceOf<ThisChain<B>>: Saturating + FixedPointOperand,
ThisDispatchInstance: 'static,
ThisRuntime: pallet_bridge_dispatch::Config<
ThisDispatchInstance,
BridgeMessageId = (LaneId, MessageNonce),
> + pallet_transaction_payment::Config,
<ThisRuntime as pallet_transaction_payment::Config>::OnChargeTransaction:
pallet_transaction_payment::OnChargeTransaction<
ThisRuntime,
Balance = BalanceOf<ThisChain<B>>,
>,
ThisCurrency: Currency<AccountIdOf<ThisChain<B>>, Balance = BalanceOf<ThisChain<B>>>,
pallet_bridge_dispatch::Pallet<ThisRuntime, ThisDispatchInstance>:
bp_message_dispatch::MessageDispatch<
AccountIdOf<ThisChain<B>>,
(LaneId, MessageNonce),
Message = FromBridgedChainMessagePayload<B>,
>,
{
type DispatchPayload = FromBridgedChainMessagePayload<B>;

fn dispatch_weight(
message: &DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
) -> frame_support::weights::Weight {
message.data.payload.as_ref().map(|payload| payload.weight).unwrap_or(0)
}

fn dispatch(
relayer_account: &AccountIdOf<ThisChain<B>>,
message: DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
) -> MessageDispatchResult {
let message_id = (message.key.lane_id, message.key.nonce);
pallet_bridge_dispatch::Pallet::<ThisRuntime, ThisDispatchInstance>::dispatch(
B::BRIDGED_CHAIN_ID,
B::THIS_CHAIN_ID,
message_id,
message.data.payload.map_err(drop),
|dispatch_origin, dispatch_weight| {
let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight);
let fee_multiplier =
pallet_transaction_payment::Pallet::<ThisRuntime>::next_fee_multiplier();
let adjusted_weight_fee = fee_multiplier.saturating_mul_int(unadjusted_weight_fee);
if !adjusted_weight_fee.is_zero() {
ThisCurrency::transfer(
dispatch_origin,
relayer_account,
adjusted_weight_fee,
ExistenceRequirement::AllowDeath,
)
.map_err(drop)
} else {
Ok(())
}
},
)
}
}
158 changes: 155 additions & 3 deletions node/runtime/pangoro/src/bridges_message/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_support::{
RuntimeDebug,
};
use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128};
use sp_std::{convert::TryFrom, ops::RangeInclusive};
use sp_std::{convert::TryFrom, marker::PhantomData, ops::RangeInclusive};
// --- darwinia-network ---
use crate::*;
use bp_message_dispatch::CallOrigin;
Expand Down Expand Up @@ -64,8 +64,12 @@ pub type ToPangolinMessageVerifier =
pub type FromPangolinEncodedCall = FromBridgedChainEncodedMessageCall<Call>;

/// Call-dispatch based message dispatch for Pangolin -> Pangoro messages.
pub type FromPangolinMessageDispatch =
FromBridgedChainMessageDispatch<WithPangolinMessageBridge, Runtime, Ring, WithPangolinDispatch>;
// pub type FromPangolinMessageDispatch = DarwiniaFromBridgedChainMessageDispatch<
// WithPangolinMessageBridge,
// Runtime,
// Ring,
// WithPangolinDispatch,
// >;

/// The s2s issuing pallet index in the pangolin chain runtime
pub const PANGOLIN_S2S_ISSUING_PALLET_INDEX: u8 = 49;
Expand Down Expand Up @@ -303,3 +307,151 @@ impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Pangolin {
)
}
}

// pub type FromPangolinMessageDispatch = DarwiniaFromBridgedChainMessageDispatch<
// WithPangolinMessageBridge,
// Runtime,
// Ring,
// WithPangolinDispatch,
// >;

/// Dispatching Bridged -> This chain messages.
// #[derive(RuntimeDebug, Clone, Copy)]
// pub struct DarwiniaFromBridgedChainMessageDispatch<
// B,
// ThisRuntime,
// ThisCurrency,
// ThisDispatchInstance,
// > {
// _marker: PhantomData<(B, ThisRuntime, ThisCurrency, ThisDispatchInstance)>,
// }

// use bridge_runtime_common::messages::AccountIdOf;
// use frame_support::{
// traits::{Currency, ExistenceRequirement},
// weights::WeightToFeePolynomial,
// };
// use sp_runtime::{traits::Saturating, FixedPointOperand};
// // use bp_message_dispatch::MessageDispatch;
// use bp_message_dispatch::MessageDispatch as _;
// use bp_messages::target_chain::MessageDispatch;

// impl<B: MessageBridge, ThisRuntime, ThisCurrency, ThisDispatchInstance>
// MessageDispatch<AccountIdOf<ThisChain<B>>, BalanceOf<BridgedChain<B>>>
// for DarwiniaFromBridgedChainMessageDispatch<B, ThisRuntime, ThisCurrency,
// ThisDispatchInstance> where
// BalanceOf<ThisChain<B>>: Saturating + FixedPointOperand,
// ThisDispatchInstance: 'static,
// ThisRuntime: pallet_bridge_dispatch::Config<
// ThisDispatchInstance,
// BridgeMessageId = (LaneId, MessageNonce),
// > + pallet_transaction_payment::Config,
// <ThisRuntime as pallet_transaction_payment::Config>::OnChargeTransaction:
// pallet_transaction_payment::OnChargeTransaction<
// ThisRuntime,
// Balance = BalanceOf<ThisChain<B>>,
// >,
// ThisCurrency: Currency<AccountIdOf<ThisChain<B>>, Balance = BalanceOf<ThisChain<B>>>,
// pallet_bridge_dispatch::Pallet<ThisRuntime, ThisDispatchInstance>:
// bp_message_dispatch::MessageDispatch<
// AccountIdOf<ThisChain<B>>,
// (LaneId, MessageNonce),
// Message = FromBridgedChainMessagePayload<B>,
// >,
// {
// type DispatchPayload = FromBridgedChainMessagePayload<B>;

// fn dispatch_weight(
// message: &DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
// ) -> frame_support::weights::Weight {
// message.data.payload.as_ref().map(|payload| payload.weight).unwrap_or(0)
// }

// fn dispatch(
// relayer_account: &AccountIdOf<ThisChain<B>>,
// message: DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>,
// ) -> MessageDispatchResult {
// let message_id = (message.key.lane_id, message.key.nonce);
// pallet_bridge_dispatch::Pallet::<ThisRuntime, ThisDispatchInstance>::dispatch(
// B::BRIDGED_CHAIN_ID,
// B::THIS_CHAIN_ID,
// message_id,
// message.data.payload.map_err(drop),
// |dispatch_origin, dispatch_weight| {
// let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight);
// let fee_multiplier =
// pallet_transaction_payment::Pallet::<ThisRuntime>::next_fee_multiplier();
// let adjusted_weight_fee = fee_multiplier.saturating_mul_int(unadjusted_weight_fee);
// if !adjusted_weight_fee.is_zero() {
// ThisCurrency::transfer(
// dispatch_origin,
// relayer_account,
// adjusted_weight_fee,
// ExistenceRequirement::AllowDeath,
// )
// .map_err(drop)
// } else {
// Ok(())
// }
// },
// )
// }
// }

// Dispatching Bridged -> This chain messages.
use bridge_runtime_common::messages::AccountIdOf;
use frame_support::{
traits::{Currency, ExistenceRequirement},
weights::WeightToFeePolynomial,
};
use sp_runtime::{traits::Saturating, FixedPointOperand};
// use bp_message_dispatch::MessageDispatch;
use bp_message_dispatch::MessageDispatch as _;
use bp_messages::target_chain::MessageDispatch;
use sp_runtime::MultiAddress;

#[derive(RuntimeDebug, Clone, Copy)]
pub struct FromPangolinMessageDispatch;
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved

impl MessageDispatch<bp_pangoro::AccountId, BalanceOf<Pangolin>> for FromPangolinMessageDispatch {
type DispatchPayload = FromPangolinMessagePayload;

fn dispatch_weight(
message: &DispatchMessage<Self::DispatchPayload, BalanceOf<Pangolin>>,
) -> frame_support::weights::Weight {
message.data.payload.as_ref().map(|payload| payload.weight).unwrap_or(0)
}

fn dispatch(
relayer_account: &bp_pangoro::AccountId,
message: DispatchMessage<Self::DispatchPayload, BalanceOf<Pangolin>>,
) -> MessageDispatchResult {
let message_id = (message.key.lane_id, message.key.nonce);
pallet_bridge_dispatch::Pallet::<Runtime, WithPangolinDispatch>::dispatch(
PANGOLIN_CHAIN_ID,
PANGORO_CHAIN_ID,
message_id,
message.data.payload.map_err(drop),
|dispatch_origin, dispatch_weight| {
let unadjusted_weight_fee =
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
&dispatch_weight,
);
let fee_multiplier =
pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier();
let adjusted_weight_fee = fee_multiplier.saturating_mul_int(unadjusted_weight_fee);
if !adjusted_weight_fee.is_zero() {
Ring::transfer(
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
Origin::signed(dispatch_origin.clone()),
MultiAddress::Id(relayer_account.clone()),
adjusted_weight_fee,
)
.map(|_| ())
.map_err(drop)
} else {
Ok(())
}
},
)
}
}