mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 16:37:57 +00:00
Adds support for returning a custom header from validate_block (#825)
* Adds support for returning a custom header from `validate_block` This adds support for returning a custom header from `validate_block`. Before this, we always returned the header of the block that was validated (and still do it by default). However, after this pr it is possible to set a custom header or better custom head data that will be returned instead from `validate_block`. This can be for example when a chain wants to fork. * FMT
This commit is contained in:
+12
-8
@@ -27,6 +27,8 @@ pub mod wasm_spec_version_incremented {
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary_spec_version_incremented.rs"));
|
||||
}
|
||||
|
||||
mod test_pallet;
|
||||
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use sp_api::{decl_runtime_apis, impl_runtime_apis};
|
||||
use sp_core::OpaqueMetadata;
|
||||
@@ -58,6 +60,7 @@ pub use pallet_timestamp::Call as TimestampCall;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub use sp_runtime::BuildStorage;
|
||||
pub use sp_runtime::{Perbill, Permill};
|
||||
pub use test_pallet::Call as TestPalletCall;
|
||||
|
||||
pub type SessionHandlers = ();
|
||||
|
||||
@@ -265,20 +268,21 @@ parameter_types! {
|
||||
pub storage ParachainId: cumulus_primitives_core::ParaId = 100.into();
|
||||
}
|
||||
|
||||
impl test_pallet::Config for Runtime {}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
NodeBlock = NodeBlock,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
|
||||
ParachainSystem: cumulus_pallet_parachain_system::{
|
||||
Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned,
|
||||
},
|
||||
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
System: frame_system,
|
||||
ParachainSystem: cumulus_pallet_parachain_system,
|
||||
Timestamp: pallet_timestamp,
|
||||
Balances: pallet_balances,
|
||||
Sudo: pallet_sudo,
|
||||
TransactionPayment: pallet_transaction_payment,
|
||||
TestPallet: test_pallet,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/// A special pallet that exposes dispatchables that are only useful for testing.
|
||||
pub use pallet::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + cumulus_pallet_parachain_system::Config {}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// A test dispatchable for setting a custom head data in `validate_block`.
|
||||
#[pallet::weight(0)]
|
||||
pub fn set_custom_validation_head_data(
|
||||
_: OriginFor<T>,
|
||||
custom_header: sp_std::vec::Vec<u8>,
|
||||
) -> DispatchResult {
|
||||
cumulus_pallet_parachain_system::Pallet::<T>::set_custom_validation_head_data(
|
||||
custom_header,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user