diff --git a/bridges/bin/millau/runtime/Cargo.toml b/bridges/bin/millau/runtime/Cargo.toml index a1619d4d8d..271ff3cc98 100644 --- a/bridges/bin/millau/runtime/Cargo.toml +++ b/bridges/bin/millau/runtime/Cargo.toml @@ -23,6 +23,7 @@ bridge-runtime-common = { path = "../../runtime-common", default-features = fals pallet-bridge-dispatch = { path = "../../../modules/dispatch", default-features = false } pallet-bridge-grandpa = { path = "../../../modules/grandpa", default-features = false } pallet-bridge-messages = { path = "../../../modules/messages", default-features = false } +pallet-bridge-token-swap = { path = "../../../modules/token-swap", default-features = false } pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false } # Substrate Dependencies @@ -77,6 +78,7 @@ std = [ "pallet-bridge-dispatch/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", + "pallet-bridge-token-swap/std", "pallet-grandpa/std", "pallet-randomness-collective-flip/std", "pallet-session/std", diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index 7469ebfec1..f02e257730 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -362,7 +362,7 @@ parameter_types! { pub const GetDeliveryConfirmationTransactionFee: Balance = bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT as _; pub const RootAccountForPayments: Option = None; - pub const BridgedChainId: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID; + pub const RialtoChainId: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID; } /// Instance of the messages pallet used to relay messages to/from Rialto chain. @@ -394,11 +394,31 @@ impl pallet_bridge_messages::Config for Runtime { GetDeliveryConfirmationTransactionFee, RootAccountForPayments, >; - type OnDeliveryConfirmed = (); + type OnDeliveryConfirmed = pallet_bridge_token_swap::Pallet; type SourceHeaderChain = crate::rialto_messages::Rialto; type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch; - type BridgedChainId = BridgedChainId; + type BridgedChainId = RialtoChainId; +} + +parameter_types! { + pub const TokenSwapMessagesLane: bp_messages::LaneId = *b"swap"; +} + +/// Instance of the with-Rialto token swap pallet. +pub type WithRialtoTokenSwapInstance = (); + +impl pallet_bridge_token_swap::Config for Runtime { + type Event = Event; + + type BridgedChainId = RialtoChainId; + type OutboundMessageLaneId = TokenSwapMessagesLane; + type MessagesBridge = pallet_bridge_messages::Pallet; + type ThisCurrency = pallet_balances::Pallet; + type FromSwapToThisAccountIdConverter = bp_rialto::AccountIdConverter; + + type BridgedChain = bp_rialto::Rialto; + type FromBridgedToThisAccountIdConverter = bp_millau::AccountIdConverter; } construct_runtime!( @@ -407,20 +427,30 @@ construct_runtime!( NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { - BridgeRialtoMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event, Config}, - BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event}, - BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, - BridgeWestendGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Config, Storage}, System: frame_system::{Pallet, Call, Config, Storage, Event}, - RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event}, + + // Must be before session. Aura: pallet_aura::{Pallet, Config}, - Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, + + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, - Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event}, + + // Consensus support. Session: pallet_session::{Pallet, Call, Storage, Event, Config}, + Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, ShiftSessionManager: pallet_shift_session_manager::{Pallet}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, + + // Rialto bridge modules. + BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, + BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event}, + BridgeRialtoMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event, Config}, + BridgeRialtoTokenSwap: pallet_bridge_token_swap::{Pallet, Call, Storage, Event}, + + // Westend bridge modules. + BridgeWestendGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Config, Storage}, } ); diff --git a/bridges/bin/millau/runtime/src/rialto_messages.rs b/bridges/bin/millau/runtime/src/rialto_messages.rs index 34b3b231c8..1bc15caa10 100644 --- a/bridges/bin/millau/runtime/src/rialto_messages.rs +++ b/bridges/bin/millau/runtime/src/rialto_messages.rs @@ -108,7 +108,7 @@ impl messages::ThisChainWithMessages for Millau { type Call = crate::Call; fn is_outbound_lane_enabled(lane: &LaneId) -> bool { - *lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1] + *lane == [0, 0, 0, 0] || *lane == [0, 0, 0, 1] || *lane == crate::TokenSwapMessagesLane::get() } fn maximal_pending_messages_at_outbound_lane() -> MessageNonce { diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 2d55a84518..335cc7f960 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -56,7 +56,11 @@ use bp_messages::{ }; use bp_runtime::{ChainId, Size}; use codec::{Decode, Encode}; -use frame_support::{fail, traits::Get, weights::PostDispatchInfo}; +use frame_support::{ + fail, + traits::Get, + weights::{Pays, PostDispatchInfo}, +}; use frame_system::RawOrigin; use num_traits::{SaturatingAdd, Zero}; use sp_runtime::traits::BadOrigin; @@ -241,94 +245,13 @@ pub mod pallet { payload: T::OutboundPayload, delivery_and_dispatch_fee: T::OutboundMessageFee, ) -> DispatchResultWithPostInfo { - ensure_normal_operating_mode::()?; - let submitter = origin.into().map_err(|_| BadOrigin)?; - - // initially, actual (post-dispatch) weight is equal to pre-dispatch weight - let mut actual_weight = T::WeightInfo::send_message_weight(&payload); - - // let's first check if message can be delivered to target chain - T::TargetHeaderChain::verify_message(&payload).map_err(|err| { - log::trace!( - target: "runtime::bridge-messages", - "Message to lane {:?} is rejected by target chain: {:?}", - lane_id, - err, - ); - - Error::::MessageRejectedByChainVerifier - })?; - - // now let's enforce any additional lane rules - let mut lane = outbound_lane::(lane_id); - T::LaneMessageVerifier::verify_message( - &submitter, - &delivery_and_dispatch_fee, - &lane_id, - &lane.data(), - &payload, - ) - .map_err(|err| { - log::trace!( - target: "runtime::bridge-messages", - "Message to lane {:?} is rejected by lane verifier: {:?}", - lane_id, - err, - ); - - Error::::MessageRejectedByLaneVerifier - })?; - - // let's withdraw delivery and dispatch fee from submitter - T::MessageDeliveryAndDispatchPayment::pay_delivery_and_dispatch_fee( - &submitter, - &delivery_and_dispatch_fee, - &Self::relayer_fund_account_id(), - ) - .map_err(|err| { - log::trace!( - target: "runtime::bridge-messages", - "Message to lane {:?} is rejected because submitter {:?} is unable to pay fee {:?}: {:?}", - lane_id, - submitter, - delivery_and_dispatch_fee, - err, - ); - - Error::::FailedToWithdrawMessageFee - })?; - - // finally, save message in outbound storage and emit event - let encoded_payload = payload.encode(); - let encoded_payload_len = encoded_payload.len(); - let nonce = lane.send_message(MessageData { - payload: encoded_payload, - fee: delivery_and_dispatch_fee, - }); - - // message sender pays for pruning at most `MaxMessagesToPruneAtOnce` messages - // the cost of pruning every message is roughly single db write - // => lets refund sender if less than `MaxMessagesToPruneAtOnce` messages pruned - let max_messages_to_prune = T::MaxMessagesToPruneAtOnce::get(); - let pruned_messages = lane.prune_messages(max_messages_to_prune); - if let Some(extra_messages) = max_messages_to_prune.checked_sub(pruned_messages) { - actual_weight = actual_weight.saturating_sub(T::DbWeight::get().writes(extra_messages)); - } - - log::trace!( - target: "runtime::bridge-messages", - "Accepted message {} to lane {:?}. Message size: {:?}", - nonce, + crate::send_message::( + origin.into().map_err(|_| BadOrigin)?, lane_id, - encoded_payload_len, - ); - - Self::deposit_event(Event::MessageAccepted(lane_id, nonce)); - - Ok(PostDispatchInfo { - actual_weight: Some(actual_weight), - pays_fee: Pays::Yes, - }) + payload, + delivery_and_dispatch_fee, + ) + .map(|sent_message| sent_message.post_dispatch_info) } /// Pay additional fee for the message. @@ -899,6 +822,126 @@ pub mod storage_keys { } } +impl bp_messages::source_chain::MessagesBridge + for Pallet +where + T: Config, + I: 'static, +{ + type Error = sp_runtime::DispatchErrorWithPostInfo; + + fn send_message( + sender: bp_messages::source_chain::Sender, + lane: LaneId, + message: T::OutboundPayload, + delivery_and_dispatch_fee: T::OutboundMessageFee, + ) -> Result { + crate::send_message::(sender, lane, message, delivery_and_dispatch_fee) + .map(|sent_message| sent_message.nonce) + } +} + +/// Message that has been sent. +struct SentMessage { + /// Nonce of the message. + pub nonce: MessageNonce, + /// Post-dispatch call info. + pub post_dispatch_info: PostDispatchInfo, +} + +/// Function that actually sends message. +fn send_message, I: 'static>( + submitter: bp_messages::source_chain::Sender, + lane_id: LaneId, + payload: T::OutboundPayload, + delivery_and_dispatch_fee: T::OutboundMessageFee, +) -> sp_std::result::Result> { + ensure_normal_operating_mode::()?; + + // initially, actual (post-dispatch) weight is equal to pre-dispatch weight + let mut actual_weight = T::WeightInfo::send_message_weight(&payload); + + // let's first check if message can be delivered to target chain + T::TargetHeaderChain::verify_message(&payload).map_err(|err| { + log::trace!( + target: "runtime::bridge-messages", + "Message to lane {:?} is rejected by target chain: {:?}", + lane_id, + err, + ); + + Error::::MessageRejectedByChainVerifier + })?; + + // now let's enforce any additional lane rules + let mut lane = outbound_lane::(lane_id); + T::LaneMessageVerifier::verify_message(&submitter, &delivery_and_dispatch_fee, &lane_id, &lane.data(), &payload) + .map_err(|err| { + log::trace!( + target: "runtime::bridge-messages", + "Message to lane {:?} is rejected by lane verifier: {:?}", + lane_id, + err, + ); + + Error::::MessageRejectedByLaneVerifier + })?; + + // let's withdraw delivery and dispatch fee from submitter + T::MessageDeliveryAndDispatchPayment::pay_delivery_and_dispatch_fee( + &submitter, + &delivery_and_dispatch_fee, + &Pallet::::relayer_fund_account_id(), + ) + .map_err(|err| { + log::trace!( + target: "runtime::bridge-messages", + "Message to lane {:?} is rejected because submitter {:?} is unable to pay fee {:?}: {:?}", + lane_id, + submitter, + delivery_and_dispatch_fee, + err, + ); + + Error::::FailedToWithdrawMessageFee + })?; + + // finally, save message in outbound storage and emit event + let encoded_payload = payload.encode(); + let encoded_payload_len = encoded_payload.len(); + let nonce = lane.send_message(MessageData { + payload: encoded_payload, + fee: delivery_and_dispatch_fee, + }); + + // message sender pays for pruning at most `MaxMessagesToPruneAtOnce` messages + // the cost of pruning every message is roughly single db write + // => lets refund sender if less than `MaxMessagesToPruneAtOnce` messages pruned + let max_messages_to_prune = T::MaxMessagesToPruneAtOnce::get(); + let pruned_messages = lane.prune_messages(max_messages_to_prune); + if let Some(extra_messages) = max_messages_to_prune.checked_sub(pruned_messages) { + actual_weight = actual_weight.saturating_sub(T::DbWeight::get().writes(extra_messages)); + } + + log::trace!( + target: "runtime::bridge-messages", + "Accepted message {} to lane {:?}. Message size: {:?}", + nonce, + lane_id, + encoded_payload_len, + ); + + Pallet::::deposit_event(Event::MessageAccepted(lane_id, nonce)); + + Ok(SentMessage { + nonce, + post_dispatch_info: PostDispatchInfo { + actual_weight: Some(actual_weight), + pays_fee: Pays::Yes, + }, + }) +} + /// Ensure that the origin is either root, or `PalletOwner`. fn ensure_owner_or_root, I: 'static>(origin: T::Origin) -> Result<(), BadOrigin> { match origin.into() { diff --git a/bridges/modules/token-swap/Cargo.toml b/bridges/modules/token-swap/Cargo.toml index bf3411ec06..0266fd51f7 100644 --- a/bridges/modules/token-swap/Cargo.toml +++ b/bridges/modules/token-swap/Cargo.toml @@ -26,7 +26,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "mast sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [dev-dependencies] pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bridges/modules/token-swap/src/lib.rs b/bridges/modules/token-swap/src/lib.rs index 206f040b96..3216c69029 100644 --- a/bridges/modules/token-swap/src/lib.rs +++ b/bridges/modules/token-swap/src/lib.rs @@ -49,6 +49,8 @@ //! While swap is pending, the `source_balance_at_this_chain` tokens are owned by the special //! temporary `swap_account_at_this_chain` account. It is destroyed upon swap completion. +#![cfg_attr(not(feature = "std"), no_std)] + use bp_messages::{ source_chain::{MessagesBridge, OnDeliveryConfirmed}, DeliveredMessages, LaneId, MessageNonce, @@ -64,6 +66,7 @@ use frame_support::{ use sp_core::H256; use sp_io::hashing::blake2_256; use sp_runtime::traits::{Convert, Saturating}; +use sp_std::vec::Vec; #[cfg(test)] mod mock; @@ -98,7 +101,7 @@ pub mod pallet { type Event: From> + IsType<::Event>; /// Id of the bridge with the Bridged chain. - type BridgeChainId: Get; + type BridgedChainId: Get; /// The identifier of outbound message lane on This chain used to send token transfer /// messages to the Bridged chain. /// @@ -114,8 +117,6 @@ pub mod pallet { >::Balance, MessagePayloadOf, >; - /// Message delivery and dispatch fee for the tokens transfer message heading to the Bridged chain. - type MessageDeliveryAndDispatchFee: Get<>::Balance>; /// This chain Currency used in the tokens swap. type ThisCurrency: Currency; @@ -128,6 +129,10 @@ pub mod pallet { type FromBridgedToThisAccountIdConverter: Convert; } + /// Tokens balance at This chain. + pub type ThisChainBalance = + <>::ThisCurrency as Currency<::AccountId>>::Balance; + /// Type of the Bridged chain. pub type BridgedChainOf = >::BridgedChain; /// Tokens balance type at the Bridged chain. @@ -151,7 +156,7 @@ pub mod pallet { /// Type of `TokenSwap` used by the pallet. pub type TokenSwapOf = TokenSwap< BlockNumberFor, - <>::ThisCurrency as Currency<::AccountId>>::Balance, + ThisChainBalance, ::AccountId, BridgedBalanceOf, BridgedAccountIdOf, @@ -203,6 +208,7 @@ pub mod pallet { origin: OriginFor, swap: TokenSwapOf, target_public_at_bridged_chain: BridgedAccountPublicOf, + swap_delivery_and_dispatch_fee: ThisChainBalance, bridged_chain_spec_version: u32, bridged_currency_transfer: RawBridgedTransferCall, bridged_currency_transfer_weight: Weight, @@ -239,13 +245,12 @@ pub mod pallet { let swap_account = swap_account_id::(&swap); frame_support::storage::with_transaction(|| { // funds are transferred from This account to the temporary Swap account - let message_delivery_and_dispatch_fee = T::MessageDeliveryAndDispatchFee::get(); let transfer_result = T::ThisCurrency::transfer( &swap.source_account_at_this_chain, &swap_account, // saturating_add is ok, or we have the chain where single holder owns all tokens swap.source_balance_at_this_chain - .saturating_add(message_delivery_and_dispatch_fee), + .saturating_add(swap_delivery_and_dispatch_fee), // if we'll allow account to die, then he'll be unable to `cancel_claim` // if something won't work ExistenceRequirement::KeepAlive, @@ -268,7 +273,7 @@ pub mod pallet { // `Currency::transfer` call on the bridged chain, but no checks are made - it is // the transaction submitter to ensure it is valid. let send_message_result = T::MessagesBridge::send_message( - swap_account.clone(), + bp_messages::source_chain::Sender::from(Some(swap_account.clone())), T::OutboundMessageLaneId::get(), bp_message_dispatch::MessagePayload { spec_version: bridged_chain_spec_version, @@ -281,7 +286,7 @@ pub mod pallet { dispatch_fee_payment: DispatchFeePayment::AtTargetChain, call: bridged_currency_transfer, }, - message_delivery_and_dispatch_fee, + swap_delivery_and_dispatch_fee, ); let transfer_message_nonce = match send_message_result { Ok(transfer_message_nonce) => transfer_message_nonce, @@ -493,7 +498,7 @@ pub mod pallet { /// Expected target account representation on This chain (aka `target_account_at_this_chain`). pub(crate) fn target_account_at_this_chain, I: 'static>(swap: &TokenSwapOf) -> T::AccountId { T::FromBridgedToThisAccountIdConverter::convert(bp_runtime::derive_account_id( - T::BridgeChainId::get(), + T::BridgedChainId::get(), bp_runtime::SourceAccount::Account(swap.target_account_at_bridged_chain.clone()), )) } @@ -584,6 +589,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -606,6 +612,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT + 1), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -626,6 +633,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), swap, bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -646,6 +654,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), swap, bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -666,6 +675,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, transfer, BRIDGED_CHAIN_CALL_WEIGHT, @@ -683,6 +693,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -694,6 +705,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -713,6 +725,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -731,6 +744,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -749,6 +763,7 @@ mod tests { Origin::signed(THIS_CHAIN_ACCOUNT), test_swap(), bridged_chain_account_public(), + SWAP_DELIVERY_AND_DISPATCH_FEE, BRIDGED_CHAIN_SPEC_VERSION, test_transfer(), BRIDGED_CHAIN_CALL_WEIGHT, @@ -763,7 +778,7 @@ mod tests { assert_eq!(PendingMessages::::get(MESSAGE_NONCE), Some(swap_hash)); assert_eq!( pallet_balances::Pallet::::free_balance(&swap_account_id::(&test_swap())), - test_swap().source_balance_at_this_chain + MessageDeliveryAndDispatchFee::get(), + test_swap().source_balance_at_this_chain + SWAP_DELIVERY_AND_DISPATCH_FEE, ); assert!( frame_system::Pallet::::events() @@ -989,7 +1004,7 @@ mod tests { ); assert_eq!( pallet_balances::Pallet::::free_balance(&THIS_CHAIN_ACCOUNT), - THIS_CHAIN_ACCOUNT_BALANCE - MessageDeliveryAndDispatchFee::get(), + THIS_CHAIN_ACCOUNT_BALANCE - SWAP_DELIVERY_AND_DISPATCH_FEE, ); assert!( frame_system::Pallet::::events() diff --git a/bridges/modules/token-swap/src/mock.rs b/bridges/modules/token-swap/src/mock.rs index 603db2adec..c95f413b72 100644 --- a/bridges/modules/token-swap/src/mock.rs +++ b/bridges/modules/token-swap/src/mock.rs @@ -43,6 +43,8 @@ pub const MESSAGE_NONCE: MessageNonce = 3; pub const THIS_CHAIN_ACCOUNT: AccountId = 1; pub const THIS_CHAIN_ACCOUNT_BALANCE: Balance = 100_000; +pub const SWAP_DELIVERY_AND_DISPATCH_FEE: Balance = 1; + frame_support::construct_runtime! { pub enum TestRuntime where Block = Block, @@ -106,18 +108,16 @@ impl pallet_balances::Config for TestRuntime { } frame_support::parameter_types! { - pub const BridgeChainId: ChainId = *b"inst"; + pub const BridgedChainId: ChainId = *b"inst"; pub const OutboundMessageLaneId: LaneId = *b"lane"; - pub const MessageDeliveryAndDispatchFee: Balance = 1; } impl pallet_bridge_token_swap::Config for TestRuntime { type Event = Event; - type BridgeChainId = BridgeChainId; + type BridgedChainId = BridgedChainId; type OutboundMessageLaneId = OutboundMessageLaneId; type MessagesBridge = TestMessagesBridge; - type MessageDeliveryAndDispatchFee = MessageDeliveryAndDispatchFee; type ThisCurrency = pallet_balances::Pallet; type FromSwapToThisAccountIdConverter = TestAccountConverter; @@ -146,14 +146,14 @@ impl MessagesBridge> for T type Error = (); fn send_message( - sender: AccountId, + sender: frame_system::RawOrigin, lane: LaneId, message: MessagePayloadOf, delivery_and_dispatch_fee: Balance, ) -> Result { - assert_ne!(sender, THIS_CHAIN_ACCOUNT); + assert_ne!(sender, frame_system::RawOrigin::Signed(THIS_CHAIN_ACCOUNT)); assert_eq!(lane, OutboundMessageLaneId::get()); - assert_eq!(delivery_and_dispatch_fee, MessageDeliveryAndDispatchFee::get()); + assert_eq!(delivery_and_dispatch_fee, SWAP_DELIVERY_AND_DISPATCH_FEE); match message.call[0] { OK_TRANSFER_CALL => Ok(MESSAGE_NONCE), BAD_TRANSFER_CALL => Err(()), diff --git a/bridges/primitives/messages/src/source_chain.rs b/bridges/primitives/messages/src/source_chain.rs index 03bd67a03f..3b84562e9b 100644 --- a/bridges/primitives/messages/src/source_chain.rs +++ b/bridges/primitives/messages/src/source_chain.rs @@ -136,7 +136,7 @@ pub trait MessagesBridge { /// /// Returns unique message nonce or error if send has failed. fn send_message( - sender: AccountId, + sender: Sender, lane: LaneId, message: Payload, delivery_and_dispatch_fee: Balance, diff --git a/bridges/primitives/token-swap/src/lib.rs b/bridges/primitives/token-swap/src/lib.rs index 5509d2b72c..afdaa2497e 100644 --- a/bridges/primitives/token-swap/src/lib.rs +++ b/bridges/primitives/token-swap/src/lib.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +#![cfg_attr(not(feature = "std"), no_std)] + use codec::{Decode, Encode}; use frame_support::RuntimeDebug; use sp_core::U256; diff --git a/bridges/relays/bin-substrate/src/cli/encode_message.rs b/bridges/relays/bin-substrate/src/cli/encode_message.rs index d002ab28f4..a2e049f24f 100644 --- a/bridges/relays/bin-substrate/src/cli/encode_message.rs +++ b/bridges/relays/bin-substrate/src/cli/encode_message.rs @@ -102,6 +102,6 @@ mod tests { let hex = encode_message.encode().unwrap(); // then - assert_eq!(format!("{:?}", hex), "0x01000000b0d60f000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c040130000000000000000000000000"); + assert_eq!(format!("{:?}", hex), "0x01000000b0d60f000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c000130000000000000000000000000"); } } diff --git a/bridges/relays/bin-substrate/src/cli/send_message.rs b/bridges/relays/bin-substrate/src/cli/send_message.rs index 66c2f17755..68b332b069 100644 --- a/bridges/relays/bin-substrate/src/cli/send_message.rs +++ b/bridges/relays/bin-substrate/src/cli/send_message.rs @@ -323,7 +323,7 @@ mod tests { weight: 1038000, origin: CallOrigin::SourceAccount(sp_keyring::AccountKeyring::Alice.to_account_id()), dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtSourceChain, - call: hex!("0401081234").to_vec(), + call: hex!("0001081234").to_vec(), } ); }