diff --git a/Cargo.lock b/Cargo.lock index 917e0fd8..067c49b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7321,6 +7321,34 @@ dependencies = [ "prometheus", ] +[[package]] +name = "sc_tendermint" +version = "0.1.0" +dependencies = [ + "async-trait", + "futures", + "log", + "sc-client-api", + "sc-consensus", + "sc-executor", + "sc-network", + "sc-network-gossip", + "sc-service", + "sc-transaction-pool", + "sp-api", + "sp-application-crypto", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-staking", + "sp-tendermint", + "substrate-prometheus-endpoint", + "tendermint-machine", + "tokio", +] + [[package]] name = "scale-info" version = "2.2.0" @@ -7525,40 +7553,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "930c0acf610d3fdb5e2ab6213019aaa04e227ebe9547b0649ba599b16d788bd7" -[[package]] -name = "serai-consensus" -version = "0.1.0" -dependencies = [ - "async-trait", - "frame-support", - "futures", - "log", - "pallet-session", - "sc-basic-authorship", - "sc-client-api", - "sc-client-db", - "sc-consensus", - "sc-executor", - "sc-network", - "sc-network-gossip", - "sc-service", - "sc-transaction-pool", - "serai-runtime", - "sp-api", - "sp-application-crypto", - "sp-blockchain", - "sp-consensus", - "sp-core", - "sp-inherents", - "sp-runtime", - "sp-staking", - "sp-tendermint", - "sp-timestamp", - "substrate-prometheus-endpoint", - "tendermint-machine", - "tokio", -] - [[package]] name = "serai-extension" version = "0.1.0" @@ -7587,6 +7581,7 @@ dependencies = [ name = "serai-node" version = "0.1.0" dependencies = [ + "async-trait", "clap 4.0.18", "frame-benchmarking", "frame-benchmarking-cli", @@ -7598,6 +7593,7 @@ dependencies = [ "sc-basic-authorship", "sc-cli", "sc-client-api", + "sc-client-db", "sc-consensus", "sc-executor", "sc-keystore", @@ -7608,12 +7604,13 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", - "serai-consensus", + "sc_tendermint", "serai-runtime", "sp-api", "sp-application-crypto", "sp-block-builder", "sp-blockchain", + "sp-consensus", "sp-core", "sp-inherents", "sp-keyring", diff --git a/substrate/node/Cargo.toml b/substrate/node/Cargo.toml index 90c392f3..a6b74b5e 100644 --- a/substrate/node/Cargo.toml +++ b/substrate/node/Cargo.toml @@ -12,28 +12,33 @@ publish = false name = "serai-node" [dependencies] +async-trait = "0.1" + clap = { version = "4", features = ["derive"] } jsonrpsee = { version = "0.15", features = ["server"] } sp-core = { git = "https://github.com/serai-dex/substrate" } sp-application-crypto = { git = "https://github.com/serai-dex/substrate" } -sp-runtime = { git = "https://github.com/serai-dex/substrate" } -sp-timestamp = { git = "https://github.com/serai-dex/substrate" } -sp-inherents = { git = "https://github.com/serai-dex/substrate" } sp-keyring = { git = "https://github.com/serai-dex/substrate" } -sp-api = { 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-runtime = { git = "https://github.com/serai-dex/substrate" } sp-blockchain = { git = "https://github.com/serai-dex/substrate" } +sp-api = { git = "https://github.com/serai-dex/substrate" } sp-block-builder = { git = "https://github.com/serai-dex/substrate" } +sp-consensus = { git = "https://github.com/serai-dex/substrate" } sc-keystore = { git = "https://github.com/serai-dex/substrate" } sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" } -sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" } sc-transaction-pool-api = { 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-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-network = { git = "https://github.com/serai-dex/substrate" } sc-consensus = { git = "https://github.com/serai-dex/substrate" } + sc-telemetry = { git = "https://github.com/serai-dex/substrate" } sc-cli = { git = "https://github.com/serai-dex/substrate" } @@ -50,7 +55,7 @@ pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate pallet-tendermint = { path = "../tendermint/pallet", default-features = false } serai-runtime = { path = "../runtime" } -serai-consensus = { path = "../tendermint/client" } +sc_tendermint = { path = "../tendermint/client" } [build-dependencies] substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate.git" } diff --git a/substrate/node/src/service.rs b/substrate/node/src/service.rs index ac9921b0..bc2e9745 100644 --- a/substrate/node/src/service.rs +++ b/substrate/node/src/service.rs @@ -1,16 +1,25 @@ -use std::sync::Arc; +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::{error::Error as ServiceError, Configuration, TaskManager, TFullClient}; -use sc_executor::NativeElseWasmExecutor; -use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; -use serai_runtime::{self, opaque::Block, RuntimeApi}; -pub(crate) use serai_consensus::{ - TendermintImport, TendermintAuthority, ExecutorDispatch, FullClient, TendermintValidatorFirm, +pub(crate) use sc_tendermint::{ + TendermintClientMinimal, TendermintValidator, TendermintImport, TendermintAuthority, + TendermintSelectChain, import_queue, }; +use serai_runtime::{self, MILLISECS_PER_BLOCK, opaque::Block, RuntimeApi}; type FullBackend = sc_service::TFullBackend; -type FullSelectChain = serai_consensus::TendermintSelectChain; +type FullSelectChain = TendermintSelectChain; type PartialComponents = sc_service::PartialComponents< FullClient, @@ -21,6 +30,59 @@ type PartialComponents = sc_service::PartialComponents< Option, >; +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> { + serai_runtime::api::dispatch(method, data) + } + + fn native_version() -> NativeVersion { + serai_runtime::native_version() + } +} + +pub type FullClient = TFullClient>; + +pub struct Cidp; +#[async_trait::async_trait] +impl CreateInherentDataProviders for Cidp { + type InherentDataProviders = (sp_timestamp::InherentDataProvider,); + async fn create_inherent_data_providers( + &self, + _: ::Hash, + _: (), + ) -> Result> { + Ok((sp_timestamp::InherentDataProvider::from_system_time(),)) + } +} + +pub struct TendermintValidatorFirm; +impl TendermintClientMinimal for TendermintValidatorFirm { + const BLOCK_TIME_IN_SECONDS: u32 = { (MILLISECS_PER_BLOCK / 1000) as u32 }; + + type Block = Block; + type Backend = sc_client_db::Backend; + type Api = >::Api; + type Client = FullClient; +} + +impl TendermintValidator for TendermintValidatorFirm { + type CIDP = Cidp; + type Environment = sc_basic_authorship::ProposerFactory< + FullPool, + Self::Backend, + Self::Client, + DisableProofRecording, + >; + + type Network = Arc::Hash>>; +} + pub fn new_partial( config: &Configuration, ) -> Result<(TendermintImport, PartialComponents), ServiceError> { @@ -67,13 +129,13 @@ pub fn new_partial( client.clone(), ); - let (authority, import_queue) = serai_consensus::import_queue( + let (authority, import_queue) = import_queue( &task_manager.spawn_essential_handle(), client.clone(), config.prometheus_registry(), ); - let select_chain = serai_consensus::TendermintSelectChain::new(backend.clone()); + let select_chain = TendermintSelectChain::new(backend.clone()); Ok(( authority, @@ -161,7 +223,7 @@ pub async fn new_full(config: Configuration) -> Result"] @@ -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" } diff --git a/substrate/tendermint/client/src/lib.rs b/substrate/tendermint/client/src/lib.rs index c31ad687..0888db56 100644 --- a/substrate/tendermint/client/src/lib.rs +++ b/substrate/tendermint/client/src/lib.rs @@ -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> { - serai_runtime::api::dispatch(method, data) - } - - fn native_version() -> NativeVersion { - serai_runtime::native_version() - } -} - -pub type FullClient = TFullClient>; - -pub struct Cidp; -#[async_trait::async_trait] -impl CreateInherentDataProviders for Cidp { - type InherentDataProviders = (sp_timestamp::InherentDataProvider,); - async fn create_inherent_data_providers( - &self, - _: ::Hash, - _: (), - ) -> Result> { - 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; - type Api = >::Api; - type Client = FullClient; -} - -impl TendermintValidator for TendermintValidatorFirm { - type CIDP = Cidp; - type Environment = sc_basic_authorship::ProposerFactory< - FullPool, - Self::Backend, - Self::Client, - DisableProofRecording, - >; - - type Network = Arc::Hash>>; -} diff --git a/substrate/tendermint/primitives/Cargo.toml b/substrate/tendermint/primitives/Cargo.toml index a152fa7d..6200add5 100644 --- a/substrate/tendermint/primitives/Cargo.toml +++ b/substrate/tendermint/primitives/Cargo.toml @@ -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 "]