referrerpolicy=no-referrer-when-downgrade

sp_consensus_aura/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Primitives for Aura.
19
20#![cfg_attr(not(feature = "std"), no_std)]
21
22extern crate alloc;
23
24use alloc::vec::Vec;
25use codec::{Codec, Decode, Encode};
26use sp_runtime::ConsensusEngineId;
27
28pub mod digests;
29pub mod inherents;
30
31pub mod sr25519 {
32	mod app_sr25519 {
33		use sp_application_crypto::{app_crypto, key_types::AURA, sr25519};
34		app_crypto!(sr25519, AURA);
35	}
36
37	sp_application_crypto::with_pair! {
38		/// An Aura authority keypair using S/R 25519 as its crypto.
39		pub type AuthorityPair = app_sr25519::Pair;
40	}
41
42	/// An Aura authority signature using S/R 25519 as its crypto.
43	pub type AuthoritySignature = app_sr25519::Signature;
44
45	/// An Aura authority identifier using S/R 25519 as its crypto.
46	pub type AuthorityId = app_sr25519::Public;
47}
48
49pub mod ed25519 {
50	mod app_ed25519 {
51		use sp_application_crypto::{app_crypto, ed25519, key_types::AURA};
52		app_crypto!(ed25519, AURA);
53	}
54
55	sp_application_crypto::with_pair! {
56		/// An Aura authority keypair using Ed25519 as its crypto.
57		pub type AuthorityPair = app_ed25519::Pair;
58	}
59
60	/// An Aura authority signature using Ed25519 as its crypto.
61	pub type AuthoritySignature = app_ed25519::Signature;
62
63	/// An Aura authority identifier using Ed25519 as its crypto.
64	pub type AuthorityId = app_ed25519::Public;
65}
66
67pub use sp_consensus_slots::{Slot, SlotDuration};
68
69/// The `ConsensusEngineId` of AuRa.
70pub const AURA_ENGINE_ID: ConsensusEngineId = [b'a', b'u', b'r', b'a'];
71
72/// The index of an authority.
73pub type AuthorityIndex = u32;
74
75/// An consensus log item for Aura.
76#[derive(Decode, Encode)]
77pub enum ConsensusLog<AuthorityId: Codec> {
78	/// The authorities have changed.
79	#[codec(index = 1)]
80	AuthoritiesChange(Vec<AuthorityId>),
81	/// Disable the authority with given index.
82	#[codec(index = 2)]
83	OnDisabled(AuthorityIndex),
84}
85
86sp_api::decl_runtime_apis! {
87	/// API necessary for block authorship with aura.
88	pub trait AuraApi<AuthorityId: Codec> {
89		/// Returns the slot duration for Aura.
90		///
91		/// Currently, only the value provided by this type at genesis will be used.
92		fn slot_duration() -> SlotDuration;
93
94		/// Return the current set of authorities.
95		fn authorities() -> Vec<AuthorityId>;
96	}
97}