Move serai_runtime specific code from tendermint/client to node

Renames serai-consensus to sc_tendermint
This commit is contained in:
Luke Parker
2022-10-30 10:54:17 -04:00
parent a0e0545c49
commit 91ae2b7112
6 changed files with 120 additions and 131 deletions

View File

@@ -1,7 +1,7 @@
[package]
name = "serai-consensus"
name = "sc_tendermint"
version = "0.1.0"
description = "Serai consensus module"
description = "Tendermint client for Substrate"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/tendermint/client"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
@@ -23,7 +23,6 @@ tokio = { version = "1", features = ["sync", "rt"] }
sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate" }
sp-inherents = { git = "https://github.com/serai-dex/substrate" }
sp-timestamp = { git = "https://github.com/serai-dex/substrate" }
sp-staking = { git = "https://github.com/serai-dex/substrate" }
sp-blockchain = { git = "https://github.com/serai-dex/substrate" }
sp-runtime = { git = "https://github.com/serai-dex/substrate" }
@@ -33,20 +32,13 @@ sp-consensus = { git = "https://github.com/serai-dex/substrate" }
sp-tendermint = { path = "../primitives" }
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }
sc-executor = { git = "https://github.com/serai-dex/substrate" }
sc-network = { git = "https://github.com/serai-dex/substrate" }
sc-network-gossip = { git = "https://github.com/serai-dex/substrate" }
sc-service = { git = "https://github.com/serai-dex/substrate" }
sc-client-db = { git = "https://github.com/serai-dex/substrate" }
sc-client-api = { git = "https://github.com/serai-dex/substrate" }
sc-consensus = { git = "https://github.com/serai-dex/substrate" }
frame-support = { git = "https://github.com/serai-dex/substrate" }
pallet-session = { git = "https://github.com/serai-dex/substrate" }
substrate-prometheus-endpoint = { git = "https://github.com/serai-dex/substrate" }
tendermint-machine = { path = "../machine", features = ["substrate"] }
serai-runtime = { path = "../../runtime" }

View File

@@ -1,26 +1,12 @@
use std::{boxed::Box, sync::Arc, error::Error};
use sp_runtime::traits::Block as BlockTrait;
use sp_inherents::CreateInherentDataProviders;
use sp_consensus::DisableProofRecording;
use sp_api::ProvideRuntimeApi;
use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
use sc_transaction_pool::FullPool;
use sc_network::NetworkService;
use sc_service::TFullClient;
use serai_runtime::{self, opaque::Block, RuntimeApi};
mod types;
use types::{TendermintClientMinimal, TendermintValidator};
pub use types::{TendermintClientMinimal, TendermintValidator};
mod validators;
pub(crate) mod tendermint;
pub use tendermint::TendermintImport;
mod block_import;
mod block_import;
mod import_queue;
pub use import_queue::{TendermintImportQueue, import_queue};
@@ -32,56 +18,3 @@ mod select_chain;
pub use select_chain::TendermintSelectChain;
const CONSENSUS_ID: [u8; 4] = *b"tend";
pub struct ExecutorDispatch;
impl NativeExecutionDispatch for ExecutorDispatch {
#[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)
}
fn native_version() -> NativeVersion {
serai_runtime::native_version()
}
}
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
pub struct Cidp;
#[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(),))
}
}
pub struct TendermintValidatorFirm;
impl TendermintClientMinimal for TendermintValidatorFirm {
const BLOCK_TIME_IN_SECONDS: u32 = { (serai_runtime::MILLISECS_PER_BLOCK / 1000) as u32 };
type Block = Block;
type Backend = sc_client_db::Backend<Block>;
type Api = <FullClient as ProvideRuntimeApi<Block>>::Api;
type Client = FullClient;
}
impl TendermintValidator for TendermintValidatorFirm {
type CIDP = Cidp;
type Environment = sc_basic_authorship::ProposerFactory<
FullPool<Block, FullClient>,
Self::Backend,
Self::Client,
DisableProofRecording,
>;
type Network = Arc<NetworkService<Block, <Block as BlockTrait>::Hash>>;
}

View File

@@ -1,7 +1,7 @@
[package]
name = "sp-tendermint"
version = "0.1.0"
description = "Substrate primitives for Tendermint"
description = "Tendermint primitives for Substrate"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/tendermint/primitives"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]