cumulus-primitives-core 0.24.0

Cumulus related core primitive types and traits
Documentation
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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Cumulus related core primitive types and traits.

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::vec::Vec;
use codec::{Compact, Decode, DecodeAll, DecodeWithMemTracking, Encode, MaxEncodedLen};
use polkadot_parachain_primitives::primitives::HeadData;
use scale_info::TypeInfo;
use Debug;

/// The ref time per core in seconds.
///
/// This is the execution time each PoV gets on a core on the relay chain.
pub const REF_TIME_PER_CORE_IN_SECS: u64 = 2;

pub mod parachain_block_data;

pub use parachain_block_data::ParachainBlockData;
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use polkadot_parachain_primitives::primitives::{
	DmpMessageHandler, Id as ParaId, IsSystem, UpwardMessage, ValidationParams, XcmpMessageFormat,
	XcmpMessageHandler,
};
pub use polkadot_primitives::{
	AbridgedHostConfiguration, AbridgedHrmpChannel, ClaimQueueOffset, CoreSelector,
	PersistedValidationData,
};
pub use sp_runtime::{
	generic::{Digest, DigestItem},
	traits::Block as BlockT,
	ConsensusEngineId,
};
pub use xcm::latest::prelude::*;

/// A module that re-exports relevant relay chain definitions.
pub mod relay_chain {
	pub use polkadot_core_primitives::*;
	pub use polkadot_primitives::*;
}

/// An inbound HRMP message.
pub type InboundHrmpMessage = polkadot_primitives::InboundHrmpMessage<relay_chain::BlockNumber>;

/// And outbound HRMP message
pub type OutboundHrmpMessage = polkadot_primitives::OutboundHrmpMessage<ParaId>;

/// Error description of a message send failure.
#[derive(Eq, PartialEq, Copy, Clone, Debug, Encode, Decode)]
pub enum MessageSendError {
	/// The dispatch queue is full.
	QueueFull,
	/// There does not exist a channel for sending the message.
	NoChannel,
	/// The message is too big to ever fit in a channel.
	TooBig,
	/// Some other error.
	Other,
	/// There are too many channels open at once.
	TooManyChannels,
}

impl From<MessageSendError> for &'static str {
	fn from(e: MessageSendError) -> Self {
		use MessageSendError::*;
		match e {
			QueueFull => "QueueFull",
			NoChannel => "NoChannel",
			TooBig => "TooBig",
			Other => "Other",
			TooManyChannels => "TooManyChannels",
		}
	}
}

/// The origin of an inbound message.
#[derive(
	Encode, Decode, DecodeWithMemTracking, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug,
)]
pub enum AggregateMessageOrigin {
	/// The message came from the para-chain itself.
	Here,
	/// The message came from the relay-chain.
	///
	/// This is used by the DMP queue.
	Parent,
	/// The message came from a sibling para-chain.
	///
	/// This is used by the HRMP queue.
	Sibling(ParaId),
}

impl From<AggregateMessageOrigin> for Location {
	fn from(origin: AggregateMessageOrigin) -> Self {
		match origin {
			AggregateMessageOrigin::Here => Location::here(),
			AggregateMessageOrigin::Parent => Location::parent(),
			AggregateMessageOrigin::Sibling(id) => Location::new(1, Junction::Parachain(id.into())),
		}
	}
}

#[cfg(feature = "runtime-benchmarks")]
impl From<u32> for AggregateMessageOrigin {
	fn from(x: u32) -> Self {
		match x {
			0 => Self::Here,
			1 => Self::Parent,
			p => Self::Sibling(ParaId::from(p)),
		}
	}
}

/// Information about an XCMP channel.
pub struct ChannelInfo {
	/// The maximum number of messages that can be pending in the channel at once.
	pub max_capacity: u32,
	/// The maximum total size of the messages that can be pending in the channel at once.
	pub max_total_size: u32,
	/// The maximum message size that could be put into the channel.
	pub max_message_size: u32,
	/// The current number of messages pending in the channel.
	/// Invariant: should be less or equal to `max_capacity`.s`.
	pub msg_count: u32,
	/// The total size in bytes of all message payloads in the channel.
	/// Invariant: should be less or equal to `max_total_size`.
	pub total_size: u32,
}

pub trait GetChannelInfo {
	fn get_channel_status(id: ParaId) -> ChannelStatus;
	fn get_channel_info(id: ParaId) -> Option<ChannelInfo>;
}

/// List all open outgoing channels.
pub trait ListChannelInfos {
	fn outgoing_channels() -> Vec<ParaId>;
}

