mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 23:01:01 +00:00
095f4bd9ae
This PR introduces the pallet for Sassafras consensus. ## Non Goals The pallet delivers only the bare-bones and doesn't deliver support for auxiliary functionalities such as equivocation report and support for epoch change via session pallet. These functionalities were drafted in the [main PR](https://github.com/paritytech/polkadot-sdk/pull/1336), but IMO is better to introduce this auxiliary stuff in a follow up PR and after client code. ## Potential follow ups https://github.com/paritytech/polkadot-sdk/issues/2364 --------- Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: Koute <koute@users.noreply.github.com> Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Bastian Köcher <git@kchr.de>
99 lines
2.9 KiB
Rust
99 lines
2.9 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// 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.
|
|
|
|
//! Sassafras digests structures and helpers.
|
|
|
|
use crate::{
|
|
ticket::TicketClaim, vrf::VrfSignature, AuthorityId, AuthorityIndex, AuthoritySignature,
|
|
EpochConfiguration, Randomness, Slot, SASSAFRAS_ENGINE_ID,
|
|
};
|
|
|
|
use scale_codec::{Decode, Encode, MaxEncodedLen};
|
|
use scale_info::TypeInfo;
|
|
|
|
use sp_runtime::{DigestItem, RuntimeDebug};
|
|
use sp_std::vec::Vec;
|
|
|
|
/// Epoch slot claim digest entry.
|
|
///
|
|
/// This is mandatory for each block.
|
|
#[derive(Clone, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
|
pub struct SlotClaim {
|
|
/// Authority index that claimed the slot.
|
|
pub authority_idx: AuthorityIndex,
|
|
/// Corresponding slot number.
|
|
pub slot: Slot,
|
|
/// Slot claim VRF signature.
|
|
pub vrf_signature: VrfSignature,
|
|
/// Ticket auxiliary information for claim check.
|
|
pub ticket_claim: Option<TicketClaim>,
|
|
}
|
|
|
|
/// Information about the next epoch.
|
|
///
|
|
/// This is mandatory in the first block of each epoch.
|
|
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
|
pub struct NextEpochDescriptor {
|
|
/// Randomness value.
|
|
pub randomness: Randomness,
|
|
/// Authorities list.
|
|
pub authorities: Vec<AuthorityId>,
|
|
/// Epoch configuration.
|
|
///
|
|
/// If not present previous epoch parameters are used.
|
|
pub config: Option<EpochConfiguration>,
|
|
}
|
|
|
|
/// Runtime digest entries.
|
|
///
|
|
/// Entries which may be generated by on-chain code.
|
|
#[derive(Decode, Encode, Clone, PartialEq, Eq)]
|
|
pub enum ConsensusLog {
|
|
/// Provides information about the next epoch parameters.
|
|
#[codec(index = 1)]
|
|
NextEpochData(NextEpochDescriptor),
|
|
/// Disable the authority with given index.
|
|
#[codec(index = 2)]
|
|
OnDisabled(AuthorityIndex),
|
|
}
|
|
|
|
impl TryFrom<&DigestItem> for SlotClaim {
|
|
type Error = ();
|
|
fn try_from(item: &DigestItem) -> Result<Self, Self::Error> {
|
|
item.pre_runtime_try_to(&SASSAFRAS_ENGINE_ID).ok_or(())
|
|
}
|
|
}
|
|
|
|
impl From<&SlotClaim> for DigestItem {
|
|
fn from(claim: &SlotClaim) -> Self {
|
|
DigestItem::PreRuntime(SASSAFRAS_ENGINE_ID, claim.encode())
|
|
}
|
|
}
|
|
|
|
impl TryFrom<&DigestItem> for AuthoritySignature {
|
|
type Error = ();
|
|
fn try_from(item: &DigestItem) -> Result<Self, Self::Error> {
|
|
item.seal_try_to(&SASSAFRAS_ENGINE_ID).ok_or(())
|
|
}
|
|
}
|
|
|
|
impl From<&AuthoritySignature> for DigestItem {
|
|
fn from(signature: &AuthoritySignature) -> Self {
|
|
DigestItem::Seal(SASSAFRAS_ENGINE_ID, signature.encode())
|
|
}
|
|
}
|