backport changes from polkadot-sdk (#2872)

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