mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 23:07:57 +00:00
backport changes from polkadot-sdk (#2872)
This commit is contained in:
committed by
Bastian Köcher
parent
4bfd7807e7
commit
8bb0bfa524
@@ -13,7 +13,7 @@ workspace = true
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
|
||||
hash-db = { version = "0.16.0", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
static_assertions = { version = "1.1", optional = true }
|
||||
|
||||
@@ -93,6 +93,7 @@ runtime-benchmarks = [
|
||||
"pallet-bridge-messages/runtime-benchmarks",
|
||||
"pallet-bridge-parachains/runtime-benchmarks",
|
||||
"pallet-bridge-relayers/runtime-benchmarks",
|
||||
"pallet-transaction-payment/runtime-benchmarks",
|
||||
"pallet-utility/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
|
||||
@@ -105,43 +105,48 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
|
||||
($call:ty, $account_id:ty, $($filter_call:ty),*) => {
|
||||
#[derive(Clone, codec::Decode, Default, codec::Encode, Eq, PartialEq, sp_runtime::RuntimeDebug, scale_info::TypeInfo)]
|
||||
pub struct BridgeRejectObsoleteHeadersAndMessages;
|
||||
impl sp_runtime::traits::SignedExtension for BridgeRejectObsoleteHeadersAndMessages {
|
||||
impl sp_runtime::traits::TransactionExtensionBase for BridgeRejectObsoleteHeadersAndMessages {
|
||||
const IDENTIFIER: &'static str = "BridgeRejectObsoleteHeadersAndMessages";
|
||||
type AccountId = $account_id;
|
||||
type Call = $call;
|
||||
type AdditionalSigned = ();
|
||||
type Implicit = ();
|
||||
}
|
||||
impl<Context> sp_runtime::traits::TransactionExtension<$call, Context> for BridgeRejectObsoleteHeadersAndMessages {
|
||||
type Pre = ();
|
||||
|
||||
fn additional_signed(&self) -> sp_std::result::Result<
|
||||
(),
|
||||
sp_runtime::transaction_validity::TransactionValidityError,
|
||||
> {
|
||||
Ok(())
|
||||
}
|
||||
type Val = ();
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
_who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
_info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
|
||||
origin: <$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
|
||||
call: &$call,
|
||||
_info: &sp_runtime::traits::DispatchInfoOf<$call>,
|
||||
_len: usize,
|
||||
) -> sp_runtime::transaction_validity::TransactionValidity {
|
||||
let valid = sp_runtime::transaction_validity::ValidTransaction::default();
|
||||
_context: &mut Context,
|
||||
_self_implicit: Self::Implicit,
|
||||
_inherited_implication: &impl codec::Encode,
|
||||
) -> Result<
|
||||
(
|
||||
sp_runtime::transaction_validity::ValidTransaction,
|
||||
Self::Val,
|
||||
<$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
|
||||
), sp_runtime::transaction_validity::TransactionValidityError
|
||||
> {
|
||||
let tx_validity = sp_runtime::transaction_validity::ValidTransaction::default();
|
||||
$(
|
||||
let valid = valid
|
||||
.combine_with(<$filter_call as $crate::BridgeRuntimeFilterCall<$call>>::validate(call)?);
|
||||
let call_filter_validity = <$filter_call as $crate::BridgeRuntimeFilterCall<$call>>::validate(call)?;
|
||||
let tx_validity = tx_validity.combine_with(call_filter_validity);
|
||||
)*
|
||||
Ok(valid)
|
||||
Ok((tx_validity, (), origin))
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
fn prepare(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
_val: Self::Val,
|
||||
_origin: &<$call as sp_runtime::traits::Dispatchable>::RuntimeOrigin,
|
||||
_call: &$call,
|
||||
_info: &sp_runtime::traits::DispatchInfoOf<$call>,
|
||||
_len: usize,
|
||||
_context: &Context,
|
||||
) -> Result<Self::Pre, sp_runtime::transaction_validity::TransactionValidityError> {
|
||||
self.validate(who, call, info, len).map(drop)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -150,12 +155,14 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::BridgeRuntimeFilterCall;
|
||||
use frame_support::{assert_err, assert_ok};
|
||||
use codec::Encode;
|
||||
use frame_support::assert_err;
|
||||
use sp_runtime::{
|
||||
traits::SignedExtension,
|
||||
traits::DispatchTransaction,
|
||||
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
|
||||
};
|
||||
|
||||
#[derive(Encode)]
|
||||
pub struct MockCall {
|
||||
data: u32,
|
||||
}
|
||||
@@ -206,17 +213,20 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_err!(
|
||||
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 1 }, &(), 0),
|
||||
BridgeRejectObsoleteHeadersAndMessages.validate_only((), &MockCall { data: 1 }, &(), 0),
|
||||
InvalidTransaction::Custom(1)
|
||||
);
|
||||
|
||||
assert_err!(
|
||||
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 2 }, &(), 0),
|
||||
BridgeRejectObsoleteHeadersAndMessages.validate_only((), &MockCall { data: 2 }, &(), 0),
|
||||
InvalidTransaction::Custom(2)
|
||||
);
|
||||
|
||||
assert_ok!(
|
||||
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 3 }, &(), 0),
|
||||
assert_eq!(
|
||||
BridgeRejectObsoleteHeadersAndMessages
|
||||
.validate_only((), &MockCall { data: 3 }, &(), 0)
|
||||
.unwrap()
|
||||
.0,
|
||||
ValidTransaction { priority: 3, ..Default::default() }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ impl pallet_balances::Config for TestRuntime {
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
#[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig as pallet_transaction_payment::DefaultConfig)]
|
||||
impl pallet_transaction_payment::Config for TestRuntime {
|
||||
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
@@ -176,7 +177,6 @@ impl pallet_transaction_payment::Config for TestRuntime {
|
||||
MinimumMultiplier,
|
||||
MaximumMultiplier,
|
||||
>;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
|
||||
impl pallet_bridge_grandpa::Config for TestRuntime {
|
||||
|
||||
@@ -169,12 +169,15 @@ mod integrity_tests {
|
||||
// nodes to the proof (x0.5 because we expect some nodes to be reused)
|
||||
let estimated_message_size = 512;
|
||||
// let's say all our messages have the same dispatch weight
|
||||
let estimated_message_dispatch_weight =
|
||||
Runtime::WeightInfo::message_dispatch_weight(estimated_message_size);
|
||||
let estimated_message_dispatch_weight = <Runtime as pallet_bridge_messages::Config<
|
||||
MessagesInstance,
|
||||
>>::WeightInfo::message_dispatch_weight(
|
||||
estimated_message_size
|
||||
);
|
||||
// messages proof argument size is (for every message) messages size + some additional
|
||||
// trie nodes. Some of them are reused by different messages, so let's take 2/3 of default
|
||||
// "overhead" constant
|
||||
let messages_proof_size = Runtime::WeightInfo::expected_extra_storage_proof_size()
|
||||
let messages_proof_size = <Runtime as pallet_bridge_messages::Config<MessagesInstance>>::WeightInfo::expected_extra_storage_proof_size()
|
||||
.saturating_mul(2)
|
||||
.saturating_div(3)
|
||||
.saturating_add(estimated_message_size)
|
||||
@@ -182,7 +185,7 @@ mod integrity_tests {
|
||||
|
||||
// finally we are able to estimate transaction size and weight
|
||||
let transaction_size = base_tx_size.saturating_add(messages_proof_size);
|
||||
let transaction_weight = Runtime::WeightInfo::receive_messages_proof_weight(
|
||||
let transaction_weight = <Runtime as pallet_bridge_messages::Config<MessagesInstance>>::WeightInfo::receive_messages_proof_weight(
|
||||
&PreComputedSize(transaction_size as _),
|
||||
messages as _,
|
||||
estimated_message_dispatch_weight.saturating_mul(messages),
|
||||
|
||||
@@ -48,9 +48,12 @@ use pallet_transaction_payment::{Config as TransactionPaymentConfig, OnChargeTra
|
||||
use pallet_utility::{Call as UtilityCall, Config as UtilityConfig, Pallet as UtilityPallet};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, Dispatchable, Get, PostDispatchInfoOf, SignedExtension, Zero},
|
||||
traits::{
|
||||
AsSystemOriginSigner, DispatchInfoOf, Dispatchable, Get, PostDispatchInfoOf,
|
||||
TransactionExtension, TransactionExtensionBase, ValidateResult, Zero,
|
||||
},
|
||||
transaction_validity::{
|
||||
TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
|
||||
InvalidTransaction, TransactionPriority, TransactionValidityError, ValidTransactionBuilder,
|
||||
},
|
||||
DispatchResult, FixedPointOperand, RuntimeDebug,
|
||||
};
|
||||
@@ -239,8 +242,8 @@ pub enum RelayerAccountAction<AccountId, Reward> {
|
||||
Slash(AccountId, RewardsAccountParams),
|
||||
}
|
||||
|
||||
/// Everything common among our refund signed extensions.
|
||||
pub trait RefundSignedExtension:
|
||||
/// Everything common among our refund transaction extensions.
|
||||
pub trait RefundTransactionExtension:
|
||||
'static + Clone + Codec + sp_std::fmt::Debug + Default + Eq + PartialEq + Send + Sync + TypeInfo
|
||||
where
|
||||
<Self::Runtime as GrandpaConfig<Self::GrandpaInstance>>::BridgedChain:
|
||||
@@ -456,8 +459,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapter that allow implementing `sp_runtime::traits::SignedExtension` for any
|
||||
/// `RefundSignedExtension`.
|
||||
/// Adapter that allow implementing `sp_runtime::traits::TransactionExtension` for any
|
||||
/// `RefundTransactionExtension`.
|
||||
#[derive(
|
||||
DefaultNoBound,
|
||||
CloneNoBound,
|
||||
@@ -468,12 +471,13 @@ where
|
||||
RuntimeDebugNoBound,
|
||||
TypeInfo,
|
||||
)]
|
||||
pub struct RefundSignedExtensionAdapter<T: RefundSignedExtension>(T)
|
||||
pub struct RefundTransactionExtensionAdapter<T: RefundTransactionExtension>(T)
|
||||
where
|
||||
<T::Runtime as GrandpaConfig<T::GrandpaInstance>>::BridgedChain:
|
||||
Chain<BlockNumber = RelayBlockNumber>;
|
||||
|
||||
impl<T: RefundSignedExtension> SignedExtension for RefundSignedExtensionAdapter<T>
|
||||
impl<T: RefundTransactionExtension> TransactionExtensionBase
|
||||
for RefundTransactionExtensionAdapter<T>
|
||||
where
|
||||
<T::Runtime as GrandpaConfig<T::GrandpaInstance>>::BridgedChain:
|
||||
Chain<BlockNumber = RelayBlockNumber>,
|
||||
@@ -483,22 +487,35 @@ where
|
||||
+ MessagesCallSubType<T::Runtime, <T::Msgs as RefundableMessagesLaneId>::Instance>,
|
||||
{
|
||||
const IDENTIFIER: &'static str = T::Id::STR;
|
||||
type AccountId = AccountIdOf<T::Runtime>;
|
||||
type Call = CallOf<T::Runtime>;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = Option<PreDispatchData<AccountIdOf<T::Runtime>>>;
|
||||
type Implicit = ();
|
||||
}
|
||||
|
||||
fn additional_signed(&self) -> Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
impl<T: RefundTransactionExtension, Context> TransactionExtension<CallOf<T::Runtime>, Context>
|
||||
for RefundTransactionExtensionAdapter<T>
|
||||
where
|
||||
<T::Runtime as GrandpaConfig<T::GrandpaInstance>>::BridgedChain:
|
||||
Chain<BlockNumber = RelayBlockNumber>,
|
||||
CallOf<T::Runtime>: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
|
||||
+ IsSubType<CallableCallFor<UtilityPallet<T::Runtime>, T::Runtime>>
|
||||
+ GrandpaCallSubType<T::Runtime, T::GrandpaInstance>
|
||||
+ MessagesCallSubType<T::Runtime, <T::Msgs as RefundableMessagesLaneId>::Instance>,
|
||||
<CallOf<T::Runtime> as Dispatchable>::RuntimeOrigin:
|
||||
AsSystemOriginSigner<AccountIdOf<T::Runtime>> + Clone,
|
||||
{
|
||||
type Pre = Option<PreDispatchData<AccountIdOf<T::Runtime>>>;
|
||||
type Val = Option<CallInfo>;
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
origin: <CallOf<T::Runtime> as Dispatchable>::RuntimeOrigin,
|
||||
call: &CallOf<T::Runtime>,
|
||||
_info: &DispatchInfoOf<CallOf<T::Runtime>>,
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
_context: &mut Context,
|
||||
_self_implicit: Self::Implicit,
|
||||
_inherited_implication: &impl Encode,
|
||||
) -> ValidateResult<Self::Val, CallOf<T::Runtime>> {
|
||||
let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
|
||||
// this is the only relevant line of code for the `pre_dispatch`
|
||||
//
|
||||
// we're not calling `validate` from `pre_dispatch` directly because of performance
|
||||
@@ -511,12 +528,12 @@ where
|
||||
// we only boost priority of presumably correct message delivery transactions
|
||||
let bundled_messages = match T::bundled_messages_for_priority_boost(parsed_call.as_ref()) {
|
||||
Some(bundled_messages) => bundled_messages,
|
||||
None => return Ok(Default::default()),
|
||||
None => return Ok((Default::default(), parsed_call, origin)),
|
||||
};
|
||||
|
||||
// we only boost priority if relayer has staked required balance
|
||||
if !RelayersPallet::<T::Runtime>::is_registration_active(who) {
|
||||
return Ok(Default::default())
|
||||
return Ok((Default::default(), parsed_call, origin))
|
||||
}
|
||||
|
||||
// compute priority boost
|
||||
@@ -535,20 +552,21 @@ where
|
||||
priority_boost,
|
||||
);
|
||||
|
||||
valid_transaction.build()
|
||||
let validity = valid_transaction.build()?;
|
||||
Ok((validity, parsed_call, origin))
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
fn prepare(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
val: Self::Val,
|
||||
origin: &<CallOf<T::Runtime> as Dispatchable>::RuntimeOrigin,
|
||||
_call: &CallOf<T::Runtime>,
|
||||
_info: &DispatchInfoOf<CallOf<T::Runtime>>,
|
||||
_len: usize,
|
||||
_context: &Context,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
// this is a relevant piece of `validate` that we need here (in `pre_dispatch`)
|
||||
let parsed_call = T::parse_and_check_for_obsolete_call(call)?;
|
||||
|
||||
Ok(parsed_call.map(|call_info| {
|
||||
let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
|
||||
Ok(val.map(|call_info| {
|
||||
log::trace!(
|
||||
target: "runtime::bridge",
|
||||
"{} via {:?} parsed bridge transaction in pre-dispatch: {:?}",
|
||||
@@ -561,13 +579,14 @@ where
|
||||
}
|
||||
|
||||
fn post_dispatch(
|
||||
pre: Option<Self::Pre>,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
post_info: &PostDispatchInfoOf<Self::Call>,
|
||||
pre: Self::Pre,
|
||||
info: &DispatchInfoOf<CallOf<T::Runtime>>,
|
||||
post_info: &PostDispatchInfoOf<CallOf<T::Runtime>>,
|
||||
len: usize,
|
||||
result: &DispatchResult,
|
||||
_context: &Context,
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
let call_result = T::analyze_call_result(pre, info, post_info, len, result);
|
||||
let call_result = T::analyze_call_result(Some(pre), info, post_info, len, result);
|
||||
|
||||
match call_result {
|
||||
RelayerAccountAction::None => (),
|
||||
@@ -595,7 +614,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Signed extension that refunds a relayer for new messages coming from a parachain.
|
||||
/// Transaction extension that refunds a relayer for new messages coming from a parachain.
|
||||
///
|
||||
/// Also refunds relayer for successful finality delivery if it comes in batch (`utility.batchAll`)
|
||||
/// with message delivery transaction. Batch may deliver either both relay chain header and
|
||||
@@ -636,7 +655,7 @@ pub struct RefundBridgedParachainMessages<Runtime, Para, Msgs, Refund, Priority,
|
||||
)>,
|
||||
);
|
||||
|
||||
impl<Runtime, Para, Msgs, Refund, Priority, Id> RefundSignedExtension
|
||||
impl<Runtime, Para, Msgs, Refund, Priority, Id> RefundTransactionExtension
|
||||
for RefundBridgedParachainMessages<Runtime, Para, Msgs, Refund, Priority, Id>
|
||||
where
|
||||
Self: 'static + Send + Sync,
|
||||
@@ -730,13 +749,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Signed extension that refunds a relayer for new messages coming from a standalone (GRANDPA)
|
||||
/// Transaction extension that refunds a relayer for new messages coming from a standalone (GRANDPA)
|
||||
/// chain.
|
||||
///
|
||||
/// Also refunds relayer for successful finality delivery if it comes in batch (`utility.batchAll`)
|
||||
/// with message delivery transaction. Batch may deliver either both relay chain header and
|
||||
/// parachain head, or just parachain head. Corresponding headers must be used in messages
|
||||
/// proof verification.
|
||||
/// parachain head, or just parachain head. Corresponding headers must be used in messages proof
|
||||
/// verification.
|
||||
///
|
||||
/// Extension does not refund transaction tip due to security reasons.
|
||||
#[derive(
|
||||
@@ -771,7 +790,7 @@ pub struct RefundBridgedGrandpaMessages<Runtime, GrandpaInstance, Msgs, Refund,
|
||||
)>,
|
||||
);
|
||||
|
||||
impl<Runtime, GrandpaInstance, Msgs, Refund, Priority, Id> RefundSignedExtension
|
||||
impl<Runtime, GrandpaInstance, Msgs, Refund, Priority, Id> RefundTransactionExtension
|
||||
for RefundBridgedGrandpaMessages<Runtime, GrandpaInstance, Msgs, Refund, Priority, Id>
|
||||
where
|
||||
Self: 'static + Send + Sync,
|
||||
@@ -869,8 +888,8 @@ mod tests {
|
||||
Call as ParachainsCall, Pallet as ParachainsPallet, RelayBlockHash,
|
||||
};
|
||||
use sp_runtime::{
|
||||
traits::{ConstU64, Header as HeaderT},
|
||||
transaction_validity::{InvalidTransaction, ValidTransaction},
|
||||
traits::{ConstU64, DispatchTransaction, Header as HeaderT},
|
||||
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
|
||||
DispatchError,
|
||||
};
|
||||
|
||||
@@ -899,7 +918,7 @@ mod tests {
|
||||
ConstU64<1>,
|
||||
StrTestExtension,
|
||||
>;
|
||||
type TestGrandpaExtension = RefundSignedExtensionAdapter<TestGrandpaExtensionProvider>;
|
||||
type TestGrandpaExtension = RefundTransactionExtensionAdapter<TestGrandpaExtensionProvider>;
|
||||
type TestExtensionProvider = RefundBridgedParachainMessages<
|
||||
TestRuntime,
|
||||
DefaultRefundableParachainId<(), TestParachain>,
|
||||
@@ -908,7 +927,7 @@ mod tests {
|
||||
ConstU64<1>,
|
||||
StrTestExtension,
|
||||
>;
|
||||
type TestExtension = RefundSignedExtensionAdapter<TestExtensionProvider>;
|
||||
type TestExtension = RefundTransactionExtensionAdapter<TestExtensionProvider>;
|
||||
|
||||
fn initial_balance_of_relayer_account_at_this_chain() -> ThisChainBalance {
|
||||
let test_stake: ThisChainBalance = TestStake::get();
|
||||
@@ -1407,14 +1426,28 @@ mod tests {
|
||||
|
||||
fn run_validate(call: RuntimeCall) -> TransactionValidity {
|
||||
let extension: TestExtension =
|
||||
RefundSignedExtensionAdapter(RefundBridgedParachainMessages(PhantomData));
|
||||
extension.validate(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||
RefundTransactionExtensionAdapter(RefundBridgedParachainMessages(PhantomData));
|
||||
extension
|
||||
.validate_only(
|
||||
Some(relayer_account_at_this_chain()).into(),
|
||||
&call,
|
||||
&DispatchInfo::default(),
|
||||
0,
|
||||
)
|
||||
.map(|res| res.0)
|
||||
}
|
||||
|
||||
fn run_grandpa_validate(call: RuntimeCall) -> TransactionValidity {
|
||||
let extension: TestGrandpaExtension =
|
||||
RefundSignedExtensionAdapter(RefundBridgedGrandpaMessages(PhantomData));
|
||||
extension.validate(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||
RefundTransactionExtensionAdapter(RefundBridgedGrandpaMessages(PhantomData));
|
||||
extension
|
||||
.validate_only(
|
||||
Some(relayer_account_at_this_chain()).into(),
|
||||
&call,
|
||||
&DispatchInfo::default(),
|
||||
0,
|
||||
)
|
||||
.map(|res| res.0)
|
||||
}
|
||||
|
||||
fn run_validate_ignore_priority(call: RuntimeCall) -> TransactionValidity {
|
||||
@@ -1428,16 +1461,30 @@ mod tests {
|
||||
call: RuntimeCall,
|
||||
) -> Result<Option<PreDispatchData<ThisChainAccountId>>, TransactionValidityError> {
|
||||
let extension: TestExtension =
|
||||
RefundSignedExtensionAdapter(RefundBridgedParachainMessages(PhantomData));
|
||||
extension.pre_dispatch(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||
RefundTransactionExtensionAdapter(RefundBridgedParachainMessages(PhantomData));
|
||||
extension
|
||||
.validate_and_prepare(
|
||||
Some(relayer_account_at_this_chain()).into(),
|
||||
&call,
|
||||
&DispatchInfo::default(),
|
||||
0,
|
||||
)
|
||||
.map(|(pre, _)| pre)
|
||||
}
|
||||
|
||||
fn run_grandpa_pre_dispatch(
|
||||
call: RuntimeCall,
|
||||
) -> Result<Option<PreDispatchData<ThisChainAccountId>>, TransactionValidityError> {
|
||||
let extension: TestGrandpaExtension =
|
||||
RefundSignedExtensionAdapter(RefundBridgedGrandpaMessages(PhantomData));
|
||||
extension.pre_dispatch(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||
RefundTransactionExtensionAdapter(RefundBridgedGrandpaMessages(PhantomData));
|
||||
extension
|
||||
.validate_and_prepare(
|
||||
Some(relayer_account_at_this_chain()).into(),
|
||||
&call,
|
||||
&DispatchInfo::default(),
|
||||
0,
|
||||
)
|
||||
.map(|(pre, _)| pre)
|
||||
}
|
||||
|
||||
fn dispatch_info() -> DispatchInfo {
|
||||
@@ -1460,11 +1507,12 @@ mod tests {
|
||||
dispatch_result: DispatchResult,
|
||||
) {
|
||||
let post_dispatch_result = TestExtension::post_dispatch(
|
||||
Some(pre_dispatch_data),
|
||||
pre_dispatch_data,
|
||||
&dispatch_info(),
|
||||
&post_dispatch_info(),
|
||||
1024,
|
||||
&dispatch_result,
|
||||
&(),
|
||||
);
|
||||
assert_eq!(post_dispatch_result, Ok(()));
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", optional = true }
|
||||
serde = { optional = true, workspace = true }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ workspace = true
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
finality-grandpa = { version = "0.16.2", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
@@ -11,7 +11,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
@@ -11,7 +11,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
@@ -11,7 +11,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive", "serde"] }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
@@ -11,7 +11,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
@@ -12,7 +12,7 @@ workspace = true
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
serde = { default-features = false, features = ["alloc", "derive"], workspace = true }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use bp_polkadot_core::{
|
||||
};
|
||||
|
||||
use bp_messages::*;
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtension;
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtension;
|
||||
use bp_runtime::extensions::{
|
||||
BridgeRejectObsoleteHeadersAndMessages, RefundBridgedParachainMessagesSchema,
|
||||
};
|
||||
@@ -164,7 +164,7 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
|
||||
|
||||
/// Signed extension that is used by all bridge hubs.
|
||||
pub type SignedExtension = SuffixedCommonSignedExtension<(
|
||||
pub type TransactionExtension = SuffixedCommonTransactionExtension<(
|
||||
BridgeRejectObsoleteHeadersAndMessages,
|
||||
RefundBridgedParachainMessagesSchema,
|
||||
)>;
|
||||
|
||||
@@ -107,5 +107,5 @@ frame_support::parameter_types! {
|
||||
|
||||
/// Transaction fee that is paid at the Rococo BridgeHub for delivering single outbound message confirmation.
|
||||
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_complex_message_confirmation_transaction` + `33%`)
|
||||
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 5_380_829_647;
|
||||
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 5_380_904_835;
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ impl ChainWithGrandpa for Kusama {
|
||||
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
|
||||
}
|
||||
|
||||
// The SignedExtension used by Kusama.
|
||||
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;
|
||||
// The TransactionExtension used by Kusama.
|
||||
pub use bp_polkadot_core::CommonTransactionExtension as TransactionExtension;
|
||||
|
||||
/// Name of the parachains pallet in the Kusama runtime.
|
||||
pub const PARAS_PALLET_NAME: &str = "Paras";
|
||||
|
||||
@@ -25,7 +25,7 @@ use bp_runtime::{
|
||||
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis,
|
||||
extensions::{
|
||||
CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
|
||||
CheckWeight, GenericSignedExtension, GenericSignedExtensionSchema,
|
||||
CheckWeight, GenericTransactionExtension, GenericTransactionExtensionSchema,
|
||||
},
|
||||
Chain, ChainId, TransactionEra,
|
||||
};
|
||||
@@ -37,7 +37,12 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::limits;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{traits::DispatchInfoOf, transaction_validity::TransactionValidityError, Perbill};
|
||||
use sp_runtime::{
|
||||
impl_tx_ext_default,
|
||||
traits::{Dispatchable, TransactionExtensionBase},
|
||||
transaction_validity::TransactionValidityError,
|
||||
Perbill,
|
||||
};
|
||||
|
||||
// This chain reuses most of Polkadot primitives.
|
||||
pub use bp_polkadot_core::{
|
||||
@@ -71,10 +76,10 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
|
||||
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
|
||||
|
||||
/// This signed extension is used to ensure that the chain transactions are signed by proper
|
||||
pub type ValidateSigned = GenericSignedExtensionSchema<(), ()>;
|
||||
pub type ValidateSigned = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
/// Signed extension schema, used by Polkadot Bulletin.
|
||||
pub type SignedExtensionSchema = GenericSignedExtension<(
|
||||
pub type TransactionExtensionSchema = GenericTransactionExtension<(
|
||||
(
|
||||
CheckNonZeroSender,
|
||||
CheckSpecVersion,
|
||||
@@ -87,34 +92,30 @@ pub type SignedExtensionSchema = GenericSignedExtension<(
|
||||
ValidateSigned,
|
||||
)>;
|
||||
|
||||
/// Signed extension, used by Polkadot Bulletin.
|
||||
/// Transaction extension, used by Polkadot Bulletin.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
pub struct SignedExtension(SignedExtensionSchema);
|
||||
pub struct TransactionExtension(TransactionExtensionSchema);
|
||||
|
||||
impl sp_runtime::traits::SignedExtension for SignedExtension {
|
||||
impl TransactionExtensionBase for TransactionExtension {
|
||||
const IDENTIFIER: &'static str = "Not needed.";
|
||||
type AccountId = ();
|
||||
type Call = ();
|
||||
type AdditionalSigned =
|
||||
<SignedExtensionSchema as sp_runtime::traits::SignedExtension>::AdditionalSigned;
|
||||
type Pre = ();
|
||||
type Implicit = <TransactionExtensionSchema as TransactionExtensionBase>::Implicit;
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
self.0.additional_signed()
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
_who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(())
|
||||
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
|
||||
<TransactionExtensionSchema as TransactionExtensionBase>::implicit(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl SignedExtension {
|
||||
impl<C, Context> sp_runtime::traits::TransactionExtension<C, Context> for TransactionExtension
|
||||
where
|
||||
C: Dispatchable,
|
||||
{
|
||||
type Pre = ();
|
||||
type Val = ();
|
||||
|
||||
impl_tx_ext_default!(C; Context; validate prepare);
|
||||
}
|
||||
|
||||
impl TransactionExtension {
|
||||
/// Create signed extension from its components.
|
||||
pub fn from_params(
|
||||
spec_version: u32,
|
||||
@@ -123,7 +124,7 @@ impl SignedExtension {
|
||||
genesis_hash: Hash,
|
||||
nonce: Nonce,
|
||||
) -> Self {
|
||||
Self(GenericSignedExtension::new(
|
||||
Self(GenericTransactionExtension::new(
|
||||
(
|
||||
(
|
||||
(), // non-zero sender
|
||||
|
||||
@@ -61,8 +61,8 @@ impl ChainWithGrandpa for Polkadot {
|
||||
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
|
||||
}
|
||||
|
||||
/// The SignedExtension used by Polkadot.
|
||||
pub type SignedExtension = SuffixedCommonSignedExtension<PrevalidateAttests>;
|
||||
/// The TransactionExtension used by Polkadot.
|
||||
pub type TransactionExtension = SuffixedCommonTransactionExtension<PrevalidateAttests>;
|
||||
|
||||
/// Name of the parachains pallet in the Polkadot runtime.
|
||||
pub const PARAS_PALLET_NAME: &str = "Paras";
|
||||
|
||||
@@ -59,8 +59,8 @@ impl ChainWithGrandpa for Rococo {
|
||||
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
|
||||
}
|
||||
|
||||
// The SignedExtension used by Rococo.
|
||||
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;
|
||||
// The TransactionExtension used by Rococo.
|
||||
pub use bp_polkadot_core::CommonTransactionExtension as TransactionExtension;
|
||||
|
||||
/// Name of the parachains pallet in the Rococo runtime.
|
||||
pub const PARAS_PALLET_NAME: &str = "Paras";
|
||||
|
||||
@@ -59,8 +59,8 @@ impl ChainWithGrandpa for Westend {
|
||||
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
|
||||
}
|
||||
|
||||
// The SignedExtension used by Westend.
|
||||
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;
|
||||
// The TransactionExtension used by Westend.
|
||||
pub use bp_polkadot_core::CommonTransactionExtension as TransactionExtension;
|
||||
|
||||
/// Name of the parachains pallet in the Rococo runtime.
|
||||
pub const PARAS_PALLET_NAME: &str = "Paras";
|
||||
|
||||
@@ -13,7 +13,7 @@ workspace = true
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
finality-grandpa = { version = "0.16.2", default-features = false }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
serde = { features = ["alloc", "derive"], workspace = true }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ workspace = true
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
serde = { features = ["alloc", "derive"], workspace = true }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ workspace = true
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
|
||||
parity-util-mem = { version = "0.12.0", optional = true }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
serde = { default-features = false, features = ["derive"], optional = true, workspace = true }
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ use bp_runtime::{
|
||||
self,
|
||||
extensions::{
|
||||
ChargeTransactionPayment, CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce,
|
||||
CheckSpecVersion, CheckTxVersion, CheckWeight, GenericSignedExtension,
|
||||
SignedExtensionSchema,
|
||||
CheckSpecVersion, CheckTxVersion, CheckWeight, GenericTransactionExtension,
|
||||
TransactionExtensionSchema,
|
||||
},
|
||||
EncodedOrDecodedCall, StorageMapKeyProvider, TransactionEra,
|
||||
};
|
||||
@@ -229,8 +229,12 @@ pub type SignedBlock = generic::SignedBlock<Block>;
|
||||
pub type Balance = u128;
|
||||
|
||||
/// Unchecked Extrinsic type.
|
||||
pub type UncheckedExtrinsic<Call, SignedExt> =
|
||||
generic::UncheckedExtrinsic<AccountAddress, EncodedOrDecodedCall<Call>, Signature, SignedExt>;
|
||||
pub type UncheckedExtrinsic<Call, TransactionExt> = generic::UncheckedExtrinsic<
|
||||
AccountAddress,
|
||||
EncodedOrDecodedCall<Call>,
|
||||
Signature,
|
||||
TransactionExt,
|
||||
>;
|
||||
|
||||
/// Account address, used by the Polkadot-like chain.
|
||||
pub type Address = MultiAddress<AccountId, ()>;
|
||||
@@ -275,7 +279,7 @@ impl AccountInfoStorageMapKeyProvider {
|
||||
}
|
||||
|
||||
/// Extra signed extension data that is used by most chains.
|
||||
pub type CommonSignedExtra = (
|
||||
pub type CommonTransactionExtra = (
|
||||
CheckNonZeroSender,
|
||||
CheckSpecVersion,
|
||||
CheckTxVersion,
|
||||
@@ -286,12 +290,12 @@ pub type CommonSignedExtra = (
|
||||
ChargeTransactionPayment<Balance>,
|
||||
);
|
||||
|
||||
/// Extra signed extension data that starts with `CommonSignedExtra`.
|
||||
pub type SuffixedCommonSignedExtension<Suffix> =
|
||||
GenericSignedExtension<(CommonSignedExtra, Suffix)>;
|
||||
/// Extra transaction extension data that starts with `CommonTransactionExtra`.
|
||||
pub type SuffixedCommonTransactionExtension<Suffix> =
|
||||
GenericTransactionExtension<(CommonTransactionExtra, Suffix)>;
|
||||
|
||||
/// Helper trait to define some extra methods on `SuffixedCommonSignedExtension`.
|
||||
pub trait SuffixedCommonSignedExtensionExt<Suffix: SignedExtensionSchema> {
|
||||
/// Helper trait to define some extra methods on `SuffixedCommonTransactionExtension`.
|
||||
pub trait SuffixedCommonTransactionExtensionExt<Suffix: TransactionExtensionSchema> {
|
||||
/// Create signed extension from its components.
|
||||
fn from_params(
|
||||
spec_version: u32,
|
||||
@@ -300,7 +304,7 @@ pub trait SuffixedCommonSignedExtensionExt<Suffix: SignedExtensionSchema> {
|
||||
genesis_hash: Hash,
|
||||
nonce: Nonce,
|
||||
tip: Balance,
|
||||
extra: (Suffix::Payload, Suffix::AdditionalSigned),
|
||||
extra: (Suffix::Payload, Suffix::Implicit),
|
||||
) -> Self;
|
||||
|
||||
/// Return transaction nonce.
|
||||
@@ -310,9 +314,10 @@ pub trait SuffixedCommonSignedExtensionExt<Suffix: SignedExtensionSchema> {
|
||||
fn tip(&self) -> Balance;
|
||||
}
|
||||
|
||||
impl<Suffix> SuffixedCommonSignedExtensionExt<Suffix> for SuffixedCommonSignedExtension<Suffix>
|
||||
impl<Suffix> SuffixedCommonTransactionExtensionExt<Suffix>
|
||||
for SuffixedCommonTransactionExtension<Suffix>
|
||||
where
|
||||
Suffix: SignedExtensionSchema,
|
||||
Suffix: TransactionExtensionSchema,
|
||||
{
|
||||
fn from_params(
|
||||
spec_version: u32,
|
||||
@@ -321,9 +326,9 @@ where
|
||||
genesis_hash: Hash,
|
||||
nonce: Nonce,
|
||||
tip: Balance,
|
||||
extra: (Suffix::Payload, Suffix::AdditionalSigned),
|
||||
extra: (Suffix::Payload, Suffix::Implicit),
|
||||
) -> Self {
|
||||
GenericSignedExtension::new(
|
||||
GenericTransactionExtension::new(
|
||||
(
|
||||
(
|
||||
(), // non-zero sender
|
||||
@@ -365,7 +370,7 @@ where
|
||||
}
|
||||
|
||||
/// Signed extension that is used by most chains.
|
||||
pub type CommonSignedExtension = SuffixedCommonSignedExtension<()>;
|
||||
pub type CommonTransactionExtension = SuffixedCommonTransactionExtension<()>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -13,10 +13,10 @@ workspace = true
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
|
||||
hash-db = { version = "0.16.0", default-features = false }
|
||||
impl-trait-for-tuples = "0.2.2"
|
||||
log = { version = "0.4.21", default-features = false }
|
||||
log = { workspace = true }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
serde = { features = ["alloc", "derive"], workspace = true }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
|
||||
@@ -98,6 +98,17 @@ impl<ChainCall: Encode> Encode for EncodedOrDecodedCall<ChainCall> {
|
||||
}
|
||||
}
|
||||
|
||||
// dummy implementation to satisfy `SignedPayload` requirements
|
||||
impl<ChainCall> sp_runtime::traits::Dispatchable for EncodedOrDecodedCall<ChainCall> {
|
||||
type RuntimeOrigin = ();
|
||||
type Config = ();
|
||||
type Info = ();
|
||||
type PostInfo = ();
|
||||
fn dispatch(self, _origin: ()) -> sp_runtime::DispatchResultWithInfo<()> {
|
||||
unreachable!("never used by relayer; qed")
|
||||
}
|
||||
}
|
||||
|
||||
/// Minimal Substrate-based chain representation that may be used from no_std environment.
|
||||
pub trait Chain: Send + Sync + 'static {
|
||||
/// Chain id.
|
||||
|
||||
@@ -20,135 +20,138 @@ use codec::{Compact, Decode, Encode};
|
||||
use impl_trait_for_tuples::impl_for_tuples;
|
||||
use scale_info::{StaticTypeInfo, TypeInfo};
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, SignedExtension},
|
||||
impl_tx_ext_default,
|
||||
traits::{Dispatchable, TransactionExtension, TransactionExtensionBase},
|
||||
transaction_validity::TransactionValidityError,
|
||||
};
|
||||
use sp_std::{fmt::Debug, marker::PhantomData};
|
||||
|
||||
/// Trait that describes some properties of a `SignedExtension` that are needed in order to send a
|
||||
/// transaction to the chain.
|
||||
pub trait SignedExtensionSchema: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo {
|
||||
/// Trait that describes some properties of a `TransactionExtension` that are needed in order to
|
||||
/// send a transaction to the chain.
|
||||
pub trait TransactionExtensionSchema:
|
||||
Encode + Decode + Debug + Eq + Clone + StaticTypeInfo
|
||||
{
|
||||
/// A type of the data encoded as part of the transaction.
|
||||
type Payload: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo;
|
||||
/// Parameters which are part of the payload used to produce transaction signature,
|
||||
/// but don't end up in the transaction itself (i.e. inherent part of the runtime).
|
||||
type AdditionalSigned: Encode + Debug + Eq + Clone + StaticTypeInfo;
|
||||
type Implicit: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo;
|
||||
}
|
||||
|
||||
impl SignedExtensionSchema for () {
|
||||
impl TransactionExtensionSchema for () {
|
||||
type Payload = ();
|
||||
type AdditionalSigned = ();
|
||||
type Implicit = ();
|
||||
}
|
||||
|
||||
/// An implementation of `SignedExtensionSchema` using generic params.
|
||||
/// An implementation of `TransactionExtensionSchema` using generic params.
|
||||
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)]
|
||||
pub struct GenericSignedExtensionSchema<P, S>(PhantomData<(P, S)>);
|
||||
pub struct GenericTransactionExtensionSchema<P, S>(PhantomData<(P, S)>);
|
||||
|
||||
impl<P, S> SignedExtensionSchema for GenericSignedExtensionSchema<P, S>
|
||||
impl<P, S> TransactionExtensionSchema for GenericTransactionExtensionSchema<P, S>
|
||||
where
|
||||
P: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo,
|
||||
S: Encode + Debug + Eq + Clone + StaticTypeInfo,
|
||||
S: Encode + Decode + Debug + Eq + Clone + StaticTypeInfo,
|
||||
{
|
||||
type Payload = P;
|
||||
type AdditionalSigned = S;
|
||||
type Implicit = S;
|
||||
}
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckNonZeroSender`.
|
||||
pub type CheckNonZeroSender = GenericSignedExtensionSchema<(), ()>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckNonZeroSender`.
|
||||
pub type CheckNonZeroSender = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckSpecVersion`.
|
||||
pub type CheckSpecVersion = GenericSignedExtensionSchema<(), u32>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckSpecVersion`.
|
||||
pub type CheckSpecVersion = GenericTransactionExtensionSchema<(), u32>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckTxVersion`.
|
||||
pub type CheckTxVersion = GenericSignedExtensionSchema<(), u32>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckTxVersion`.
|
||||
pub type CheckTxVersion = GenericTransactionExtensionSchema<(), u32>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckGenesis`.
|
||||
pub type CheckGenesis<Hash> = GenericSignedExtensionSchema<(), Hash>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckGenesis`.
|
||||
pub type CheckGenesis<Hash> = GenericTransactionExtensionSchema<(), Hash>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckEra`.
|
||||
pub type CheckEra<Hash> = GenericSignedExtensionSchema<sp_runtime::generic::Era, Hash>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckEra`.
|
||||
pub type CheckEra<Hash> = GenericTransactionExtensionSchema<sp_runtime::generic::Era, Hash>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckNonce`.
|
||||
pub type CheckNonce<TxNonce> = GenericSignedExtensionSchema<Compact<TxNonce>, ()>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckNonce`.
|
||||
pub type CheckNonce<TxNonce> = GenericTransactionExtensionSchema<Compact<TxNonce>, ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `frame_system::CheckWeight`.
|
||||
pub type CheckWeight = GenericSignedExtensionSchema<(), ()>;
|
||||
/// The `TransactionExtensionSchema` for `frame_system::CheckWeight`.
|
||||
pub type CheckWeight = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `pallet_transaction_payment::ChargeTransactionPayment`.
|
||||
pub type ChargeTransactionPayment<Balance> = GenericSignedExtensionSchema<Compact<Balance>, ()>;
|
||||
/// The `TransactionExtensionSchema` for `pallet_transaction_payment::ChargeTransactionPayment`.
|
||||
pub type ChargeTransactionPayment<Balance> =
|
||||
GenericTransactionExtensionSchema<Compact<Balance>, ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `polkadot-runtime-common::PrevalidateAttests`.
|
||||
pub type PrevalidateAttests = GenericSignedExtensionSchema<(), ()>;
|
||||
/// The `TransactionExtensionSchema` for `polkadot-runtime-common::PrevalidateAttests`.
|
||||
pub type PrevalidateAttests = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `BridgeRejectObsoleteHeadersAndMessages`.
|
||||
pub type BridgeRejectObsoleteHeadersAndMessages = GenericSignedExtensionSchema<(), ()>;
|
||||
/// The `TransactionExtensionSchema` for `BridgeRejectObsoleteHeadersAndMessages`.
|
||||
pub type BridgeRejectObsoleteHeadersAndMessages = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
/// The `SignedExtensionSchema` for `RefundBridgedParachainMessages`.
|
||||
/// The `TransactionExtensionSchema` for `RefundBridgedParachainMessages`.
|
||||
/// This schema is dedicated for `RefundBridgedParachainMessages` signed extension as
|
||||
/// wildcard/placeholder, which relies on the scale encoding for `()` or `((), ())`, or `((), (),
|
||||
/// ())` is the same. So runtime can contains any kind of tuple:
|
||||
/// `(BridgeRefundBridgeHubRococoMessages)`
|
||||
/// `(BridgeRefundBridgeHubRococoMessages, BridgeRefundBridgeHubWestendMessages)`
|
||||
/// `(BridgeRefundParachainMessages1, ..., BridgeRefundParachainMessagesN)`
|
||||
pub type RefundBridgedParachainMessagesSchema = GenericSignedExtensionSchema<(), ()>;
|
||||
pub type RefundBridgedParachainMessagesSchema = GenericTransactionExtensionSchema<(), ()>;
|
||||
|
||||
#[impl_for_tuples(1, 12)]
|
||||
impl SignedExtensionSchema for Tuple {
|
||||
impl TransactionExtensionSchema for Tuple {
|
||||
for_tuples!( type Payload = ( #( Tuple::Payload ),* ); );
|
||||
for_tuples!( type AdditionalSigned = ( #( Tuple::AdditionalSigned ),* ); );
|
||||
for_tuples!( type Implicit = ( #( Tuple::Implicit ),* ); );
|
||||
}
|
||||
|
||||
/// A simplified version of signed extensions meant for producing signed transactions
|
||||
/// and signed payloads in the client code.
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
pub struct GenericSignedExtension<S: SignedExtensionSchema> {
|
||||
pub struct GenericTransactionExtension<S: TransactionExtensionSchema> {
|
||||
/// A payload that is included in the transaction.
|
||||
pub payload: S::Payload,
|
||||
#[codec(skip)]
|
||||
// It may be set to `None` if extensions are decoded. We are never reconstructing transactions
|
||||
// (and it makes no sense to do that) => decoded version of `SignedExtensions` is only used to
|
||||
// read fields of the `payload`. And when resigning transaction, we're reconstructing
|
||||
// `SignedExtensions` from scratch.
|
||||
additional_signed: Option<S::AdditionalSigned>,
|
||||
// (and it makes no sense to do that) => decoded version of `TransactionExtensions` is only
|
||||
// used to read fields of the `payload`. And when resigning transaction, we're reconstructing
|
||||
// `TransactionExtensions` from scratch.
|
||||
implicit: Option<S::Implicit>,
|
||||
}
|
||||
|
||||
impl<S: SignedExtensionSchema> GenericSignedExtension<S> {
|
||||
/// Create new `GenericSignedExtension` object.
|
||||
pub fn new(payload: S::Payload, additional_signed: Option<S::AdditionalSigned>) -> Self {
|
||||
Self { payload, additional_signed }
|
||||
impl<S: TransactionExtensionSchema> GenericTransactionExtension<S> {
|
||||
/// Create new `GenericTransactionExtension` object.
|
||||
pub fn new(payload: S::Payload, implicit: Option<S::Implicit>) -> Self {
|
||||
Self { payload, implicit }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> SignedExtension for GenericSignedExtension<S>
|
||||
impl<S> TransactionExtensionBase for GenericTransactionExtension<S>
|
||||
where
|
||||
S: SignedExtensionSchema,
|
||||
S: TransactionExtensionSchema,
|
||||
S::Payload: Send + Sync,
|
||||
S::AdditionalSigned: Send + Sync,
|
||||
S::Implicit: Send + Sync,
|
||||
{
|
||||
const IDENTIFIER: &'static str = "Not needed.";
|
||||
type AccountId = ();
|
||||
type Call = ();
|
||||
type AdditionalSigned = S::AdditionalSigned;
|
||||
type Pre = ();
|
||||
type Implicit = S::Implicit;
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
|
||||
// we shall not ever see this error in relay, because we are never signing decoded
|
||||
// transactions. Instead we're constructing and signing new transactions. So the error code
|
||||
// is kinda random here
|
||||
self.additional_signed.clone().ok_or(
|
||||
frame_support::unsigned::TransactionValidityError::Unknown(
|
||||
self.implicit
|
||||
.clone()
|
||||
.ok_or(frame_support::unsigned::TransactionValidityError::Unknown(
|
||||
frame_support::unsigned::UnknownTransaction::Custom(0xFF),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
_who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(())
|
||||
))
|
||||
}
|
||||
}
|
||||
impl<S, C, Context> TransactionExtension<C, Context> for GenericTransactionExtension<S>
|
||||
where
|
||||
C: Dispatchable,
|
||||
S: TransactionExtensionSchema,
|
||||
S::Payload: Send + Sync,
|
||||
S::Implicit: Send + Sync,
|
||||
{
|
||||
type Pre = ();
|
||||
type Val = ();
|
||||
|
||||
impl_tx_ext_default!(C; Context; validate prepare);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ pub fn make_justification_for_header<H: HeaderT>(
|
||||
votes_ancestries.push(child.clone());
|
||||
}
|
||||
|
||||
// The header we need to use when pre-commiting is the one at the highest height
|
||||
// The header we need to use when pre-committing is the one at the highest height
|
||||
// on our chain.
|
||||
let precommit_candidate = chain.last().map(|h| (h.hash(), *h.number())).unwrap();
|
||||
unsigned_precommits.push(precommit_candidate);
|
||||
|
||||
@@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "3.1.5" }
|
||||
env_logger = "0.11"
|
||||
futures = "0.3.30"
|
||||
hex = "0.4"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-format = "0.4"
|
||||
num-traits = "0.2"
|
||||
rbtag = "0.3"
|
||||
|
||||
@@ -125,18 +125,6 @@ impl relay_substrate_client::ChainWithTransactions for RococoAsPolkadot {
|
||||
unsigned.switch_chain(),
|
||||
)
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
relay_rococo_client::Rococo::is_signed(tx)
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
relay_rococo_client::Rococo::is_signed_by(signer, tx)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
relay_rococo_client::Rococo::parse_transaction(tx).map(|tx| tx.switch_chain())
|
||||
}
|
||||
}
|
||||
|
||||
impl CliChain for RococoAsPolkadot {
|
||||
@@ -232,19 +220,6 @@ impl relay_substrate_client::ChainWithTransactions for BridgeHubRococoAsBridgeHu
|
||||
unsigned.switch_chain(),
|
||||
)
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
relay_bridge_hub_rococo_client::BridgeHubRococo::is_signed(tx)
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
relay_bridge_hub_rococo_client::BridgeHubRococo::is_signed_by(signer, tx)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
relay_bridge_hub_rococo_client::BridgeHubRococo::parse_transaction(tx)
|
||||
.map(|tx| tx.switch_chain())
|
||||
}
|
||||
}
|
||||
|
||||
impl relay_substrate_client::ChainWithMessages for BridgeHubRococoAsBridgeHubPolkadot {
|
||||
|
||||
@@ -392,7 +392,7 @@ pub mod api {
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundBridgedParachainMessages;
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundSignedExtensionAdapter<_0>(pub _0);
|
||||
pub struct RefundTransactionExtensionAdapter<_0>(pub _0);
|
||||
}
|
||||
}
|
||||
pub mod cumulus_pallet_dmp_queue {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_bridge_hub_kusama::{SignedExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot::SuffixedCommonSignedExtensionExt;
|
||||
use bp_bridge_hub_kusama::{TransactionExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
calls::UtilityCall as MockUtilityCall, Chain, ChainWithBalances, ChainWithMessages,
|
||||
@@ -36,7 +36,8 @@ pub type RuntimeCall = runtime_types::bridge_hub_kusama_runtime::RuntimeCall;
|
||||
pub type BridgeMessagesCall = runtime_types::pallet_bridge_messages::pallet::Call;
|
||||
pub type BridgeGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeParachainCall = runtime_types::pallet_bridge_parachains::pallet::Call;
|
||||
type UncheckedExtrinsic = bp_bridge_hub_kusama::UncheckedExtrinsic<RuntimeCall, SignedExtension>;
|
||||
type UncheckedExtrinsic =
|
||||
bp_bridge_hub_kusama::UncheckedExtrinsic<RuntimeCall, TransactionExtension>;
|
||||
type UtilityCall = runtime_types::pallet_utility::pallet::Call;
|
||||
|
||||
/// Kusama chain definition
|
||||
@@ -86,7 +87,7 @@ impl ChainWithTransactions for BridgeHubKusama {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
SignedExtension::from_params(
|
||||
TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -108,24 +109,6 @@ impl ChainWithTransactions for BridgeHubKusama {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| {
|
||||
*address == bp_bridge_hub_kusama::Address::Id(signer.public().into())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainWithMessages for BridgeHubKusama {
|
||||
@@ -137,34 +120,3 @@ impl ChainWithMessages for BridgeHubKusama {
|
||||
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_bridge_hub_kusama::FROM_BRIDGE_HUB_KUSAMA_MESSAGE_DETAILS_METHOD;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use relay_substrate_client::TransactionEra;
|
||||
|
||||
type SystemCall = runtime_types::frame_system::pallet::Call;
|
||||
|
||||
#[test]
|
||||
fn parse_transaction_works() {
|
||||
let unsigned = UnsignedTransaction {
|
||||
call: RuntimeCall::System(SystemCall::remark { remark: b"Hello world!".to_vec() })
|
||||
.into(),
|
||||
nonce: 777,
|
||||
tip: 888,
|
||||
era: TransactionEra::immortal(),
|
||||
};
|
||||
let signed_transaction = BridgeHubKusama::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 42,
|
||||
transaction_version: 50000,
|
||||
genesis_hash: [42u8; 32].into(),
|
||||
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||
},
|
||||
unsigned.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let parsed_transaction = BridgeHubKusama::parse_transaction(signed_transaction).unwrap();
|
||||
assert_eq!(parsed_transaction, unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
pub use bp_bridge_hub_kusama::SignedExtension;
|
||||
pub use bp_bridge_hub_kusama::TransactionExtension;
|
||||
pub use bp_header_chain::BridgeGrandpaCallOf;
|
||||
pub use bp_parachains::BridgeParachainCall;
|
||||
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
|
||||
pub use relay_substrate_client::calls::{SystemCall, UtilityCall};
|
||||
|
||||
/// Unchecked BridgeHubKusama extrinsic.
|
||||
pub type UncheckedExtrinsic = bp_bridge_hub_kusama::UncheckedExtrinsic<Call, SignedExtension>;
|
||||
pub type UncheckedExtrinsic = bp_bridge_hub_kusama::UncheckedExtrinsic<Call, TransactionExtension>;
|
||||
|
||||
// The indirect pallet call used to sync `Polkadot` GRANDPA finality to `BHKusama`.
|
||||
pub type BridgePolkadotGrandpaCall = BridgeGrandpaCallOf<bp_polkadot::Polkadot>;
|
||||
|
||||
@@ -392,7 +392,7 @@ pub mod api {
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundBridgedParachainMessages;
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundSignedExtensionAdapter<_0>(pub _0);
|
||||
pub struct RefundTransactionExtensionAdapter<_0>(pub _0);
|
||||
}
|
||||
}
|
||||
pub mod cumulus_pallet_dmp_queue {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_bridge_hub_polkadot::{SignedExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_bridge_hub_polkadot::{TransactionExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
calls::UtilityCall as MockUtilityCall, Chain, ChainWithBalances, ChainWithMessages,
|
||||
@@ -40,7 +40,8 @@ pub type BridgeKusamaMessagesCall = runtime_types::pallet_bridge_messages::palle
|
||||
pub type BridgePolkadotBulletinGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeKusamaGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeParachainCall = runtime_types::pallet_bridge_parachains::pallet::Call;
|
||||
type UncheckedExtrinsic = bp_bridge_hub_polkadot::UncheckedExtrinsic<RuntimeCall, SignedExtension>;
|
||||
type UncheckedExtrinsic =
|
||||
bp_bridge_hub_polkadot::UncheckedExtrinsic<RuntimeCall, TransactionExtension>;
|
||||
type UtilityCall = runtime_types::pallet_utility::pallet::Call;
|
||||
|
||||
/// Polkadot chain definition
|
||||
@@ -90,7 +91,7 @@ impl ChainWithTransactions for BridgeHubPolkadot {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
SignedExtension::from_params(
|
||||
TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -112,24 +113,6 @@ impl ChainWithTransactions for BridgeHubPolkadot {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| {
|
||||
*address == bp_bridge_hub_polkadot::Address::Id(signer.public().into())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainWithMessages for BridgeHubPolkadot {
|
||||
@@ -141,34 +124,3 @@ impl ChainWithMessages for BridgeHubPolkadot {
|
||||
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_bridge_hub_polkadot::FROM_BRIDGE_HUB_POLKADOT_MESSAGE_DETAILS_METHOD;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use relay_substrate_client::TransactionEra;
|
||||
|
||||
type SystemCall = runtime_types::frame_system::pallet::Call;
|
||||
|
||||
#[test]
|
||||
fn parse_transaction_works() {
|
||||
let unsigned = UnsignedTransaction {
|
||||
call: RuntimeCall::System(SystemCall::remark { remark: b"Hello world!".to_vec() })
|
||||
.into(),
|
||||
nonce: 777,
|
||||
tip: 888,
|
||||
era: TransactionEra::immortal(),
|
||||
};
|
||||
let signed_transaction = BridgeHubPolkadot::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 42,
|
||||
transaction_version: 50000,
|
||||
genesis_hash: [42u8; 32].into(),
|
||||
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||
},
|
||||
unsigned.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let parsed_transaction = BridgeHubPolkadot::parse_transaction(signed_transaction).unwrap();
|
||||
assert_eq!(parsed_transaction, unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
pub use bp_bridge_hub_polkadot::SignedExtension;
|
||||
pub use bp_bridge_hub_polkadot::TransactionExtension;
|
||||
pub use bp_header_chain::BridgeGrandpaCallOf;
|
||||
pub use bp_parachains::BridgeParachainCall;
|
||||
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
|
||||
pub use relay_substrate_client::calls::{SystemCall, UtilityCall};
|
||||
|
||||
/// Unchecked BridgeHubPolkadot extrinsic.
|
||||
pub type UncheckedExtrinsic = bp_bridge_hub_polkadot::UncheckedExtrinsic<Call, SignedExtension>;
|
||||
pub type UncheckedExtrinsic = bp_bridge_hub_polkadot::UncheckedExtrinsic<Call, TransactionExtension>;
|
||||
|
||||
/// The indirect pallet call used to sync `Kusama` GRANDPA finality to `BHPolkadot`.
|
||||
pub type BridgeKusamaGrandpaCall = BridgeGrandpaCallOf<bp_kusama::Kusama>;
|
||||
|
||||
@@ -463,7 +463,7 @@ pub mod api {
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundBridgedParachainMessages;
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundSignedExtensionAdapter<_0>(pub _0);
|
||||
pub struct RefundTransactionExtensionAdapter<_0>(pub _0);
|
||||
}
|
||||
}
|
||||
pub mod cumulus_pallet_parachain_system {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_bridge_hub_rococo::{SignedExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_bridge_hub_rococo::{TransactionExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
calls::UtilityCall as MockUtilityCall, Chain, ChainWithBalances, ChainWithMessages,
|
||||
@@ -38,7 +38,8 @@ pub type BridgeBulletinMessagesCall = runtime_types::pallet_bridge_messages::pal
|
||||
pub type BridgeGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeBulletinGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call2;
|
||||
pub type BridgeParachainCall = runtime_types::pallet_bridge_parachains::pallet::Call;
|
||||
type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic<RuntimeCall, SignedExtension>;
|
||||
type UncheckedExtrinsic =
|
||||
bp_bridge_hub_rococo::UncheckedExtrinsic<RuntimeCall, TransactionExtension>;
|
||||
type UtilityCall = runtime_types::pallet_utility::pallet::Call;
|
||||
|
||||
/// Rococo chain definition
|
||||
@@ -88,7 +89,7 @@ impl ChainWithTransactions for BridgeHubRococo {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
SignedExtension::from_params(
|
||||
TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -110,24 +111,6 @@ impl ChainWithTransactions for BridgeHubRococo {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| {
|
||||
*address == bp_bridge_hub_rococo::Address::Id(signer.public().into())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainWithMessages for BridgeHubRococo {
|
||||
@@ -139,34 +122,3 @@ impl ChainWithMessages for BridgeHubRococo {
|
||||
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_bridge_hub_rococo::FROM_BRIDGE_HUB_ROCOCO_MESSAGE_DETAILS_METHOD;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use relay_substrate_client::TransactionEra;
|
||||
|
||||
type SystemCall = runtime_types::frame_system::pallet::Call;
|
||||
|
||||
#[test]
|
||||
fn parse_transaction_works() {
|
||||
let unsigned = UnsignedTransaction {
|
||||
call: RuntimeCall::System(SystemCall::remark { remark: b"Hello world!".to_vec() })
|
||||
.into(),
|
||||
nonce: 777,
|
||||
tip: 888,
|
||||
era: TransactionEra::immortal(),
|
||||
};
|
||||
let signed_transaction = BridgeHubRococo::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 42,
|
||||
transaction_version: 50000,
|
||||
genesis_hash: [42u8; 32].into(),
|
||||
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||
},
|
||||
unsigned.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let parsed_transaction = BridgeHubRococo::parse_transaction(signed_transaction).unwrap();
|
||||
assert_eq!(parsed_transaction, unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ pub mod api {
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundBridgedParachainMessages;
|
||||
#[derive(:: codec :: Decode, :: codec :: Encode, Clone, Debug, PartialEq)]
|
||||
pub struct RefundSignedExtensionAdapter<_0>(pub _0);
|
||||
pub struct RefundTransactionExtensionAdapter<_0>(pub _0);
|
||||
}
|
||||
}
|
||||
pub mod cumulus_pallet_parachain_system {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_bridge_hub_westend::{SignedExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_bridge_hub_westend::{TransactionExtension, AVERAGE_BLOCK_INTERVAL};
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
calls::UtilityCall as MockUtilityCall, Chain, ChainWithBalances, ChainWithMessages,
|
||||
@@ -36,7 +36,8 @@ pub type RuntimeCall = runtime_types::bridge_hub_westend_runtime::RuntimeCall;
|
||||
pub type BridgeMessagesCall = runtime_types::pallet_bridge_messages::pallet::Call;
|
||||
pub type BridgeGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeParachainCall = runtime_types::pallet_bridge_parachains::pallet::Call;
|
||||
type UncheckedExtrinsic = bp_bridge_hub_westend::UncheckedExtrinsic<RuntimeCall, SignedExtension>;
|
||||
type UncheckedExtrinsic =
|
||||
bp_bridge_hub_westend::UncheckedExtrinsic<RuntimeCall, TransactionExtension>;
|
||||
type UtilityCall = runtime_types::pallet_utility::pallet::Call;
|
||||
|
||||
/// Westend chain definition
|
||||
@@ -86,7 +87,7 @@ impl ChainWithTransactions for BridgeHubWestend {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
SignedExtension::from_params(
|
||||
TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -108,24 +109,6 @@ impl ChainWithTransactions for BridgeHubWestend {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| {
|
||||
*address == bp_bridge_hub_westend::Address::Id(signer.public().into())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainWithMessages for BridgeHubWestend {
|
||||
@@ -137,34 +120,3 @@ impl ChainWithMessages for BridgeHubWestend {
|
||||
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_bridge_hub_westend::FROM_BRIDGE_HUB_WESTEND_MESSAGE_DETAILS_METHOD;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use relay_substrate_client::TransactionEra;
|
||||
|
||||
type SystemCall = runtime_types::frame_system::pallet::Call;
|
||||
|
||||
#[test]
|
||||
fn parse_transaction_works() {
|
||||
let unsigned = UnsignedTransaction {
|
||||
call: RuntimeCall::System(SystemCall::remark { remark: b"Hello world!".to_vec() })
|
||||
.into(),
|
||||
nonce: 777,
|
||||
tip: 888,
|
||||
era: TransactionEra::immortal(),
|
||||
};
|
||||
let signed_transaction = BridgeHubWestend::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 42,
|
||||
transaction_version: 50000,
|
||||
genesis_hash: [42u8; 32].into(),
|
||||
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
|
||||
},
|
||||
unsigned.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let parsed_transaction = BridgeHubWestend::parse_transaction(signed_transaction).unwrap();
|
||||
assert_eq!(parsed_transaction, unsigned);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_kusama::{AccountInfoStorageMapKeyProvider, KUSAMA_SYNCED_HEADERS_GRANDPA_INFO_METHOD};
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainWithBalances, ChainWithGrandpa, ChainWithTransactions, Error as SubstrateError,
|
||||
@@ -83,7 +83,7 @@ impl RelayChain for Kusama {
|
||||
impl ChainWithTransactions for Kusama {
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction =
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_kusama::SignedExtension>;
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_kusama::TransactionExtension>;
|
||||
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
@@ -91,7 +91,7 @@ impl ChainWithTransactions for Kusama {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
bp_kusama::SignedExtension::from_params(
|
||||
bp_kusama::TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -113,20 +113,4 @@ impl ChainWithTransactions for Kusama {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,10 @@ impl ChainWithBalances for PolkadotBulletin {
|
||||
|
||||
impl ChainWithTransactions for PolkadotBulletin {
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction =
|
||||
bp_polkadot_bulletin::UncheckedExtrinsic<Self::Call, bp_polkadot_bulletin::SignedExtension>;
|
||||
type SignedTransaction = bp_polkadot_bulletin::UncheckedExtrinsic<
|
||||
Self::Call,
|
||||
bp_polkadot_bulletin::TransactionExtension,
|
||||
>;
|
||||
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
@@ -108,7 +110,7 @@ impl ChainWithTransactions for PolkadotBulletin {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
bp_polkadot_bulletin::SignedExtension::from_params(
|
||||
bp_polkadot_bulletin::TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -128,20 +130,4 @@ impl ChainWithTransactions for PolkadotBulletin {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
mod codegen_runtime;
|
||||
|
||||
use bp_polkadot::{AccountInfoStorageMapKeyProvider, POLKADOT_SYNCED_HEADERS_GRANDPA_INFO_METHOD};
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainWithBalances, ChainWithGrandpa, ChainWithTransactions, Error as SubstrateError,
|
||||
@@ -83,7 +83,7 @@ impl RelayChain for Polkadot {
|
||||
impl ChainWithTransactions for Polkadot {
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction =
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_polkadot::SignedExtension>;
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_polkadot::TransactionExtension>;
|
||||
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
@@ -91,7 +91,7 @@ impl ChainWithTransactions for Polkadot {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
bp_polkadot::SignedExtension::from_params(
|
||||
bp_polkadot::TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -113,20 +113,4 @@ impl ChainWithTransactions for Polkadot {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use bp_rococo::ROCOCO_SYNCED_HEADERS_GRANDPA_INFO_METHOD;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
@@ -83,7 +83,7 @@ impl RelayChain for Rococo {
|
||||
impl ChainWithTransactions for Rococo {
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction =
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_rococo::SignedExtension>;
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_rococo::TransactionExtension>;
|
||||
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
@@ -91,7 +91,7 @@ impl ChainWithTransactions for Rococo {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
bp_rococo::SignedExtension::from_params(
|
||||
bp_rococo::TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -113,20 +113,4 @@ impl ChainWithTransactions for Rococo {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ async-trait = "0.1"
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5" }
|
||||
futures = "0.3.30"
|
||||
jsonrpsee = { version = "0.17", features = ["macros", "ws-client"] }
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-traits = "0.2"
|
||||
rand = "0.8"
|
||||
scale-info = { version = "2.10.0", features = ["derive"] }
|
||||
tokio = { version = "1.36", features = ["rt-multi-thread"] }
|
||||
thiserror = "1.0.57"
|
||||
thiserror = { workspace = true }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
|
||||
@@ -203,17 +203,6 @@ pub trait ChainWithTransactions: Chain {
|
||||
) -> Result<Self::SignedTransaction, crate::Error>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
/// Returns true if transaction is signed.
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool;
|
||||
|
||||
/// Returns true if transaction is signed by given signer.
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool;
|
||||
|
||||
/// Parse signed transaction into its unsigned part.
|
||||
///
|
||||
/// Returns `None` if signed transaction has unsupported format.
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>>;
|
||||
}
|
||||
|
||||
/// Sign transaction parameters
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
|
||||
use bp_polkadot_core::SuffixedCommonTransactionExtensionExt;
|
||||
use bp_westend::WESTEND_SYNCED_HEADERS_GRANDPA_INFO_METHOD;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
@@ -83,7 +83,7 @@ impl ChainWithBalances for Westend {
|
||||
impl ChainWithTransactions for Westend {
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction =
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_westend::SignedExtension>;
|
||||
bp_polkadot_core::UncheckedExtrinsic<Self::Call, bp_westend::TransactionExtension>;
|
||||
|
||||
fn sign_transaction(
|
||||
param: SignParam<Self>,
|
||||
@@ -91,7 +91,7 @@ impl ChainWithTransactions for Westend {
|
||||
) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::new(
|
||||
unsigned.call,
|
||||
bp_westend::SignedExtension::from_params(
|
||||
bp_westend::TransactionExtension::from_params(
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
unsigned.era,
|
||||
@@ -113,20 +113,4 @@ impl ChainWithTransactions for Westend {
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
|
||||
let extra = &tx.signature.as_ref()?.2;
|
||||
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@ bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
finality-relay = { path = "../finality" }
|
||||
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master" }
|
||||
futures = "0.3.30"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-traits = "0.2"
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
@@ -15,7 +15,7 @@ async-trait = "0.1"
|
||||
backoff = "0.4"
|
||||
bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
futures = "0.3.30"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-traits = "0.2"
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
thiserror = "1.0.57"
|
||||
thiserror = { workspace = true }
|
||||
async-std = "1.9.0"
|
||||
async-trait = "0.1"
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5" }
|
||||
futures = "0.3.30"
|
||||
hex = "0.4"
|
||||
num-traits = "0.2"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ async-trait = "0.1"
|
||||
env_logger = "0.11"
|
||||
futures = "0.3.30"
|
||||
hex = "0.4"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-traits = "0.2"
|
||||
parking_lot = "0.12.1"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ workspace = true
|
||||
async-std = "1.6.5"
|
||||
async-trait = "0.1"
|
||||
futures = "0.3.30"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
@@ -18,13 +18,13 @@ isahc = "1.2"
|
||||
env_logger = "0.11.3"
|
||||
futures = "0.3.30"
|
||||
jsonpath_lib = "0.3"
|
||||
log = "0.4.21"
|
||||
log = { workspace = true }
|
||||
num-traits = "0.2"
|
||||
serde_json = "1.0"
|
||||
serde_json = { workspace = true, default-features = true }
|
||||
sysinfo = "0.30"
|
||||
time = { version = "0.3", features = ["formatting", "local-offset", "std"] }
|
||||
tokio = { version = "1.36", features = ["rt"] }
|
||||
thiserror = "1.0.57"
|
||||
thiserror = { workspace = true }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
|
||||
Reference in New Issue
Block a user