use std::{sync::Arc, time::Duration};
use futures::prelude::*;
use subsoil::api::ProofRecorder;
use subsoil::externalities::Extensions;
use subsoil::runtime::{
traits::{Block as BlockT, HashingFor},
Digest,
};
pub mod block_validation;
pub mod error;
mod select_chain;
pub use self::error::Error;
pub use select_chain::SelectChain;
pub use subsoil::inherents::InherentData;
pub use subsoil::state_machine::Backend as StateBackend;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum BlockStatus {
Queued,
InChainWithState,
InChainPruned,
KnownBad,
Unknown,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum BlockOrigin {
Genesis,
NetworkInitialSync,
NetworkBroadcast,
ConsensusBroadcast,
Own,
File,
WarpSync,
GapSync,
}
pub trait Environment<B: BlockT> {
type Proposer: Proposer<B> + Send + 'static;
type CreateProposer: Future<Output = Result<Self::Proposer, Self::Error>>
+ Send
+ Unpin
+ 'static;
type Error: From<Error> + Send + Sync + std::error::Error + 'static;
fn init(&mut self, parent_header: &B::Header) -> Self::CreateProposer;
}
pub struct Proposal<Block: BlockT> {
pub block: Block,
pub storage_changes: subsoil::state_machine::StorageChanges<HashingFor<Block>>,
}
pub struct ProposeArgs<B: BlockT> {
pub inherent_data: InherentData,
pub inherent_digests: Digest,
pub max_duration: Duration,
pub block_size_limit: Option<usize>,
pub storage_proof_recorder: Option<ProofRecorder<B>>,
pub extra_extensions: Extensions,
}
impl<B: BlockT> Default for ProposeArgs<B> {
fn default() -> Self {
Self {
inherent_data: Default::default(),
inherent_digests: Default::default(),
max_duration: Default::default(),
block_size_limit: Default::default(),
storage_proof_recorder: Default::default(),
extra_extensions: Default::default(),
}
}
}
pub trait Proposer<B: BlockT> {
type Error: From<Error> + Send + Sync + std::error::Error + 'static;
type Proposal: Future<Output = Result<Proposal<B>, Self::Error>> + Send + Unpin + 'static;
fn propose(self, args: ProposeArgs<B>) -> Self::Proposal;
}
pub trait SyncOracle {
fn is_major_syncing(&self) -> bool;
fn is_offline(&self) -> bool;
}
#[derive(Clone, Copy, Debug)]
pub struct NoNetwork;
impl SyncOracle for NoNetwork {
fn is_major_syncing(&self) -> bool {
false
}
fn is_offline(&self) -> bool {
false
}
}
impl<T> SyncOracle for Arc<T>
where
T: ?Sized,
T: SyncOracle,
{
fn is_major_syncing(&self) -> bool {
T::is_major_syncing(self)
}
fn is_offline(&self) -> bool {
T::is_offline(self)
}
}