Newer
Older
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot 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.
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use application_crypto::KeyTypeId;
use inherents::InherentIdentifier;
use primitives::RuntimeDebug;
use runtime_primitives::traits::{AppVerify, Header as HeaderT};
use sp_arithmetic::traits::{BaseArithmetic, Saturating};
pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT};
// Export some core primitives.
pub use polkadot_core_primitives::v2::{
AccountId, AccountIndex, AccountPublic, Balance, Block, BlockId, BlockNumber, CandidateHash,
ChainId, DownwardMessage, Hash, Header, InboundDownwardMessage, InboundHrmpMessage, Moment,
Nonce, OutboundHrmpMessage, Remark, Signature, UncheckedExtrinsic,
};
// Export some polkadot-parachain primitives
pub use polkadot_parachain::primitives::{
HeadData, HrmpChannelId, Id, UpwardMessage, ValidationCode, ValidationCodeHash,
LOWEST_PUBLIC_ID, LOWEST_USER_ID,
};
#[cfg(feature = "std")]
use parity_util_mem::{MallocSizeOf, MallocSizeOfOps};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
pub use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
pub use sp_consensus_slots::Slot;
pub use sp_staking::SessionIndex;
/// Signed data.
mod signed;
pub use signed::{EncodeAs, Signed, UncheckedSigned};
mod metrics;
pub use metrics::{
metric_definitions, RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues,
RuntimeMetricLabels, RuntimeMetricOp, RuntimeMetricUpdate,
};
/// The key type ID for a collator key.
pub const COLLATOR_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"coll");
mod collator_app {
use application_crypto::{app_crypto, sr25519};
app_crypto!(sr25519, super::COLLATOR_KEY_TYPE_ID);
}
/// Identity that collators use.
pub type CollatorId = collator_app::Public;
#[cfg(feature = "std")]
impl MallocSizeOf for CollatorId {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
fn constant_size() -> Option<usize> {
Some(0)
}
}
/// A Parachain collator keypair.
#[cfg(feature = "std")]
pub type CollatorPair = collator_app::Pair;
/// Signature on candidate's block data by a collator.
pub type CollatorSignature = collator_app::Signature;
#[cfg(feature = "std")]
impl MallocSizeOf for CollatorSignature {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
fn constant_size() -> Option<usize> {
Some(0)
}
}
/// The key type ID for a parachain validator key.
pub const PARACHAIN_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"para");
mod validator_app {
use application_crypto::{app_crypto, sr25519};
app_crypto!(sr25519, super::PARACHAIN_KEY_TYPE_ID);
}
/// Identity that parachain validators use when signing validation messages.
///
/// For now we assert that parachain validator set is exactly equivalent to the authority set, and
/// so we define it to be the same type as `SessionKey`. In the future it may have different crypto.
pub type ValidatorId = validator_app::Public;
#[cfg(feature = "std")]
impl MallocSizeOf for ValidatorId {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
fn constant_size() -> Option<usize> {
Some(0)
}
}
/// Index of the validator is used as a lightweight replacement of the `ValidatorId` when appropriate.
#[derive(Eq, Ord, PartialEq, PartialOrd, Copy, Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, MallocSizeOf))]
pub struct ValidatorIndex(pub u32);
// We should really get https://github.com/paritytech/polkadot/issues/2403 going ..
impl From<u32> for ValidatorIndex {
fn from(n: u32) -> Self {
ValidatorIndex(n)
}
}
application_crypto::with_pair! {
/// A Parachain validator keypair.
pub type ValidatorPair = validator_app::Pair;
}
/// Signature with which parachain validators sign blocks.
///
/// For now we assert that parachain validator set is exactly equivalent to the authority set, and
/// so we define it to be the same type as `SessionKey`. In the future it may have different crypto.
pub type ValidatorSignature = validator_app::Signature;
#[cfg(feature = "std")]
impl MallocSizeOf for ValidatorSignature {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
fn constant_size() -> Option<usize> {
Some(0)
}
}
/// A declarations of storage keys where an external observer can find some interesting data.
pub mod well_known_keys {
use super::{HrmpChannelId, Id};
use hex_literal::hex;
use parity_scale_codec::Encode as _;
use sp_io::hashing::twox_64;
use sp_std::prelude::*;
// A note on generating these magic values below:
//
// The `StorageValue`, such as `ACTIVE_CONFIG` was obtained by calling:
//
// <Self as Store>::ActiveConfig::hashed_key()
//
// The `StorageMap` values require `prefix`, and for example for `hrmp_egress_channel_index`,
// it could be obtained like:
//
// <Hrmp as Store>::HrmpEgressChannelsIndex::prefix_hash();
//
/// The current slot number.
///
/// The storage entry should be accessed as a `Slot` encoded value.
pub const CURRENT_SLOT: &[u8] =
&hex!["1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed"];
/// The currently active host configuration.
///
/// The storage entry should be accessed as an `AbridgedHostConfiguration` encoded value.
pub const ACTIVE_CONFIG: &[u8] =
&hex!["06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385"];
/// The upward message dispatch queue for the given para id.
///
/// The storage entry stores a tuple of two values:
///
/// - `count: u32`, the number of messages currently in the queue for given para,
/// - `total_size: u32`, the total size of all messages in the queue.
pub fn relay_dispatch_queue_size(para_id: Id) -> Vec<u8> {
let prefix = hex!["f5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e"];
para_id.using_encoded(|para_id: &[u8]| {
Loading full blame...