#![deny(warnings)]
#![forbid(unsafe_code, missing_docs, unused_variables, unused_imports)]
use crate::core::crypto::KeyTypeId;
use crate::runtime::ConsensusEngineId;
use alloc::vec::Vec;
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
pub use crate::consensus::slots::{Slot, SlotDuration};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub mod digests;
pub mod ticket;
pub mod vrf;
pub use ticket::{
ticket_id_threshold, EphemeralPublic, EphemeralSignature, TicketBody, TicketClaim,
TicketEnvelope, TicketId,
};
mod app {
use crate::application_crypto::{bandersnatch, key_types::SASSAFRAS};
crate::app_crypto!(bandersnatch, SASSAFRAS);
}
pub const KEY_TYPE: KeyTypeId = crate::application_crypto::key_types::SASSAFRAS;
pub const SASSAFRAS_ENGINE_ID: ConsensusEngineId = *b"SASS";
pub const RANDOMNESS_LENGTH: usize = 32;
pub type AuthorityIndex = u32;
#[cfg(feature = "std")]
pub type AuthorityPair = app::Pair;
pub type AuthoritySignature = app::Signature;
pub type AuthorityId = app::Public;
pub type SassafrasBlockWeight = u32;
pub type EquivocationProof<H> = crate::consensus::slots::EquivocationProof<H, AuthorityId>;
pub type Randomness = [u8; RANDOMNESS_LENGTH];
#[derive(
Copy,
Clone,
PartialEq,
Eq,
Encode,
Decode,
DecodeWithMemTracking,
Debug,
MaxEncodedLen,
TypeInfo,
Default,
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EpochConfiguration {
pub redundancy_factor: u32,
pub attempts_number: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Epoch {
pub index: u64,
pub start: Slot,
pub length: u32,
pub randomness: Randomness,
pub authorities: Vec<AuthorityId>,
pub config: EpochConfiguration,
}
#[derive(Decode, Encode, PartialEq, TypeInfo)]
#[repr(transparent)]
pub struct OpaqueKeyOwnershipProof(Vec<u8>);
crate::api::decl_runtime_apis! {
pub trait SassafrasApi {
fn ring_context() -> Option<vrf::RingContext>;
fn submit_tickets_unsigned_extrinsic(tickets: Vec<TicketEnvelope>) -> bool;
fn slot_ticket_id(slot: Slot) -> Option<TicketId>;
fn slot_ticket(slot: Slot) -> Option<(TicketId, TicketBody)>;
fn current_epoch() -> Epoch;
fn next_epoch() -> Epoch;
fn generate_key_ownership_proof(authority_id: AuthorityId) -> Option<OpaqueKeyOwnershipProof>;
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: EquivocationProof<Block::Header>,
key_owner_proof: OpaqueKeyOwnershipProof,
) -> bool;
}
}