Bring support for calling check_inherents (#490)

* Start

* More work

* Add proc-macro for `validate_block`

* Make everything compile

* Add some test
This commit is contained in:
Bastian Köcher
2021-06-12 19:21:46 +01:00
committed by GitHub
parent c5819c9e78
commit 2dc281b482
20 changed files with 684 additions and 326 deletions
+53 -14
View File
@@ -30,8 +30,8 @@
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo, DmpMessageHandler,
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, OnValidationData,
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
XcmpMessageHandler, XcmpMessageSource,
OutboundHrmpMessage, ParaId, UpwardMessage, UpwardMessageSender, XcmpMessageHandler,
XcmpMessageSource, PersistedValidationData,
};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use frame_support::{
@@ -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, Hash},
traits::{BlakeTwo256, Block as BlockT, Hash},
transaction_validity::{
InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity,
ValidTransaction,
@@ -60,6 +60,31 @@ pub mod validate_block;
#[cfg(test)]
mod tests;
/// Register the `validate_block` function that is used by parachains to validate blocks on a
/// validator.
///
/// Does *nothing* when `std` feature is enabled.
///
/// Expects as parameters the runtime, a block executor and an inherent checker.
///
/// # Example
///
/// ```
/// struct BlockExecutor;
/// struct Runtime;
/// struct CheckInherents;
///
/// cumulus_pallet_parachain_system::register_validate_block! {
/// Runtime = Runtime,
/// BlockExecutor = Executive,
/// CheckInherents = CheckInherents,
/// }
///
/// # fn main() {}
/// ```
pub use cumulus_pallet_parachain_system_proc_macro::register_validate_block;
pub use relay_state_snapshot::RelayChainStateProof;
pub use pallet::*;
#[frame_support::pallet]
@@ -309,17 +334,19 @@ pub mod pallet {
}
}
let (host_config, relevant_messaging_state) =
match relay_state_snapshot::extract_from_proof(
T::SelfParaId::get(),
vfp.relay_parent_storage_root,
relay_chain_state,
) {
Ok(r) => r,
Err(err) => {
panic!("invalid relay chain merkle proof: {:?}", err);
}
};
let relay_state_proof = RelayChainStateProof::new(
T::SelfParaId::get(),
vfp.relay_parent_storage_root,
relay_chain_state,
)
.expect("Invalid relay chain state proof");
let host_config = relay_state_proof
.read_abridged_host_configuration()
.expect("Invalid host configuration in relay chain state proof");
let relevant_messaging_state = relay_state_proof
.read_messaging_state_snapshot()
.expect("Invalid messaging state in relay chain state proof");
<ValidationData<T>>::put(&vfp);
<RelevantMessagingState<T>>::put(relevant_messaging_state.clone());
@@ -999,3 +1026,15 @@ impl<T: Config> UpwardMessageSender for Pallet<T> {
Self::send_upward_message(message)
}
}
/// Something that can check the inherents of a block.
pub trait CheckInherents<Block: BlockT> {
/// Check all inherents of the block.
///
/// This function gets passed all the extrinsics of the block, so it is up to the callee to
/// identify the inherents. The `validation_data` can be used to access the
fn check_inherents(
extrinsics: &[Block::Extrinsic],
validation_data: &RelayChainStateProof,
) -> frame_support::inherent::CheckInherentsResult;
}