cumulus_primitives_aura/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
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	pub trait AuraUnincludedSegmentApi {
38		/// Whether it is legal to extend the chain, assuming the given block is the most
39		/// recently included one as-of the relay parent that will be built against, and
40		/// the given slot.
41		///
42		/// This should be consistent with the logic the runtime uses when validating blocks to
43		/// avoid issues.
44		///
45		/// When the unincluded segment is empty, i.e. `included_hash == at`, where at is the block
46		/// whose state we are querying against, this must always return `true` as long as the slot
47		/// is more recent than the included block itself.
48		fn can_build_upon(included_hash: Block::Hash, slot: Slot) -> bool;
49	}
50}