From 422f7e3e2fb552091228d999549073f554ba380f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 21 Oct 2022 21:14:05 -0400 Subject: [PATCH] Replace panicking todos with stubs and // TODO Enables progress. --- substrate/consensus/src/import_queue.rs | 29 ++++++++++++++------- substrate/consensus/src/signature_scheme.rs | 8 ++++++ substrate/consensus/src/weights.rs | 1 + 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/substrate/consensus/src/import_queue.rs b/substrate/consensus/src/import_queue.rs index cdf6ced3..e887b82d 100644 --- a/substrate/consensus/src/import_queue.rs +++ b/substrate/consensus/src/import_queue.rs @@ -21,7 +21,7 @@ use async_trait::async_trait; use tokio::sync::RwLock as AsyncRwLock; -use sp_core::Decode; +use sp_core::{Encode, Decode}; use sp_application_crypto::sr25519::Signature; use sp_inherents::CreateInherentDataProviders; use sp_runtime::{ @@ -109,7 +109,8 @@ impl< block: B, providers: CIDP::InherentDataProviders, ) -> Result<(), Error> { - todo!() + // TODO + Ok(()) } // Ensure this is part of a sequential import @@ -218,6 +219,18 @@ impl< Ok(()) } + + fn import_justification_actual( + &mut self, + hash: B::Hash, + justification: Justification, + ) -> Result<(), Error> { + self.verify_justification(hash, &justification)?; + self + .client + .finalize_block(BlockId::Hash(hash), Some(justification), true) + .map_err(|_| Error::InvalidJustification) + } } #[async_trait] @@ -282,11 +295,7 @@ impl< _: ::Number, justification: Justification, ) -> Result<(), Error> { - self.verify_justification(hash, &justification)?; - self - .client - .finalize_block(BlockId::Hash(hash), Some(justification), true) - .map_err(|_| Error::InvalidJustification) + self.import_justification_actual(hash, justification) } } @@ -325,7 +334,7 @@ impl< const BLOCK_TIME: u32 = { (serai_runtime::MILLISECS_PER_BLOCK / 1000) as u32 }; fn signature_scheme(&self) -> Arc { - todo!() + Arc::new(TendermintSigner::new()) } fn weights(&self) -> Arc { @@ -333,7 +342,7 @@ impl< } async fn broadcast(&mut self, msg: SignedMessage) { - todo!() + // TODO } async fn slash(&mut self, validator: u16) { @@ -348,6 +357,8 @@ impl< } fn add_block(&mut self, block: B, commit: Commit) -> B { + self.import_justification_actual(block.hash(), (CONSENSUS_ID, commit.encode())).unwrap(); + // Next block proposal todo!() } } diff --git a/substrate/consensus/src/signature_scheme.rs b/substrate/consensus/src/signature_scheme.rs index bf3c3e72..bf552f36 100644 --- a/substrate/consensus/src/signature_scheme.rs +++ b/substrate/consensus/src/signature_scheme.rs @@ -10,6 +10,14 @@ pub(crate) struct TendermintSigner { lookup: Vec, } +impl TendermintSigner { + pub(crate) fn new() -> TendermintSigner { + // TODO + let keys = Pair::from_string("//Alice", None).unwrap(); + TendermintSigner { lookup: vec![keys.public()], keys } + } +} + impl SignatureScheme for TendermintSigner { type ValidatorId = u16; type Signature = Signature; diff --git a/substrate/consensus/src/weights.rs b/substrate/consensus/src/weights.rs index d9d5c405..f6c801e1 100644 --- a/substrate/consensus/src/weights.rs +++ b/substrate/consensus/src/weights.rs @@ -4,6 +4,7 @@ use tendermint_machine::ext::{BlockNumber, Round, Weights}; const VALIDATORS: usize = 1; +// TODO: Move to sp_session pub(crate) struct TendermintWeights; impl Weights for TendermintWeights { type ValidatorId = u16;