From 7b4f1c223671703752b07457ac8931918384a63c Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 21 Oct 2021 15:29:49 +0300 Subject: [PATCH] Limit max call size of Rialto/Millau runtimes (#1187) * max call size <= 230 bytes * fix benchmarks --- bridges/bin/millau/runtime/src/lib.rs | 4 +- bridges/bin/rialto/runtime/src/lib.rs | 4 +- bridges/modules/ethereum/src/benchmarking.rs | 10 +- bridges/modules/ethereum/src/lib.rs | 6 +- .../modules/token-swap/src/benchmarking.rs | 35 ++-- bridges/modules/token-swap/src/lib.rs | 195 ++++++++---------- bridges/primitives/token-swap/Cargo.toml | 2 + bridges/primitives/token-swap/src/lib.rs | 26 ++- bridges/relays/bin-ethereum/src/instances.rs | 4 +- .../bin-substrate/src/cli/swap_tokens.rs | 14 +- 10 files changed, 159 insertions(+), 141 deletions(-) diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index 161816c2d9..4e43868fe8 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -844,9 +844,7 @@ mod tests { #[test] fn call_size() { - // pallets that are (to be) used by polkadot runtime const MAX_CALL_SIZE: usize = 230; // value from polkadot-runtime tests - assert!(core::mem::size_of::>() <= MAX_CALL_SIZE); - assert!(core::mem::size_of::>() <= MAX_CALL_SIZE); + assert!(core::mem::size_of::() <= MAX_CALL_SIZE); } } diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 11e67c1f62..9e70dae32e 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -1447,9 +1447,7 @@ mod tests { #[test] fn call_size() { - // pallets that are (to be) used by polkadot runtime const MAX_CALL_SIZE: usize = 230; // value from polkadot-runtime tests - assert!(core::mem::size_of::>() <= MAX_CALL_SIZE); - assert!(core::mem::size_of::>() <= MAX_CALL_SIZE); + assert!(core::mem::size_of::() <= MAX_CALL_SIZE); } } diff --git a/bridges/modules/ethereum/src/benchmarking.rs b/bridges/modules/ethereum/src/benchmarking.rs index 268795d8a8..511cbcac1a 100644 --- a/bridges/modules/ethereum/src/benchmarking.rs +++ b/bridges/modules/ethereum/src/benchmarking.rs @@ -46,7 +46,7 @@ benchmarks_instance_pallet! { header }, ); - }: import_unsigned_header(RawOrigin::None, header, None) + }: import_unsigned_header(RawOrigin::None, Box::new(header), None) verify { let storage = BridgeStorage::::new(); assert_eq!(storage.best_block().0.number, 1); @@ -91,7 +91,7 @@ benchmarks_instance_pallet! { // Need to make sure that the header we're going to import hasn't been inserted // into storage already let header = HeaderBuilder::with_parent(&last_header).sign_by(&last_authority); - }: import_unsigned_header(RawOrigin::None, header, None) + }: import_unsigned_header(RawOrigin::None, Box::new(header), None) verify { let storage = BridgeStorage::::new(); assert_eq!(storage.best_block().0.number, (num_blocks + 1) as u64); @@ -132,7 +132,7 @@ benchmarks_instance_pallet! { // Need to make sure that the header we're going to import hasn't been inserted // into storage already let header = HeaderBuilder::with_parent(&last_header).sign_by(&last_authority); - }: import_unsigned_header(RawOrigin::None, header, None) + }: import_unsigned_header(RawOrigin::None, Box::new(header), None) verify { let storage = BridgeStorage::::new(); assert_eq!(storage.best_block().0.number, (num_blocks + 1) as u64); @@ -167,7 +167,7 @@ benchmarks_instance_pallet! { } let header = HeaderBuilder::with_parent(&parent).sign_by_set(&validators); - }: import_unsigned_header(RawOrigin::None, header, None) + }: import_unsigned_header(RawOrigin::None, Box::new(header), None) verify { let storage = BridgeStorage::::new(); let max_pruned: u64 = (n - 1) as _; @@ -209,7 +209,7 @@ benchmarks_instance_pallet! { header }, ); - }: import_unsigned_header(RawOrigin::None, header, Some(receipts)) + }: import_unsigned_header(RawOrigin::None, Box::new(header), Some(receipts)) verify { let storage = BridgeStorage::::new(); assert_eq!(storage.best_block().0.number, 2); diff --git a/bridges/modules/ethereum/src/lib.rs b/bridges/modules/ethereum/src/lib.rs index 6234a02cca..ad2382a949 100644 --- a/bridges/modules/ethereum/src/lib.rs +++ b/bridges/modules/ethereum/src/lib.rs @@ -25,7 +25,7 @@ use bp_eth_poa::{ use codec::{Decode, Encode}; use frame_support::traits::Get; use sp_runtime::RuntimeDebug; -use sp_std::{cmp::Ord, collections::btree_map::BTreeMap, prelude::*}; +use sp_std::{boxed::Box, cmp::Ord, collections::btree_map::BTreeMap, prelude::*}; pub use validators::{ValidatorsConfiguration, ValidatorsSource}; @@ -406,7 +406,7 @@ pub mod pallet { #[pallet::weight(0)] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78) pub fn import_unsigned_header( origin: OriginFor, - header: AuraHeader, + header: Box, receipts: Option>, ) -> DispatchResult { frame_system::ensure_none(origin)?; @@ -417,7 +417,7 @@ pub mod pallet { &T::AuraConfiguration::get(), &T::ValidatorsConfiguration::get(), None, - header, + *header, &T::ChainTime::default(), receipts, ) diff --git a/bridges/modules/token-swap/src/benchmarking.rs b/bridges/modules/token-swap/src/benchmarking.rs index 0dd8922d15..bbc544a8b9 100644 --- a/bridges/modules/token-swap/src/benchmarking.rs +++ b/bridges/modules/token-swap/src/benchmarking.rs @@ -18,10 +18,11 @@ use crate::{ swap_account_id, target_account_at_this_chain, BridgedAccountIdOf, BridgedAccountPublicOf, - BridgedAccountSignatureOf, BridgedBalanceOf, Call, Pallet, ThisChainBalance, TokenSwapOf, + BridgedAccountSignatureOf, BridgedBalanceOf, Call, Pallet, ThisChainBalance, + TokenSwapCreationOf, TokenSwapOf, }; -use bp_token_swap::{TokenSwap, TokenSwapState, TokenSwapType}; +use bp_token_swap::{TokenSwap, TokenSwapCreation, TokenSwapState, TokenSwapType}; use codec::Encode; use frame_benchmarking::{account, benchmarks_instance_pallet}; use frame_support::{traits::Currency, Parameter}; @@ -62,21 +63,11 @@ benchmarks_instance_pallet! { let sender = funded_account::("source_account_at_this_chain", 0); let swap: TokenSwapOf = test_swap::(sender.clone(), true); - let target_public_at_bridged_chain = target_public_at_bridged_chain::(); - let swap_delivery_and_dispatch_fee = swap_delivery_and_dispatch_fee::(); - let bridged_chain_spec_version = 0; - let bridged_currency_transfer = Vec::new(); - let bridged_currency_transfer_weight = 0; - let bridged_currency_transfer_signature = bridged_currency_transfer_signature::(); + let swap_creation: TokenSwapCreationOf = test_swap_creation::(); }: create_swap( RawOrigin::Signed(sender.clone()), swap, - target_public_at_bridged_chain, - swap_delivery_and_dispatch_fee, - bridged_chain_spec_version, - bridged_currency_transfer, - bridged_currency_transfer_weight, - bridged_currency_transfer_signature + Box::new(swap_creation) ) verify { assert!(crate::PendingSwaps::::contains_key(test_swap_hash::(sender, true))); @@ -144,6 +135,22 @@ fn test_swap_hash, I: 'static>(sender: T::AccountId, is_create: boo test_swap::(sender, is_create).using_encoded(blake2_256).into() } +/// Returns test token swap creation params. +fn test_swap_creation, I: 'static>() -> TokenSwapCreationOf +where + BridgedAccountPublicOf: Default, + BridgedAccountSignatureOf: Default, +{ + TokenSwapCreation { + target_public_at_bridged_chain: target_public_at_bridged_chain::(), + swap_delivery_and_dispatch_fee: swap_delivery_and_dispatch_fee::(), + bridged_chain_spec_version: 0, + bridged_currency_transfer: Vec::new(), + bridged_currency_transfer_weight: 0, + bridged_currency_transfer_signature: bridged_currency_transfer_signature::(), + } +} + /// Account that has some balance. fn funded_account, I: 'static>(name: &'static str, index: u32) -> T::AccountId { let account: T::AccountId = account(name, index, SEED); diff --git a/bridges/modules/token-swap/src/lib.rs b/bridges/modules/token-swap/src/lib.rs index 3a49d431c7..60ca1221dd 100644 --- a/bridges/modules/token-swap/src/lib.rs +++ b/bridges/modules/token-swap/src/lib.rs @@ -23,29 +23,39 @@ //! There are four accounts participating in the swap: //! //! 1) account of This chain that has signed the `create_swap` transaction and has balance on This -//! chain. We'll be referring to this account as `source_account_at_this_chain`; +//! chain. We'll be referring to this account as `source_account_at_this_chain`; +//! //! 2) account of the Bridged chain that is sending the `claim_swap` message from the Bridged to -//! This chain. This account has balance on Bridged chain and is willing to swap these tokens to -//! This chain tokens of the `source_account_at_this_chain`. We'll be referring to this account -//! as `target_account_at_bridged_chain`; 3) account of the Bridged chain that is indirectly -//! controlled by the `source_account_at_this_chain`. We'll be referring this account as -//! `source_account_at_bridged_chain`; 4) account of This chain that is indirectly controlled by the -//! `target_account_at_bridged_chain`. We'll be referring this account as -//! `target_account_at_this_chain`. +//! This chain. This account has balance on Bridged chain and is willing to swap these tokens to +//! This chain tokens of the `source_account_at_this_chain`. We'll be referring to this account +//! as `target_account_at_bridged_chain`; +//! +//! 3) account of the Bridged chain that is indirectly controlled by the +//! `source_account_at_this_chain`. We'll be referring this account as +//! `source_account_at_bridged_chain`; +//! +//! 4) account of This chain that is indirectly controlled by the `target_account_at_bridged_chain`. +//! We'll be referring this account as `target_account_at_this_chain`. //! //! So the tokens swap is an intention of `source_account_at_this_chain` to swap his //! `source_balance_at_this_chain` tokens to the `target_balance_at_bridged_chain` tokens owned by //! `target_account_at_bridged_chain`. The swap process goes as follows: //! //! 1) the `source_account_at_this_chain` account submits the `create_swap` transaction on This -//! chain; 2) the tokens transfer message that would transfer `target_balance_at_bridged_chain` -//! tokens from the `target_account_at_bridged_chain` to the `source_account_at_bridged_chain`, -//! is sent over the bridge; 3) when transfer message is delivered and dispatched, the pallet -//! receives notification; 4) if message has been successfully dispatched, the -//! `target_account_at_bridged_chain` sends the message that would transfer -//! `source_balance_at_this_chain` tokens to his `target_account_at_this_chain` account; +//! chain; +//! +//! 2) the tokens transfer message that would transfer `target_balance_at_bridged_chain` +//! tokens from the `target_account_at_bridged_chain` to the `source_account_at_bridged_chain`, +//! is sent over the bridge; +//! +//! 3) when transfer message is delivered and dispatched, the pallet receives notification; +//! +//! 4) if message has been successfully dispatched, the `target_account_at_bridged_chain` sends the +//! message that would transfer `source_balance_at_this_chain` tokens to his +//! `target_account_at_this_chain` account; +//! //! 5) if message dispatch has failed, the `source_account_at_this_chain` may submit the -//! `cancel_swap` transaction and return his `source_balance_at_this_chain` back to his account. +//! `cancel_swap` transaction and return his `source_balance_at_this_chain` back to his account. //! //! 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. @@ -57,7 +67,9 @@ use bp_messages::{ DeliveredMessages, LaneId, MessageNonce, }; use bp_runtime::{messages::DispatchFeePayment, ChainId}; -use bp_token_swap::{TokenSwap, TokenSwapState, TokenSwapType}; +use bp_token_swap::{ + RawBridgedTransferCall, TokenSwap, TokenSwapCreation, TokenSwapState, TokenSwapType, +}; use codec::Encode; use frame_support::{ fail, @@ -67,7 +79,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; +use sp_std::boxed::Box; use weights::WeightInfo; pub use weights_ext::WeightInfoExt; @@ -146,8 +158,6 @@ pub mod pallet { /// Account signature type at the Bridged chain. pub type BridgedAccountSignatureOf = bp_runtime::SignatureOf>; - /// SCALE-encoded `Currency::transfer` call on the bridged chain. - pub type RawBridgedTransferCall = Vec; /// Bridge message payload used by the pallet. pub type MessagePayloadOf = bp_message_dispatch::MessagePayload< ::AccountId, @@ -163,6 +173,12 @@ pub mod pallet { BridgedBalanceOf, BridgedAccountIdOf, >; + /// Type of `TokenSwapCreation` used by the pallet. + pub type TokenSwapCreationOf = TokenSwapCreation< + BridgedAccountPublicOf, + ThisChainBalance, + BridgedAccountSignatureOf, + >; #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] @@ -184,14 +200,7 @@ pub mod pallet { /// Method arguments are: /// /// - `swap` - token swap intention; - /// - `target_public_at_bridged_chain` - the public key of the - /// `swap.target_account_at_bridged_chain` account used to verify - /// `bridged_currency_transfer_signature`; - /// - `bridged_currency_transfer` - the SCALE-encoded tokens transfer call at the Bridged - /// chain; - /// - `bridged_currency_transfer_signature` - the signature of the - /// `swap.target_account_at_bridged_chain` for the message returned by the - /// `pallet_bridge_dispatch::account_ownership_digest()` function call. + /// - `swap_creation_params` - additional parameters required to start tokens swap. /// /// The `source_account_at_this_chain` MUST have enough balance to cover both token swap and /// message transfer. Message fee may be estimated using corresponding `OutboundLaneApi` of @@ -199,15 +208,20 @@ pub mod pallet { /// /// **WARNING**: the submitter of this transaction is responsible for verifying: /// - /// 1) that the `bridged_currency_transfer` represents a valid token transfer call that - /// transfers `swap.target_balance_at_bridged_chain` to his - /// `source_account_at_bridged_chain` account; 2) that either the - /// `source_account_at_bridged_chain` already exists, or the - /// `swap.target_balance_at_bridged_chain` is above existential deposit of the Bridged - /// chain; 3) the `target_public_at_bridged_chain` matches the - /// `swap.target_account_at_bridged_chain`; 4) the `bridged_currency_transfer_signature` is - /// valid and generated by the owner of the `target_public_at_bridged_chain` account - /// (read more about [`CallOrigin::TargetAccount`]). + /// 1) that the `swap_creation_params.bridged_currency_transfer` represents a valid token + /// transfer call that transfers `swap.target_balance_at_bridged_chain` to his + /// `swap.source_account_at_bridged_chain` account; + /// + /// 2) that either the `swap.source_account_at_bridged_chain` already exists, or the + /// `swap.target_balance_at_bridged_chain` is above existential deposit of the Bridged + /// chain; + /// + /// 3) the `swap_creation_params.target_public_at_bridged_chain` matches the + /// `swap.target_account_at_bridged_chain`; + /// + /// 4) the `bridged_currency_transfer_signature` is valid and generated by the owner of + /// the `swap_creation_params.target_public_at_bridged_chain` account (read more + /// about [`CallOrigin::TargetAccount`]). /// /// Violating rule#1 will lead to losing your `source_balance_at_this_chain` tokens. /// Violating other rules will lead to losing message fees for this and other transactions + @@ -215,21 +229,24 @@ pub mod pallet { #[pallet::weight( T::WeightInfo::create_swap() .saturating_add(T::WeightInfo::send_message_weight( - &&bridged_currency_transfer[..], + &&swap_creation_params.bridged_currency_transfer[..], T::DbWeight::get(), )) )] - #[allow(clippy::too_many_arguments)] pub fn create_swap( 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, - bridged_currency_transfer_signature: BridgedAccountSignatureOf, + swap_creation_params: Box>, ) -> DispatchResultWithPostInfo { + let TokenSwapCreation { + target_public_at_bridged_chain, + swap_delivery_and_dispatch_fee, + bridged_chain_spec_version, + bridged_currency_transfer, + bridged_currency_transfer_weight, + bridged_currency_transfer_signature, + } = *swap_creation_params; + // ensure that the `origin` is the same account that is mentioned in the `swap` // intention let origin_account = ensure_signed(origin)?; @@ -648,6 +665,17 @@ mod tests { } } + fn test_swap_creation() -> TokenSwapCreationOf { + TokenSwapCreation { + target_public_at_bridged_chain: bridged_chain_account_public(), + swap_delivery_and_dispatch_fee: SWAP_DELIVERY_AND_DISPATCH_FEE, + bridged_chain_spec_version: BRIDGED_CHAIN_SPEC_VERSION, + bridged_currency_transfer: test_transfer(), + bridged_currency_transfer_weight: BRIDGED_CHAIN_CALL_WEIGHT, + bridged_currency_transfer_signature: bridged_chain_account_signature(), + } + } + fn test_swap_hash() -> H256 { test_swap().using_encoded(blake2_256).into() } @@ -660,12 +688,14 @@ mod tests { assert_ok!(Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(TokenSwapCreation { + target_public_at_bridged_chain: bridged_chain_account_public(), + swap_delivery_and_dispatch_fee: SWAP_DELIVERY_AND_DISPATCH_FEE, + bridged_chain_spec_version: BRIDGED_CHAIN_SPEC_VERSION, + bridged_currency_transfer: test_transfer(), + bridged_currency_transfer_weight: BRIDGED_CHAIN_CALL_WEIGHT, + bridged_currency_transfer_signature: bridged_chain_account_signature(), + }), )); } @@ -683,12 +713,7 @@ mod tests { Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), ), Error::::MismatchedSwapSourceOrigin ); @@ -704,12 +729,7 @@ mod tests { Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), ), Error::::TooLowBalanceOnThisChain ); @@ -725,12 +745,7 @@ mod tests { Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), ), Error::::FailedToTransferToSwapAccount ); @@ -742,16 +757,13 @@ mod tests { run_test(|| { let mut transfer = test_transfer(); transfer[0] = BAD_TRANSFER_CALL; + let mut swap_creation = test_swap_creation(); + swap_creation.bridged_currency_transfer = transfer; assert_noop!( Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(swap_creation), ), Error::::FailedToSendTransferMessage ); @@ -764,24 +776,14 @@ mod tests { assert_ok!(Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), )); assert_noop!( Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), ), Error::::SwapAlreadyStarted ); @@ -796,12 +798,7 @@ mod tests { Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), ), Error::::SwapPeriodIsFinished ); @@ -815,12 +812,7 @@ mod tests { assert_ok!(Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), )); }); } @@ -834,12 +826,7 @@ mod tests { assert_ok!(Pallet::::create_swap( 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, - bridged_chain_account_signature(), + Box::new(test_swap_creation()), )); let swap_hash = test_swap_hash(); diff --git a/bridges/primitives/token-swap/Cargo.toml b/bridges/primitives/token-swap/Cargo.toml index 03f40438e0..dd42f4e4a0 100644 --- a/bridges/primitives/token-swap/Cargo.toml +++ b/bridges/primitives/token-swap/Cargo.toml @@ -13,6 +13,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] @@ -20,4 +21,5 @@ std = [ "codec/std", "frame-support/std", "sp-core/std", + "sp-std/std", ] diff --git a/bridges/primitives/token-swap/src/lib.rs b/bridges/primitives/token-swap/src/lib.rs index 336e3263f0..48aaeb38c3 100644 --- a/bridges/primitives/token-swap/src/lib.rs +++ b/bridges/primitives/token-swap/src/lib.rs @@ -17,8 +17,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Decode, Encode}; -use frame_support::RuntimeDebug; +use frame_support::{weights::Weight, RuntimeDebug}; use sp_core::U256; +use sp_std::vec::Vec; /// Pending token swap state. #[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)] @@ -82,3 +83,26 @@ pub struct TokenSwap; + +/// Token swap creation parameters. +#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)] +pub struct TokenSwapCreation { + /// Public key of the `target_account_at_bridged_chain` account used to verify + /// `bridged_currency_transfer_signature`. + pub target_public_at_bridged_chain: BridgedAccountPublic, + /// Fee that the `source_account_at_this_chain` is ready to pay for the tokens + /// transfer message delivery and dispatch. + pub swap_delivery_and_dispatch_fee: ThisChainBalance, + /// Specification version of the Bridged chain. + pub bridged_chain_spec_version: u32, + /// SCALE-encoded tokens transfer call at the Bridged chain. + pub bridged_currency_transfer: RawBridgedTransferCall, + /// Dispatch weight of the tokens transfer call at the Bridged chain. + pub bridged_currency_transfer_weight: Weight, + /// The signature of the `target_account_at_bridged_chain` for the message + /// returned by the `pallet_bridge_dispatch::account_ownership_digest()` function call. + pub bridged_currency_transfer_signature: BridgedAccountSignature, +} diff --git a/bridges/relays/bin-ethereum/src/instances.rs b/bridges/relays/bin-ethereum/src/instances.rs index 90d736fa25..3f2ebf825b 100644 --- a/bridges/relays/bin-ethereum/src/instances.rs +++ b/bridges/relays/bin-ethereum/src/instances.rs @@ -67,7 +67,7 @@ impl BridgeInstance for RialtoPoA { fn build_unsigned_header_call(&self, header: QueuedEthereumHeader) -> Call { let pallet_call = rialto_runtime::BridgeEthPoACall::import_unsigned_header( - into_substrate_ethereum_header(header.header()), + Box::new(into_substrate_ethereum_header(header.header())), into_substrate_ethereum_receipts(header.extra()), ); @@ -104,7 +104,7 @@ impl BridgeInstance for Kovan { fn build_unsigned_header_call(&self, header: QueuedEthereumHeader) -> Call { let pallet_call = rialto_runtime::BridgeEthPoACall::import_unsigned_header( - into_substrate_ethereum_header(header.header()), + Box::new(into_substrate_ethereum_header(header.header())), into_substrate_ethereum_receipts(header.extra()), ); diff --git a/bridges/relays/bin-substrate/src/cli/swap_tokens.rs b/bridges/relays/bin-substrate/src/cli/swap_tokens.rs index 01eb3fbb4f..9f4b3ba698 100644 --- a/bridges/relays/bin-substrate/src/cli/swap_tokens.rs +++ b/bridges/relays/bin-substrate/src/cli/swap_tokens.rs @@ -220,12 +220,14 @@ impl SwapTokens { .await?; let create_swap_call: CallOf = pallet_bridge_token_swap::Call::create_swap( token_swap.clone(), - target_public_at_bridged_chain, - swap_delivery_and_dispatch_fee, - bridged_chain_spec_version, - bridged_currency_transfer.encode(), - bridged_currency_transfer_weight, - bridged_currency_transfer_signature, + Box::new(bp_token_swap::TokenSwapCreation { + target_public_at_bridged_chain, + swap_delivery_and_dispatch_fee, + bridged_chain_spec_version, + bridged_currency_transfer: bridged_currency_transfer.encode(), + bridged_currency_transfer_weight, + bridged_currency_transfer_signature, + }), ) .into();