/// Something that should be called when sending an upward message.
pub trait UpwardMessageSender {
	/// Send the given UMP message; return the expected number of blocks before the message will
	/// be dispatched or an error if the message cannot be sent.
	/// return the hash of the message sent
	fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError>;

	/// Pre-check the given UMP message.
	fn can_send_upward_message(message: &UpwardMessage) -> Result<(), MessageSendError>;

	/// Ensure `[Self::send_upward_message]` is successful when called in benchmarks/tests.
	#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
	fn ensure_successful_delivery() {}
}

impl UpwardMessageSender for () {
	fn send_upward_message(_message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
		Err(MessageSendError::NoChannel)
	}

	fn can_send_upward_message(_message: &UpwardMessage) -> Result<(), MessageSendError> {
		Err(MessageSendError::Other)
	}
}

/// The status of a channel.
pub enum ChannelStatus {
	/// Channel doesn't exist/has been closed.
	Closed,
	/// Channel is completely full right now.
	Full,
	/// Channel is ready for sending; the two parameters are the maximum size a valid message may
	/// have right now, and the maximum size a message may ever have (this will generally have been
	/// available during message construction, but it's possible the channel parameters changed in
	/// the meantime).
	Ready(usize, usize),
}

/// A means of figuring out what outbound XCMP messages should be being sent.
pub trait XcmpMessageSource {
	/// Take a single XCMP message from the queue for the given `dest`, if one exists.
	fn take_outbound_messages(maximum_channels: usize) -> Vec<(ParaId, Vec<u8>)>;
}

impl XcmpMessageSource for () {
	fn take_outbound_messages(_maximum_channels: usize) -> Vec<(ParaId, Vec<u8>)> {
		Vec::new()
	}
}

/// The "quality of service" considerations for message sending.
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)]
pub enum ServiceQuality {
	/// Ensure that this message is dispatched in the same relative order as any other messages
	/// that were also sent with `Ordered`. This only guarantees message ordering on the dispatch
	/// side, and not necessarily on the execution side.
	Ordered,
	/// Ensure that the message is dispatched as soon as possible, which could result in it being
	/// dispatched before other messages which are larger and/or rely on relative ordering.
	Fast,
}

/// A consensus engine ID indicating that this is a Cumulus Parachain.
pub const CUMULUS_CONSENSUS_ID: ConsensusEngineId = *b"CMLS";

/// Information about the core on the relay chain this block will be validated on.
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq)]
pub struct CoreInfo {
	/// The selector that determines the actual core at `claim_queue_offset`.
	pub selector: CoreSelector,
	/// The claim queue offset that determines how far "into the future" the core is selected.
	pub claim_queue_offset: ClaimQueueOffset,
	/// The number of cores assigned to the parachain at `claim_queue_offset`.
	pub number_of_cores: Compact<u16>,
}

impl core::hash::Hash for CoreInfo {
	fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
		state.write_u8(self.selector.0);
		state.write_u8(self.claim_queue_offset.0);
		state.write_u16(self.number_of_cores.0);
	}
}

impl CoreInfo {
	/// Puts this into a [`CumulusDigestItem::CoreInfo`] and then encodes it as a Substrate
	/// [`DigestItem`].
	pub fn to_digest_item(&self) -> DigestItem {
		CumulusDigestItem::CoreInfo(self.clone()).to_digest_item()
	}
}

/// Information about a block that is part of a PoV bundle.
#[derive(Clone, Debug, Decode, Encode, PartialEq)]
pub struct BundleInfo {
	/// The index of the block in the bundle.
	pub index: u8,
	/// Is this the last block in the bundle from the point of view of the node?
	///
	/// It is possible that the runtime outputs the
	/// [`CumulusDigestItem::UseFullCore`] to inform the node to use an entire for one block
	/// only.
	pub maybe_last: bool,
}

impl BundleInfo {
	/// Puts this into a [`CumulusDigestItem::BundleInfo`] and then encodes it as a Substrate
	/// [`DigestItem`].
	pub fn to_digest_item(&self) -> DigestItem {
		CumulusDigestItem::BundleInfo(self.clone()).to_digest_item()
	}
}

/// Return value of [`CumulusDigestItem::core_info_exists_at_max_once`]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoreInfoExistsAtMaxOnce {
	/// Exists exactly once.
	Once(CoreInfo),
	/// Not found.
	NotFound,
	/// Found more than once.
	MoreThanOnce,
}

