2022-10-30 10:08:35 -04:00
|
|
|
use std::{boxed::Box, sync::Arc, error::Error};
|
2022-07-15 00:05:00 -04:00
|
|
|
|
2022-10-22 07:36:13 -04:00
|
|
|
use sp_runtime::traits::Block as BlockTrait;
|
2022-10-30 03:26:31 -04:00
|
|
|
use sp_inherents::CreateInherentDataProviders;
|
|
|
|
|
use sp_consensus::DisableProofRecording;
|
2022-10-30 10:08:35 -04:00
|
|
|
use sp_api::ProvideRuntimeApi;
|
2022-07-15 00:05:00 -04:00
|
|
|
|
2022-10-21 02:30:38 -04:00
|
|
|
use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
|
2022-10-21 23:36:24 -04:00
|
|
|
use sc_transaction_pool::FullPool;
|
2022-10-30 05:16:25 -04:00
|
|
|
use sc_network::NetworkService;
|
2022-10-30 10:08:35 -04:00
|
|
|
use sc_service::TFullClient;
|
2022-07-15 00:05:00 -04:00
|
|
|
|
2022-10-21 02:30:38 -04:00
|
|
|
use serai_runtime::{self, opaque::Block, RuntimeApi};
|
2022-10-20 03:50:06 -04:00
|
|
|
|
2022-10-30 03:26:31 -04:00
|
|
|
mod types;
|
2022-10-30 04:08:33 -04:00
|
|
|
use types::{TendermintClientMinimal, TendermintValidator};
|
2022-10-30 03:26:31 -04:00
|
|
|
|
2022-10-25 02:51:33 -04:00
|
|
|
mod validators;
|
2022-10-21 02:30:38 -04:00
|
|
|
|
2022-10-30 10:08:35 -04:00
|
|
|
pub(crate) mod tendermint;
|
|
|
|
|
pub use tendermint::TendermintImport;
|
2022-10-22 02:15:22 -04:00
|
|
|
mod block_import;
|
|
|
|
|
|
2022-10-21 02:30:38 -04:00
|
|
|
mod import_queue;
|
2022-10-30 10:08:35 -04:00
|
|
|
pub use import_queue::{TendermintImportQueue, import_queue};
|
2022-07-15 00:05:00 -04:00
|
|
|
|
2022-10-30 05:16:25 -04:00
|
|
|
pub(crate) mod gossip;
|
2022-10-30 10:08:35 -04:00
|
|
|
pub(crate) mod authority;
|
|
|
|
|
pub use authority::TendermintAuthority;
|
2022-10-30 01:21:10 -04:00
|
|
|
|
2022-10-21 05:28:26 -04:00
|
|
|
mod select_chain;
|
|
|
|
|
pub use select_chain::TendermintSelectChain;
|
|
|
|
|
|
2022-10-22 02:15:22 -04:00
|
|
|
const CONSENSUS_ID: [u8; 4] = *b"tend";
|
|
|
|
|
|
2022-07-15 00:05:00 -04:00
|
|
|
pub struct ExecutorDispatch;
|
2022-10-21 02:30:38 -04:00
|
|
|
impl NativeExecutionDispatch for ExecutorDispatch {
|
2022-07-15 00:05:00 -04:00
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
|
|
|
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
|
|
|
|
|
#[cfg(not(feature = "runtime-benchmarks"))]
|
|
|
|
|
type ExtendHostFunctions = ();
|
|
|
|
|
|
|
|
|
|
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
|
|
|
|
serai_runtime::api::dispatch(method, data)
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-21 02:30:38 -04:00
|
|
|
fn native_version() -> NativeVersion {
|
2022-07-15 00:05:00 -04:00
|
|
|
serai_runtime::native_version()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-21 02:30:38 -04:00
|
|
|
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
2022-07-15 00:05:00 -04:00
|
|
|
|
2022-10-30 04:08:33 -04:00
|
|
|
pub struct Cidp;
|
2022-10-30 03:26:31 -04:00
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
impl CreateInherentDataProviders<Block, ()> for Cidp {
|
|
|
|
|
type InherentDataProviders = (sp_timestamp::InherentDataProvider,);
|
|
|
|
|
async fn create_inherent_data_providers(
|
|
|
|
|
&self,
|
|
|
|
|
_: <Block as BlockTrait>::Hash,
|
|
|
|
|
_: (),
|
|
|
|
|
) -> Result<Self::InherentDataProviders, Box<dyn Send + Sync + Error>> {
|
|
|
|
|
Ok((sp_timestamp::InherentDataProvider::from_system_time(),))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-30 10:08:35 -04:00
|
|
|
pub struct TendermintValidatorFirm;
|
|
|
|
|
impl TendermintClientMinimal for TendermintValidatorFirm {
|
|
|
|
|
const BLOCK_TIME_IN_SECONDS: u32 = { (serai_runtime::MILLISECS_PER_BLOCK / 1000) as u32 };
|
|
|
|
|
|
2022-10-30 03:26:31 -04:00
|
|
|
type Block = Block;
|
|
|
|
|
type Backend = sc_client_db::Backend<Block>;
|
|
|
|
|
type Api = <FullClient as ProvideRuntimeApi<Block>>::Api;
|
|
|
|
|
type Client = FullClient;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-30 10:08:35 -04:00
|
|
|
impl TendermintValidator for TendermintValidatorFirm {
|
2022-10-30 03:26:31 -04:00
|
|
|
type CIDP = Cidp;
|
|
|
|
|
type Environment = sc_basic_authorship::ProposerFactory<
|
|
|
|
|
FullPool<Block, FullClient>,
|
|
|
|
|
Self::Backend,
|
|
|
|
|
Self::Client,
|
|
|
|
|
DisableProofRecording,
|
|
|
|
|
>;
|
|
|
|
|
|
2022-10-30 05:16:25 -04:00
|
|
|
type Network = Arc<NetworkService<Block, <Block as BlockTrait>::Hash>>;
|
2022-07-15 00:05:00 -04:00
|
|
|
}
|