#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
use bp_header_chain::ChainWithGrandpa;
use bp_messages::{ChainWithMessages, MessageNonce};
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis,
extensions::{
CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
CheckWeight, GenericTransactionExtension, GenericTransactionExtensionSchema,
},
Chain, ChainId, TransactionEra,
};
use codec::{Decode, Encode};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use frame_system::limits;
use scale_info::TypeInfo;
use sp_runtime::{
impl_tx_ext_default, traits::Dispatchable, transaction_validity::TransactionValidityError,
Perbill, StateVersion,
};
pub use bp_polkadot_core::{
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE, EXTRA_STORAGE_PROOF_SIZE,
MAX_MANDATORY_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY,
};
pub const MAX_AUTHORITIES_COUNT: u32 = 100;
pub const WITH_POLKADOT_BULLETIN_GRANDPA_PALLET_NAME: &str = "BridgePolkadotBulletinGrandpa";
pub const WITH_POLKADOT_BULLETIN_MESSAGES_PALLET_NAME: &str = "BridgePolkadotBulletinMessages";
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(90);
pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
pub type ValidateSigned = GenericTransactionExtensionSchema<(), ()>;
pub type TransactionExtensionSchema = GenericTransactionExtension<(
(
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<Hash>,
CheckEra<Hash>,
CheckNonce<Nonce>,
CheckWeight,
),
ValidateSigned,
)>;
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct TransactionExtension(TransactionExtensionSchema);
impl<C> sp_runtime::traits::TransactionExtension<C> for TransactionExtension
where
C: Dispatchable,
{
const IDENTIFIER: &'static str = "Not needed.";
type Implicit =
<TransactionExtensionSchema as sp_runtime::traits::TransactionExtension<C>>::Implicit;
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
<TransactionExtensionSchema as sp_runtime::traits::TransactionExtension<C>>::implicit(
&self.0,
)
}
type Pre = ();
type Val = ();
impl_tx_ext_default!(C; weight validate prepare);
}
impl TransactionExtension {
pub fn from_params(
spec_version: u32,
transaction_version: u32,
era: TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
) -> Self {
Self(GenericTransactionExtension::new(
(
(
(), (), (), (), era.frame_era(), nonce.into(), (), ),
(),
),
Some((
(
(),
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
),
(),
)),
))
}
pub fn nonce(&self) -> Nonce {
let common_payload = self.0.payload.0;
common_payload.5 .0
}
}
parameter_types! {
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::with_sensible_defaults(
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
NORMAL_DISPATCH_RATIO,
);
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
10 * 1024 * 1024,
NORMAL_DISPATCH_RATIO,
);
}
pub struct PolkadotBulletin;
impl Chain for PolkadotBulletin {
const ID: ChainId = *b"pdbc";
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type AccountId = AccountId;
type Balance = Balance;
type Nonce = Nonce;
type Signature = Signature;
const STATE_VERSION: StateVersion = StateVersion::V1;
fn max_extrinsic_size() -> u32 {
*BlockLength::get().max.get(DispatchClass::Normal)
}
fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
}
}
impl ChainWithGrandpa for PolkadotBulletin {
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_POLKADOT_BULLETIN_GRANDPA_PALLET_NAME;
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
const REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY: u32 =
REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY;
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
}
impl ChainWithMessages for PolkadotBulletin {
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
WITH_POLKADOT_BULLETIN_MESSAGES_PALLET_NAME;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
}
decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);
decl_bridge_messages_runtime_apis!(polkadot_bulletin, bp_messages::LegacyLaneId);