mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 14:05:41 +00:00
Merge remote-tracking branch 'origin/master' into gav-xcm-v3
This commit is contained in:
@@ -33,7 +33,7 @@ use cumulus_primitives_core::{
|
||||
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
|
||||
XcmpMessageHandler, XcmpMessageSource,
|
||||
};
|
||||
use cumulus_primitives_parachain_inherent::ParachainInherentData;
|
||||
use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData};
|
||||
use frame_support::{
|
||||
dispatch::{DispatchError, DispatchResult},
|
||||
ensure,
|
||||
@@ -46,7 +46,7 @@ use frame_system::{ensure_none, ensure_root};
|
||||
use polkadot_parachain::primitives::RelayChainBlockNumber;
|
||||
use relay_state_snapshot::MessagingStateSnapshot;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider, Hash},
|
||||
traits::{Block as BlockT, BlockNumberProvider, Hash},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity,
|
||||
ValidTransaction,
|
||||
@@ -236,8 +236,9 @@ pub mod pallet {
|
||||
HrmpWatermark::<T>::kill();
|
||||
UpwardMessages::<T>::kill();
|
||||
HrmpOutboundMessages::<T>::kill();
|
||||
CustomValidationHeadData::<T>::kill();
|
||||
|
||||
weight += T::DbWeight::get().writes(5);
|
||||
weight += T::DbWeight::get().writes(6);
|
||||
|
||||
// Here, in `on_initialize` we must report the weight for both `on_initialize` and
|
||||
// `on_finalize`.
|
||||
@@ -567,6 +568,12 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
pub(super) type AuthorizedUpgrade<T: Config> = StorageValue<_, T::Hash>;
|
||||
|
||||
/// A custom head data that should be returned as result of `validate_block`.
|
||||
///
|
||||
/// See [`Pallet::set_custom_validation_head_data`] for more information.
|
||||
#[pallet::storage]
|
||||
pub(super) type CustomValidationHeadData<T: Config> = StorageValue<_, Vec<u8>, OptionQuery>;
|
||||
|
||||
#[pallet::inherent]
|
||||
impl<T: Config> ProvideInherent for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
@@ -609,7 +616,7 @@ pub mod pallet {
|
||||
if let Ok(hash) = Self::validate_authorized_upgrade(code) {
|
||||
return Ok(ValidTransaction {
|
||||
priority: 100,
|
||||
requires: vec![],
|
||||
requires: Vec::new(),
|
||||
provides: vec![hash.as_ref().to_vec()],
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
propagate: true,
|
||||
@@ -692,6 +699,9 @@ impl<T: Config> Pallet<T> {
|
||||
/// import, this is a no-op.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics while validating the `PoV` on the relay chain if the [`PersistedValidationData`]
|
||||
/// passed by the block author was incorrect.
|
||||
fn validate_validation_data(validation_data: &PersistedValidationData) {
|
||||
validate_block::with_validation_params(|params| {
|
||||
assert_eq!(
|
||||
@@ -714,8 +724,10 @@ impl<T: Config> Pallet<T> {
|
||||
/// Checks if the sequence of the messages is valid, dispatches them and communicates the
|
||||
/// number of processed messages to the collator via a storage update.
|
||||
///
|
||||
/// **Panics** if it turns out that after processing all messages the Message Queue Chain
|
||||
/// hash doesn't match the expected.
|
||||
/// # Panics
|
||||
///
|
||||
/// If it turns out that after processing all messages the Message Queue Chain
|
||||
/// hash doesn't match the expected.
|
||||
fn process_inbound_downward_messages(
|
||||
expected_dmq_mqc_head: relay_chain::Hash,
|
||||
downward_messages: Vec<InboundDownwardMessage>,
|
||||
@@ -738,7 +750,7 @@ impl<T: Config> Pallet<T> {
|
||||
weight_used += T::DmpMessageHandler::handle_dmp_messages(message_iter, max_weight);
|
||||
<LastDmqMqcHead<T>>::put(&dmq_head);
|
||||
|
||||
Self::deposit_event(Event::DownwardMessagesProcessed(weight_used, dmq_head.0));
|
||||
Self::deposit_event(Event::DownwardMessagesProcessed(weight_used, dmq_head.head()));
|
||||
}
|
||||
|
||||
// After hashing each message in the message queue chain submitted by the collator, we
|
||||
@@ -746,7 +758,7 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// A mismatch means that at least some of the submitted messages were altered, omitted or
|
||||
// added improperly.
|
||||
assert_eq!(dmq_head.0, expected_dmq_mqc_head);
|
||||
assert_eq!(dmq_head.head(), expected_dmq_mqc_head);
|
||||
|
||||
ProcessedDownwardMessages::<T>::put(dm_count);
|
||||
|
||||
@@ -907,6 +919,22 @@ impl<T: Config> Pallet<T> {
|
||||
new_validation_code: NewValidationCode::<T>::get().map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set a custom head data that should be returned as result of `validate_block`.
|
||||
///
|
||||
/// This will overwrite the head data that is returned as result of `validate_block` while
|
||||
/// validating a `PoV` on the relay chain. Normally the head data that is being returned
|
||||
/// by `validate_block` is the header of the block that is validated, thus it can be
|
||||
/// enacted as the new best block. However, for features like forking it can be useful
|
||||
/// to overwrite the head data with a custom header.
|
||||
///
|
||||
/// # Attention
|
||||
///
|
||||
/// This should only be used when you are sure what you are doing as this can brick
|
||||
/// your Parachain.
|
||||
pub fn set_custom_validation_head_data(head_data: Vec<u8>) {
|
||||
CustomValidationHeadData::<T>::put(head_data);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ParachainSetCode<T>(sp_std::marker::PhantomData<T>);
|
||||
@@ -917,43 +945,6 @@ impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// This struct provides ability to extend a message queue chain (MQC) and compute a new head.
|
||||
///
|
||||
/// MQC is an instance of a [hash chain] applied to a message queue. Using a hash chain it's
|
||||
/// possible to represent a sequence of messages using only a single hash.
|
||||
///
|
||||
/// A head for an empty chain is agreed to be a zero hash.
|
||||
///
|
||||
/// [hash chain]: https://en.wikipedia.org/wiki/Hash_chain
|
||||
#[derive(Default, Clone, codec::Encode, codec::Decode, scale_info::TypeInfo)]
|
||||
struct MessageQueueChain(relay_chain::Hash);
|
||||
|
||||
impl MessageQueueChain {
|
||||
fn extend_hrmp(&mut self, horizontal_message: &InboundHrmpMessage) -> &mut Self {
|
||||
let prev_head = self.0;
|
||||
self.0 = BlakeTwo256::hash_of(&(
|
||||
prev_head,
|
||||
horizontal_message.sent_at,
|
||||
BlakeTwo256::hash_of(&horizontal_message.data),
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
fn extend_downward(&mut self, downward_message: &InboundDownwardMessage) -> &mut Self {
|
||||
let prev_head = self.0;
|
||||
self.0 = BlakeTwo256::hash_of(&(
|
||||
prev_head,
|
||||
downward_message.sent_at,
|
||||
BlakeTwo256::hash_of(&downward_message.msg),
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
fn head(&self) -> relay_chain::Hash {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
|
||||
// Check if the message fits into the relay-chain constraints.
|
||||
@@ -1008,7 +999,7 @@ pub trait CheckInherents<Block: BlockT> {
|
||||
) -> frame_support::inherent::CheckInherentsResult;
|
||||
}
|
||||
|
||||
/// Implements [`BlockNumberProvider`] that returns relaychain block number fetched from
|
||||
/// Implements [`BlockNumberProvider`] that returns relay chain block number fetched from
|
||||
/// validation data.
|
||||
/// NTOE: When validation data is not available (e.g. within on_initialize), 0 will be returned.
|
||||
pub struct RelaychainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
Reference in New Issue
Block a user