From c0432e122ce06119452a3a4b06b0af27e907afbb Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 21 Oct 2022 02:30:38 -0400 Subject: [PATCH] Update consensus/lib.rs from PoW to Tendermint Not possible to be used as the previous consensus could. It will not produce blocks nor does it currenly even instantiate a machine. This is just he next step. --- substrate/consensus/src/algorithm.rs | 27 ------------ substrate/consensus/src/lib.rs | 64 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 substrate/consensus/src/algorithm.rs diff --git a/substrate/consensus/src/algorithm.rs b/substrate/consensus/src/algorithm.rs deleted file mode 100644 index 9d51e4e1..00000000 --- a/substrate/consensus/src/algorithm.rs +++ /dev/null @@ -1,27 +0,0 @@ -use sp_core::U256; - -use sc_consensus_pow::{Error, PowAlgorithm}; -use sp_consensus_pow::Seal; - -use sp_runtime::{generic::BlockId, traits::Block as BlockT}; - -#[derive(Clone)] -pub struct AcceptAny; -impl PowAlgorithm for AcceptAny { - type Difficulty = U256; - - fn difficulty(&self, _: B::Hash) -> Result> { - Ok(U256::one()) - } - - fn verify( - &self, - _: &BlockId, - _: &B::Hash, - _: Option<&[u8]>, - _: &Seal, - _: Self::Difficulty, - ) -> Result> { - Ok(true) - } -} diff --git a/substrate/consensus/src/lib.rs b/substrate/consensus/src/lib.rs index e81c793f..762f8c20 100644 --- a/substrate/consensus/src/lib.rs +++ b/substrate/consensus/src/lib.rs @@ -1,21 +1,23 @@ -use std::{marker::Sync, sync::Arc, time::Duration}; +use std::sync::Arc; + +use sp_api::TransactionFor; +use sp_consensus::Error; + +use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor}; +use sc_service::{TaskManager, TFullClient}; use substrate_prometheus_endpoint::Registry; -use sc_consensus_pow as sc_pow; -use sc_executor::NativeElseWasmExecutor; -use sc_service::TaskManager; - use serai_runtime::{self, opaque::Block, RuntimeApi}; -mod algorithm; - mod signature_scheme; -mod import; -//mod tendermint; +mod weights; + +mod import_queue; +use import_queue::TendermintImportQueue; pub struct ExecutorDispatch; -impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { +impl NativeExecutionDispatch for ExecutorDispatch { #[cfg(feature = "runtime-benchmarks")] type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; #[cfg(not(feature = "runtime-benchmarks"))] @@ -25,41 +27,40 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { serai_runtime::api::dispatch(method, data) } - fn native_version() -> sc_executor::NativeVersion { + fn native_version() -> NativeVersion { serai_runtime::native_version() } } -pub type FullClient = - sc_service::TFullClient>; +pub type FullClient = TFullClient>; -type Db = sp_trie::PrefixedMemoryDB; - -pub fn import_queue + 'static>( +pub fn import_queue( task_manager: &TaskManager, client: Arc, - select_chain: S, registry: Option<&Registry>, -) -> Result, sp_consensus::Error> { - let pow_block_import = Box::new(sc_pow::PowBlockImport::new( +) -> Result>, Error> { + Ok(import_queue::import_queue( client.clone(), client, - algorithm::AcceptAny, - 0, - select_chain, - |_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) }, - )); - - sc_pow::import_queue( - pow_block_import, - None, - algorithm::AcceptAny, + Arc::new(|_, _| async { Ok(()) }), &task_manager.spawn_essential_handle(), registry, - ) + )) } -// Produce a block every 5 seconds +// If we're an authority, produce blocks +pub fn authority( + task_manager: &TaskManager, + client: Arc, + network: Arc::Hash>>, + pool: Arc>, + registry: Option<&Registry>, +) { + todo!() +} + +/* +// Produce a block every 6 seconds async fn produce< Block: sp_api::BlockT, Algorithm: sc_pow::PowAlgorithm + Send + Sync + 'static, @@ -126,3 +127,4 @@ pub fn authority + 'static>( task_manager.spawn_essential_handle().spawn("producer", None, produce(worker)); } +*/