This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 378
/
lib.rs
122 lines (103 loc) · 4.1 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2019 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/>.
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use parachain::primitives::{RelayChainBlockNumber, ValidationParams};
use sp_runtime::traits::Block as BlockT;
///! The Cumulus runtime to make a runtime a parachain.
use sp_std::vec::Vec;
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub use sp_std::slice;
#[macro_use]
pub mod validate_block;
/// The witness data type.
type WitnessData = Vec<Vec<u8>>;
/// The parachain block that is created on a collator and validated by a validator.
#[derive(Encode, Decode)]
pub struct ParachainBlockData<B: BlockT> {
/// The header of the parachain block.
header: <B as BlockT>::Header,
/// The extrinsics of the parachain block without the `PolkadotInherent`.
extrinsics: Vec<<B as BlockT>::Extrinsic>,
/// The data that is required to emulate the storage accesses executed by all extrinsics.
witness_data: WitnessData,
/// The storage root of the witness data.
witness_data_storage_root: <B as BlockT>::Hash,
}
impl<B: BlockT> ParachainBlockData<B> {
pub fn new(
header: <B as BlockT>::Header,
extrinsics: Vec<<B as BlockT>::Extrinsic>,
witness_data: WitnessData,
witness_data_storage_root: <B as BlockT>::Hash,
) -> Self {
Self {
header,
extrinsics,
witness_data,
witness_data_storage_root,
}
}
/// Convert `self` into the stored header.
pub fn into_header(self) -> B::Header {
self.header
}
/// Returns the header.
pub fn header(&self) -> &B::Header {
&self.header
}
/// Returns the extrinsics.
pub fn extrinsics(&self) -> &[B::Extrinsic] {
&self.extrinsics
}
}
/// Current validation function parameters.
pub const VALIDATION_FUNCTION_PARAMS: &'static [u8] = b":validation_function_params";
/// Code upgarde (set as appropriate by a pallet).
pub const NEW_VALIDATION_CODE: &'static [u8] = b":new_validation_code";
// this const is not actually dead; it's imported and used in
// /runtime/src/validate_block/implementation.rs. However, the dead code
// warning triggers in error due to the pub(crate) visibility.
#[allow(dead_code)]
/// The relay chain block number of a pending parachain validation function upgrade.
///
/// This is an implementation detail and should not be of interest to external pallets.
pub(crate) const SCHEDULED_UPGRADE_BLOCK: &'static [u8] = b":scheduled_upgrade_block";
/// Validation Function Parameters
///
/// This struct is the subset of [`ValidationParams`](../../polkadot_parachain/primitives/struct.ValidationParams.html)
/// which is of interest when upgrading parachain validation functions.
#[derive(PartialEq, Eq, Encode, Decode, Clone, Copy)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct ValidationFunctionParams {
/// The maximum code size permitted, in bytes.
pub max_code_size: u32,
/// The current relay-chain block number.
pub relay_chain_height: RelayChainBlockNumber,
/// Whether a code upgrade is allowed or not, and at which height the upgrade
/// would be applied after, if so. The parachain logic should apply any upgrade
/// issued in this block after the first block
/// with `relay_chain_height` at least this value, if `Some`. if `None`, issue
/// no upgrade.
pub code_upgrade_allowed: Option<RelayChainBlockNumber>,
}
impl ValidationFunctionParams {
pub fn new(vp: &ValidationParams) -> ValidationFunctionParams {
ValidationFunctionParams {
max_code_size: vp.max_code_size,
relay_chain_height: vp.relay_chain_height,
code_upgrade_allowed: vp.code_upgrade_allowed,
}
}
}