try_runtime_core/common/empty_block/inherents/custom_idps/
relay_parachains.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Inherent data provider for the [polkadot parachins inherent](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/primitives/src/v7/mod.rs)
19//! for empty block production on top of an existing externalities.
20
21use sp_inherents::InherentIdentifier;
22use sp_runtime::traits::Block as BlockT;
23
24pub struct InherentDataProvider<B: BlockT> {
25    parent_header: B::Header,
26}
27
28impl<B: BlockT> InherentDataProvider<B> {
29    pub fn new(parent_header: B::Header) -> Self {
30        Self { parent_header }
31    }
32}
33
34#[async_trait::async_trait]
35impl<B: BlockT> sp_inherents::InherentDataProvider for InherentDataProvider<B> {
36    async fn provide_inherent_data(
37        &self,
38        inherent_data: &mut sp_inherents::InherentData,
39    ) -> Result<(), sp_inherents::Error> {
40        let para_data = polkadot_primitives::InherentData {
41            bitfields: Vec::new(),
42            backed_candidates: Vec::new(),
43            disputes: Vec::new(),
44            parent_header: self.parent_header.clone(),
45        };
46
47        inherent_data.put_data(
48            polkadot_primitives::PARACHAINS_INHERENT_IDENTIFIER,
49            &para_data,
50        )?;
51
52        Ok(())
53    }
54
55    async fn try_handle_error(
56        &self,
57        _: &InherentIdentifier,
58        _: &[u8],
59    ) -> Option<Result<(), sp_inherents::Error>> {
60        None
61    }
62}