/// Identifier for a relay chain block used by [`CumulusDigestItem`].
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
pub enum RelayBlockIdentifier {
	/// The block is identified using its block hash.
	ByHash(relay_chain::Hash),
	/// The block is identified using its storage root and block number.
	ByStorageRoot { storage_root: relay_chain::Hash, block_number: relay_chain::BlockNumber },
}

/// Consensus header digests for Cumulus parachains.
#[derive(Clone, Debug, Decode, Encode, PartialEq)]
pub enum CumulusDigestItem {
	/// A digest item indicating the relay-parent a parachain block was built against.
	#[codec(index = 0)]
	RelayParent(relay_chain::Hash),
	/// A digest item providing information about the core selected on the relay chain for this
	/// block.
	#[codec(index = 1)]
	CoreInfo(CoreInfo),
	/// A digest item providing information about the position of the block in the bundle.
	#[codec(index = 2)]
	BundleInfo(BundleInfo),
	/// A digest item informing the node that this block should be put alone onto a core.
	///
	/// In other words, the core should not be shared with other blocks.
	///
	/// Under certain conditions (mainly runtime misconfigurations) the digest is still set when
	/// there are muliple blocks per core. This is done to communicate to the collator that block
	/// production for this core should be stopped.
	#[codec(index = 3)]
	UseFullCore,
}

impl CumulusDigestItem {
	/// Encode this as a Substrate [`DigestItem`].
	pub fn to_digest_item(&self) -> DigestItem {
		let encoded = self.encode();

		match self {
			Self::RelayParent(_) | Self::UseFullCore => {
				DigestItem::Consensus(CUMULUS_CONSENSUS_ID, encoded)
			},
			_ => DigestItem::PreRuntime(CUMULUS_CONSENSUS_ID, encoded),
		}
	}

	/// Find [`CumulusDigestItem::CoreInfo`] in the given `digest`.
	///
	/// If there are multiple valid digests, this returns the value of the first one.
	pub fn find_core_info(digest: &Digest) -> Option<CoreInfo> {
		digest.convert_first(|d| match d {
			DigestItem::PreRuntime(id, val) if id == &CUMULUS_CONSENSUS_ID => {
				let Ok(CumulusDigestItem::CoreInfo(core_info)) =
					CumulusDigestItem::decode_all(&mut &val[..])
				else {
					return None;
				};

				Some(core_info)
			},
			_ => None,
		})
	}

	/// Returns the found [`CoreInfo`] and iff [`Self::CoreInfo`] exists at max once in the given
	/// `digest`.
	pub fn core_info_exists_at_max_once(digest: &Digest) -> CoreInfoExistsAtMaxOnce {
		let mut core_info = None;
		if digest
			.logs()
			.iter()
			.filter(|l| match l {
				DigestItem::PreRuntime(CUMULUS_CONSENSUS_ID, d) => {
					if let Ok(Self::CoreInfo(ci)) = Self::decode_all(&mut &d[..]) {
						core_info = Some(ci);
						true
					} else {
						false
					}
				},
				_ => false,
			})
			.count() <= 1
		{
			core_info
				.map(CoreInfoExistsAtMaxOnce::Once)
				.unwrap_or(CoreInfoExistsAtMaxOnce::NotFound)
		} else {
			CoreInfoExistsAtMaxOnce::MoreThanOnce
		}
	}

	/// Returns the [`RelayBlockIdentifier`] from the given `digest`.
	///
	/// The identifier corresponds to the relay parent used to build the parachain block.
	pub fn find_relay_block_identifier(digest: &Digest) -> Option<RelayBlockIdentifier> {
		digest.convert_first(|d| match d {
			DigestItem::Consensus(id, val) if id == &CUMULUS_CONSENSUS_ID => {
				let Ok(CumulusDigestItem::RelayParent(hash)) =
					CumulusDigestItem::decode_all(&mut &val[..])
				else {
					return None;
				};

				Some(RelayBlockIdentifier::ByHash(hash))
			},
			DigestItem::Consensus(id, val) if id == &rpsr_digest::RPSR_CONSENSUS_ID => {
				let Ok((storage_root, block_number)) =
					rpsr_digest::RpsrType::decode_all(&mut &val[..])
				else {
					return None;
				};

				Some(RelayBlockIdentifier::ByStorageRoot {
					storage_root,
					block_number: block_number.into(),
				})
			},
			_ => None,
		})
	}

