mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Limit max call size of Rialto/Millau runtimes (#1187)
* max call size <= 230 bytes * fix benchmarks
This commit is contained in:
committed by
Bastian Köcher
parent
b60df0849c
commit
7b4f1c2236
@@ -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::<pallet_bridge_grandpa::Call<Runtime>>() <= MAX_CALL_SIZE);
|
||||
assert!(core::mem::size_of::<pallet_bridge_messages::Call<Runtime>>() <= MAX_CALL_SIZE);
|
||||
assert!(core::mem::size_of::<Call>() <= MAX_CALL_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<pallet_bridge_grandpa::Call<Runtime>>() <= MAX_CALL_SIZE);
|
||||
assert!(core::mem::size_of::<pallet_bridge_messages::Call<Runtime>>() <= MAX_CALL_SIZE);
|
||||
assert!(core::mem::size_of::<Call>() <= MAX_CALL_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<T, I>::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::<T, I>::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::<T, I>::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::<T, I>::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::<T, I>::new();
|
||||
assert_eq!(storage.best_block().0.number, 2);
|
||||
|
||||
@@ -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<T>,
|
||||
header: AuraHeader,
|
||||
header: Box<AuraHeader>,
|
||||
receipts: Option<Vec<Receipt>>,
|
||||
) -> 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,
|
||||
)
|
||||
|
||||
@@ -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::<T, I>("source_account_at_this_chain", 0);
|
||||
let swap: TokenSwapOf<T, I> = test_swap::<T, I>(sender.clone(), true);
|
||||
let target_public_at_bridged_chain = target_public_at_bridged_chain::<T, I>();
|
||||
let swap_delivery_and_dispatch_fee = swap_delivery_and_dispatch_fee::<T, I>();
|
||||
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::<T, I>();
|
||||
let swap_creation: TokenSwapCreationOf<T, I> = test_swap_creation::<T, I>();
|
||||
}: 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::<T, I>::contains_key(test_swap_hash::<T, I>(sender, true)));
|
||||
@@ -144,6 +135,22 @@ fn test_swap_hash<T: Config<I>, I: 'static>(sender: T::AccountId, is_create: boo
|
||||
test_swap::<T, I>(sender, is_create).using_encoded(blake2_256).into()
|
||||
}
|
||||
|
||||
/// Returns test token swap creation params.
|
||||
fn test_swap_creation<T: Config<I>, I: 'static>() -> TokenSwapCreationOf<T, I>
|
||||
where
|
||||
BridgedAccountPublicOf<T, I>: Default,
|
||||
BridgedAccountSignatureOf<T, I>: Default,
|
||||
{
|
||||
TokenSwapCreation {
|
||||
target_public_at_bridged_chain: target_public_at_bridged_chain::<T, I>(),
|
||||
swap_delivery_and_dispatch_fee: swap_delivery_and_dispatch_fee::<T, I>(),
|
||||
bridged_chain_spec_version: 0,
|
||||
bridged_currency_transfer: Vec::new(),
|
||||
bridged_currency_transfer_weight: 0,
|
||||
bridged_currency_transfer_signature: bridged_currency_transfer_signature::<T, I>(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Account that has some balance.
|
||||
fn funded_account<T: Config<I>, I: 'static>(name: &'static str, index: u32) -> T::AccountId {
|
||||
let account: T::AccountId = account(name, index, SEED);
|
||||
|
||||
@@ -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<T, I> = bp_runtime::SignatureOf<BridgedChainOf<T, I>>;
|
||||
|
||||
/// SCALE-encoded `Currency::transfer` call on the bridged chain.
|
||||
pub type RawBridgedTransferCall = Vec<u8>;
|
||||
/// Bridge message payload used by the pallet.
|
||||
pub type MessagePayloadOf<T, I> = bp_message_dispatch::MessagePayload<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
@@ -163,6 +173,12 @@ pub mod pallet {
|
||||
BridgedBalanceOf<T, I>,
|
||||
BridgedAccountIdOf<T, I>,
|
||||
>;
|
||||
/// Type of `TokenSwapCreation` used by the pallet.
|
||||
pub type TokenSwapCreationOf<T, I> = TokenSwapCreation<
|
||||
BridgedAccountPublicOf<T, I>,
|
||||
ThisChainBalance<T, I>,
|
||||
BridgedAccountSignatureOf<T, I>,
|
||||
>;
|
||||
|
||||
#[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<T>,
|
||||
swap: TokenSwapOf<T, I>,
|
||||
target_public_at_bridged_chain: BridgedAccountPublicOf<T, I>,
|
||||
swap_delivery_and_dispatch_fee: ThisChainBalance<T, I>,
|
||||
bridged_chain_spec_version: u32,
|
||||
bridged_currency_transfer: RawBridgedTransferCall,
|
||||
bridged_currency_transfer_weight: Weight,
|
||||
bridged_currency_transfer_signature: BridgedAccountSignatureOf<T, I>,
|
||||
swap_creation_params: Box<TokenSwapCreationOf<T, I>>,
|
||||
) -> 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<TestRuntime, ()> {
|
||||
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::<TestRuntime>::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::<TestRuntime>::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::<TestRuntime, ()>::MismatchedSwapSourceOrigin
|
||||
);
|
||||
@@ -704,12 +729,7 @@ mod tests {
|
||||
Pallet::<TestRuntime>::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::<TestRuntime, ()>::TooLowBalanceOnThisChain
|
||||
);
|
||||
@@ -725,12 +745,7 @@ mod tests {
|
||||
Pallet::<TestRuntime>::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::<TestRuntime, ()>::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::<TestRuntime>::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::<TestRuntime, ()>::FailedToSendTransferMessage
|
||||
);
|
||||
@@ -764,24 +776,14 @@ mod tests {
|
||||
assert_ok!(Pallet::<TestRuntime>::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::<TestRuntime>::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::<TestRuntime, ()>::SwapAlreadyStarted
|
||||
);
|
||||
@@ -796,12 +798,7 @@ mod tests {
|
||||
Pallet::<TestRuntime>::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::<TestRuntime, ()>::SwapPeriodIsFinished
|
||||
);
|
||||
@@ -815,12 +812,7 @@ mod tests {
|
||||
assert_ok!(Pallet::<TestRuntime>::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::<TestRuntime>::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();
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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<ThisBlockNumber, ThisBalance, ThisAccountId, BridgedBalance
|
||||
/// `target_balance_at_bridged_chain`.
|
||||
pub target_account_at_bridged_chain: BridgedAccountId,
|
||||
}
|
||||
|
||||
/// SCALE-encoded `Currency::transfer` call on the bridged chain.
|
||||
pub type RawBridgedTransferCall = Vec<u8>;
|
||||
|
||||
/// Token swap creation parameters.
|
||||
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)]
|
||||
pub struct TokenSwapCreation<BridgedAccountPublic, ThisChainBalance, BridgedAccountSignature> {
|
||||
/// 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,
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
);
|
||||
|
||||
|
||||
@@ -220,12 +220,14 @@ impl SwapTokens {
|
||||
.await?;
|
||||
let create_swap_call: CallOf<Source> = 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user