referrerpolicy=no-referrer-when-downgrade

cumulus_primitives_aura/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Core primitives for Aura in Cumulus.
18//!
19//! In particular, this exposes the [`AuraUnincludedSegmentApi`] which is used to regulate
20//! the behavior of Aura within a parachain context.
21
22#![cfg_attr(not(feature = "std"), no_std)]
23
24pub use sp_consensus_aura::Slot;
25
26sp_api::decl_runtime_apis! {
27	/// This runtime API is used to inform potential block authors whether they will
28	/// have the right to author at a slot, assuming they have claimed the slot.
29	///
30	/// In particular, this API allows Aura-based parachains to regulate their "unincluded segment",
31	/// which is the section of the head of the chain which has not yet been made available in the
32	/// relay chain.
33	///
34	/// When the unincluded segment is short, Aura chains will allow authors to create multiple
35	/// blocks per slot in order to build a backlog. When it is saturated, this API will limit
36	/// the amount of blocks that can be created.
37	///
38	/// Changes:
39	/// - Version 2: Update to `can_build_upon` to take a relay chain `Slot` instead of a parachain `Slot`.
40	#[api_version(2)]
41	pub trait AuraUnincludedSegmentApi {
42		/// Whether it is legal to extend the chain, assuming the given block is the most
43		/// recently included one as-of the relay parent that will be built against, and
44		/// the given relay chain slot.
45		///
46		/// This should be consistent with the logic the runtime uses when validating blocks to
47		/// avoid issues.
48		///
49		/// When the unincluded segment is empty, i.e. `included_hash == at`, where at is the block
50		/// whose state we are querying against, this must always return `true` as long as the slot
51		/// is more recent than the included block itself.
52		fn can_build_upon(included_hash: Block::Hash, slot: Slot) -> bool;
53	}
54}