	/// Returns the [`BundleInfo`] from the given `digest`.
	pub fn find_bundle_info(digest: &Digest) -> Option<BundleInfo> {
		digest.convert_first(|d| match d {
			DigestItem::PreRuntime(id, val) if id == &CUMULUS_CONSENSUS_ID => {
				let Ok(CumulusDigestItem::BundleInfo(bundle_info)) =
					CumulusDigestItem::decode_all(&mut &val[..])
				else {
					return None;
				};

				Some(bundle_info)
			},
			_ => None,
		})
	}

	/// Returns `true` if the given `digest` contains the [`Self::UseFullCore`] item.
	pub fn contains_use_full_core(digest: &Digest) -> bool {
		digest
			.convert_first(|d| match d {
				DigestItem::Consensus(id, val) if id == &CUMULUS_CONSENSUS_ID => {
					let Ok(CumulusDigestItem::UseFullCore) =
						CumulusDigestItem::decode_all(&mut &val[..])
					else {
						return None;
					};

					Some(true)
				},
				_ => None,
			})
			.unwrap_or_default()
	}
}

/// If there are multiple valid digests, this returns the value of the first one, although
/// well-behaving runtimes should not produce headers with more than one.
pub fn extract_relay_parent(digest: &Digest) -> Option<relay_chain::Hash> {
	digest.convert_first(|d| match d {
		DigestItem::Consensus(id, val) if id == &CUMULUS_CONSENSUS_ID => {
			match CumulusDigestItem::decode(&mut &val[..]) {
				Ok(CumulusDigestItem::RelayParent(hash)) => Some(hash),
				_ => None,
			}
		},
		_ => None,
	})
}

/// Utilities for handling the relay-parent storage root as a digest item.
///
/// This is not intended to be part of the public API, as it is a workaround for
/// <https://github.com/paritytech/cumulus/issues/303> via
/// <https://github.com/paritytech/polkadot/issues/7191>.
///
/// Runtimes using the parachain-system pallet are expected to produce this digest item,
/// but will stop as soon as they are able to provide the relay-parent hash directly.
///
/// The relay-chain storage root is, in practice, a unique identifier of a block
/// in the absence of equivocations (which are slashable). This assumes that the relay chain
/// uses BABE or SASSAFRAS, because the slot and the author's VRF randomness are both included
/// in the relay-chain storage root in both cases.
///
/// Therefore, the relay-parent storage root is a suitable identifier of unique relay chain
/// blocks in low-value scenarios such as performance optimizations.
#[doc(hidden)]
pub mod rpsr_digest {
	use super::{relay_chain, ConsensusEngineId, DecodeAll, Digest, DigestItem, Encode};
	use codec::Compact;

	/// The type used to store the relay-parent storage root and number.
	pub type RpsrType = (relay_chain::Hash, Compact<relay_chain::BlockNumber>);

	/// A consensus engine ID for relay-parent storage root digests.
	pub const RPSR_CONSENSUS_ID: ConsensusEngineId = *b"RPSR";

	/// Construct a digest item for relay-parent storage roots.
	pub fn relay_parent_storage_root_item(
		storage_root: relay_chain::Hash,
		number: impl Into<Compact<relay_chain::BlockNumber>>,
	) -> DigestItem {
		DigestItem::Consensus(
			RPSR_CONSENSUS_ID,
			RpsrType::from((storage_root, number.into())).encode(),
		)
	}

	/// Extract the relay-parent storage root and number from the provided header digest. Returns
	/// `None` if none were found.
	pub fn extract_relay_parent_storage_root(
		digest: &Digest,
	) -> Option<(relay_chain::Hash, relay_chain::BlockNumber)> {
		digest.convert_first(|d| match d {
			DigestItem::Consensus(id, val) if id == &RPSR_CONSENSUS_ID => {
				let (h, n) = RpsrType::decode_all(&mut &val[..]).ok()?;

				Some((h, n.0))
			},
			_ => None,
		})
	}
}

/// Information about a collation.
///
/// This was used in version 1 of the [`CollectCollationInfo`] runtime api.
#[derive(Clone, Debug, codec::Decode, codec::Encode, PartialEq)]
pub struct CollationInfoV1 {
	/// Messages destined to be interpreted by the Relay chain itself.
	pub upward_messages: Vec<UpwardMessage>,
	/// The horizontal messages sent by the parachain.
	pub horizontal_messages: Vec<OutboundHrmpMessage>,
	/// New validation code.
	pub new_validation_code: Option<relay_chain::ValidationCode>,
	/// The number of messages processed from the DMQ.
	pub processed_downward_messages: u32,
	/// The mark which specifies the block number up to which all inbound HRMP messages are
	/// processed.
	pub hrmp_watermark: relay_chain::BlockNumber,
}

