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
@@ -25,7 +25,7 @@ use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis,
extensions::{
CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
CheckWeight, GenericSignedExtension, GenericSignedExtensionSchema,
CheckWeight, GenericTransactionExtension, GenericTransactionExtensionSchema,
},
Chain, ChainId, TransactionEra,
};
@@ -37,7 +37,12 @@ use frame_support::{
};
use frame_system::limits;
use scale_info::TypeInfo;
use sp_runtime::{traits::DispatchInfoOf, transaction_validity::TransactionValidityError, Perbill};
use sp_runtime::{
impl_tx_ext_default,
traits::{Dispatchable, TransactionExtensionBase},
transaction_validity::TransactionValidityError,
Perbill,
};
// This chain reuses most of Polkadot primitives.
pub use bp_polkadot_core::{
@@ -71,10 +76,10 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
/// This signed extension is used to ensure that the chain transactions are signed by proper
pub type ValidateSigned = GenericSignedExtensionSchema<(), ()>;
pub type ValidateSigned = GenericTransactionExtensionSchema<(), ()>;
/// Signed extension schema, used by Polkadot Bulletin.
pub type SignedExtensionSchema = GenericSignedExtension<(
pub type TransactionExtensionSchema = GenericTransactionExtension<(
(
CheckNonZeroSender,
CheckSpecVersion,
@@ -87,34 +92,30 @@ pub type SignedExtensionSchema = GenericSignedExtension<(
ValidateSigned,
)>;
/// Signed extension, used by Polkadot Bulletin.
/// Transaction extension, used by Polkadot Bulletin.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SignedExtension(SignedExtensionSchema);
pub struct TransactionExtension(TransactionExtensionSchema);
impl sp_runtime::traits::SignedExtension for SignedExtension {
impl TransactionExtensionBase for TransactionExtension {
const IDENTIFIER: &'static str = "Not needed.";
type AccountId = ();
type Call = ();
type AdditionalSigned =
<SignedExtensionSchema as sp_runtime::traits::SignedExtension>::AdditionalSigned;
type Pre = ();
type Implicit = <TransactionExtensionSchema as TransactionExtensionBase>::Implicit;
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
self.0.additional_signed()
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
<TransactionExtensionSchema as TransactionExtensionBase>::implicit(&self.0)
}
}
impl SignedExtension {
impl<C, Context> sp_runtime::traits::TransactionExtension<C, Context> for TransactionExtension
where
C: Dispatchable,
{
type Pre = ();
type Val = ();
impl_tx_ext_default!(C; Context; validate prepare);
}
impl TransactionExtension {
/// Create signed extension from its components.
pub fn from_params(
spec_version: u32,
@@ -123,7 +124,7 @@ impl SignedExtension {
genesis_hash: Hash,
nonce: Nonce,
) -> Self {
Self(GenericSignedExtension::new(
Self(GenericTransactionExtension::new(
(
(
(), // non-zero sender