impl CollationInfoV1 {
	/// Convert into the latest version of the [`CollationInfo`] struct.
	pub fn into_latest(self, head_data: HeadData) -> CollationInfo {
		CollationInfo {
			upward_messages: self.upward_messages,
			horizontal_messages: self.horizontal_messages,
			new_validation_code: self.new_validation_code,
			processed_downward_messages: self.processed_downward_messages,
			hrmp_watermark: self.hrmp_watermark,
			head_data,
		}
	}
}

/// Information about a collation.
#[derive(Clone, Debug, codec::Decode, codec::Encode, PartialEq, TypeInfo)]
pub struct CollationInfo {
	/// Messages destined to be interpreted by the Relay chain itself.
	pub upward_messages: Vec<UpwardMessage>,
	/// The horizontal messages sent by the parachain.
	pub horizontal_messages: Vec<OutboundHrmpMessage>,
	/// New validation code.
	pub new_validation_code: Option<relay_chain::ValidationCode>,
	/// The number of messages processed from the DMQ.
	pub processed_downward_messages: u32,
	/// The mark which specifies the block number up to which all inbound HRMP messages are
	/// processed.
	pub hrmp_watermark: relay_chain::BlockNumber,
	/// The head data, aka encoded header, of the block that corresponds to the collation.
	pub head_data: HeadData,
}

/// A relay chain storage key to be included in the storage proof.
#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq)]
pub enum RelayStorageKey {
	/// Top-level relay chain storage key.
	Top(Vec<u8>),
	/// Child trie storage key.
	Child {
		/// Unprefixed storage key identifying the child trie root location.
		/// Prefix `:child_storage:default:` is added when accessing storage.
		/// Used to derive `ChildInfo` for reading child trie data.
		/// Usage: let child_info = ChildInfo::new_default(&storage_key);
		storage_key: Vec<u8>,
		/// Key within the child trie.
		key: Vec<u8>,
	},
}

/// Request for proving relay chain storage data.
///
/// Contains a list of storage keys (either top-level or child trie keys)
/// to be included in the relay chain state proof.
#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, Default)]
pub struct RelayProofRequest {
	/// Storage keys to include in the relay chain state proof.
	pub keys: Vec<RelayStorageKey>,
}

sp_api::decl_runtime_apis! {
	/// Runtime api to collect information about a collation.
	///
	/// Version history:
	/// - Version 2: Changed [`Self::collect_collation_info`] signature
	/// - Version 3: Signals to the node to use version 1 of [`ParachainBlockData`].
	#[api_version(3)]
	pub trait CollectCollationInfo {
		/// Collect information about a collation.
		#[changed_in(2)]
		fn collect_collation_info() -> CollationInfoV1;
		/// Collect information about a collation.
		///
		/// The given `header` is the header of the built block for that
		/// we are collecting the collation info for.
		fn collect_collation_info(header: &Block::Header) -> CollationInfo;
	}

	/// Runtime api used to access general info about a parachain runtime.
	pub trait GetParachainInfo {
		/// Retrieve the parachain id used for runtime.
		fn parachain_id() -> ParaId;
  }

	/// API to tell the node side how the relay parent should be chosen.
	///
	/// A larger offset indicates that the relay parent should not be the tip of the relay chain,
	/// but `N` blocks behind the tip. This offset is then enforced by the runtime.
	pub trait RelayParentOffsetApi {
		/// Fetch the slot offset that is expected from the relay chain.
		fn relay_parent_offset() -> u32;
	}

	/// API for parachain target block rate.
	///
	/// This runtime API allows the parachain runtime to communicate the target block rate
	/// to the node side. The target block rate is always valid for the next relay chain slot.
	///
	/// The runtime can not enforce this target block rate. It only acts as a maximum, but not more.
	/// In the end it depends on the collator how many blocks will be produced. If there are no cores
	/// available or the collator is offline, no blocks at all will be produced.
	pub trait TargetBlockRate {
		/// Get the target block rate for this parachain.
		///
		/// Returns the target number of blocks per relay chain slot.
		fn target_block_rate() -> u32;
	}

	/// API for specifying which relay chain storage data to include in storage proofs.
	///
	/// This API allows parachains to request both top-level relay chain storage keys
	/// and child trie storage keys to be included in the relay chain state proof.
	pub trait KeyToIncludeInRelayProof {
		/// Returns relay chain storage proof requests.
		///
		/// The collator will include them in the relay chain proof that is passed alongside the parachain inherent into the runtime.
		fn keys_to_prove() -> RelayProofRequest;
	}
}