diff --git a/finality-aleph/src/justification/handler.rs b/finality-aleph/src/justification/handler.rs index f8ac7207b5..8528039b23 100644 --- a/finality-aleph/src/justification/handler.rs +++ b/finality-aleph/src/justification/handler.rs @@ -6,7 +6,7 @@ use std::{ use futures::{channel::mpsc, Stream, StreamExt}; use futures_timer::Delay; use log::{debug, error}; -use sc_client_api::backend::Backend; +use sc_client_api::blockchain::Backend as BlockchainBackend; use sp_api::BlockT; use sp_runtime::traits::Header; use tokio::time::timeout; @@ -20,7 +20,7 @@ use crate::{ network, Metrics, STATUS_REPORT_INTERVAL, }; -pub struct JustificationHandler +pub struct JustificationHandler where B: BlockT, V: Verifier, @@ -28,15 +28,15 @@ where S: JustificationRequestScheduler, SI: SessionInfoProvider, F: BlockFinalizer, - BE: Backend + Send + Sync + 'static, + BB: BlockchainBackend + Send + Sync + 'static, { session_info_provider: SI, - block_requester: BlockRequester, + block_requester: BlockRequester, verifier_timeout: Duration, notification_timeout: Duration, } -impl JustificationHandler +impl JustificationHandler where B: BlockT, V: Verifier, @@ -44,12 +44,12 @@ where S: JustificationRequestScheduler, SI: SessionInfoProvider, F: BlockFinalizer, - BE: Backend + Send + Sync + 'static, + BB: BlockchainBackend + Send + Sync + 'static, { pub fn new( session_info_provider: SI, block_requester: RB, - backend: Arc, + backend: Arc, finalizer: F, justification_request_scheduler: S, metrics: Option::Hash>>, diff --git a/finality-aleph/src/justification/requester.rs b/finality-aleph/src/justification/requester.rs index 5b7e01b591..58fe215019 100644 --- a/finality-aleph/src/justification/requester.rs +++ b/finality-aleph/src/justification/requester.rs @@ -2,7 +2,7 @@ use std::{fmt, marker::PhantomData, sync::Arc, time::Instant}; use aleph_primitives::ALEPH_ENGINE_ID; use log::{debug, error, info, warn}; -use sc_client_api::{backend::Backend, blockchain::Backend as _, HeaderBackend}; +use sc_client_api::{blockchain::Backend as BlockchainBackend, HeaderBackend}; use sp_api::{BlockId, BlockT, NumberFor}; use sp_runtime::traits::{Header, One}; @@ -72,17 +72,17 @@ impl fmt::Display for JustificationRequestStatus { } } -pub struct BlockRequester +pub struct BlockRequester where B: BlockT, RB: network::RequestBlocks + 'static, S: JustificationRequestScheduler, F: BlockFinalizer, V: Verifier, - BE: Backend, + BB: BlockchainBackend, { block_requester: RB, - backend: Arc, + backend: Arc, finalizer: F, justification_request_scheduler: S, metrics: Option::Hash>>, @@ -90,18 +90,18 @@ where _phantom: PhantomData, } -impl BlockRequester +impl BlockRequester where B: BlockT, RB: network::RequestBlocks + 'static, S: JustificationRequestScheduler, F: BlockFinalizer, V: Verifier, - BE: Backend, + BB: BlockchainBackend, { pub fn new( block_requester: RB, - backend: Arc, + backend: Arc, finalizer: F, justification_request_scheduler: S, metrics: Option::Hash>>, @@ -182,11 +182,11 @@ where } pub fn finalized_number(&self) -> NumberFor { - self.backend.blockchain().info().finalized_number + self.backend.info().finalized_number } fn request(&mut self, hash: ::Hash) { - if let Ok(Some(header)) = self.backend.blockchain().header(BlockId::Hash(hash)) { + if let Ok(Some(header)) = self.backend.header(BlockId::Hash(hash)) { let number = *header.number(); debug!(target: "aleph-justification", "Trying to request block {:?}", number); self.request_status.save_block_number(number); @@ -207,19 +207,16 @@ where // We don't remove the child that it's on the same branch as best since a fork may happen // somewhere in between them. fn request_targets(&self, mut top_wanted: NumberFor) -> Vec<::Hash> { - let blockchain_backend = self.backend.blockchain(); - let blockchain_info = blockchain_backend.info(); + let blockchain_info = self.backend.info(); let finalized_hash = blockchain_info.finalized_hash; - let mut targets = blockchain_backend - .children(finalized_hash) - .unwrap_or_default(); + let mut targets = self.backend.children(finalized_hash).unwrap_or_default(); let best_number = blockchain_info.best_number; if best_number <= top_wanted { // most probably block best_number is not yet finalized top_wanted = best_number - NumberFor::::one(); } - match blockchain_backend.hash(top_wanted) { + match self.backend.hash(top_wanted) { Ok(Some(hash)) => { if !targets.contains(&hash) { targets.push(hash); diff --git a/finality-aleph/src/nodes/mod.rs b/finality-aleph/src/nodes/mod.rs index 07c44fd60a..5827c81570 100644 --- a/finality-aleph/src/nodes/mod.rs +++ b/finality-aleph/src/nodes/mod.rs @@ -7,6 +7,7 @@ use aleph_primitives::{AuthorityId, SessionAuthorityData}; use codec::Encode; use log::warn; pub use nonvalidator_node::run_nonvalidator_node; +use sc_client_api::blockchain::Backend as BlockchainBackend; use sc_client_api::Backend; use sc_network::{ExHashT, NetworkService}; use sp_runtime::{ @@ -83,10 +84,10 @@ impl Verifier for JustificationVerifier { } } -struct JustificationParams { +struct JustificationParams { pub network: Arc>, pub client: Arc, - pub backend: Arc, + pub backend: Arc, pub justification_rx: mpsc::UnboundedReceiver>, pub metrics: Option::Hash>>, pub session_period: SessionPeriod, @@ -127,8 +128,8 @@ impl SessionInfoProvider for SessionInfoProv } } -fn setup_justification_handler( - just_params: JustificationParams, +fn setup_justification_handler( + just_params: JustificationParams, ) -> ( UnboundedSender>, impl Future, @@ -138,6 +139,7 @@ where H: ExHashT, C: crate::ClientForAleph + Send + Sync + 'static, C::Api: aleph_primitives::AlephSessionApi, + BB: BlockchainBackend + 'static, BE: Backend + 'static, { let JustificationParams { diff --git a/finality-aleph/src/nodes/nonvalidator_node.rs b/finality-aleph/src/nodes/nonvalidator_node.rs index b949d17f9c..dceaae4f5f 100644 --- a/finality-aleph/src/nodes/nonvalidator_node.rs +++ b/finality-aleph/src/nodes/nonvalidator_node.rs @@ -1,4 +1,5 @@ use log::{debug, error}; +use sc_client_api::blockchain::Backend as BlockchainBackend; use sc_client_api::Backend; use sc_network::ExHashT; use sp_consensus::SelectChain; @@ -10,12 +11,13 @@ use crate::{ AlephConfig, }; -pub async fn run_nonvalidator_node(aleph_config: AlephConfig) +pub async fn run_nonvalidator_node(aleph_config: AlephConfig) where B: Block, H: ExHashT, C: crate::ClientForAleph + Send + Sync + 'static, C::Api: aleph_primitives::AlephSessionApi, + BB: BlockchainBackend + 'static, BE: Backend + 'static, SC: SelectChain + 'static, { diff --git a/finality-aleph/src/nodes/validator_node.rs b/finality-aleph/src/nodes/validator_node.rs index 90d9b05bf1..82b4a14c8d 100644 --- a/finality-aleph/src/nodes/validator_node.rs +++ b/finality-aleph/src/nodes/validator_node.rs @@ -3,6 +3,7 @@ use std::{marker::PhantomData, sync::Arc}; use bip39::{Language, Mnemonic, MnemonicType}; use futures::channel::oneshot; use log::{debug, error}; +use sc_client_api::blockchain::Backend as BlockchainBackend; use sc_client_api::Backend; use sc_network::ExHashT; use sp_consensus::SelectChain; @@ -37,12 +38,13 @@ pub async fn new_pen(mnemonic: &str, keystore: Arc) -> Authorit .expect("we just generated this key so everything should work") } -pub async fn run_validator_node(aleph_config: AlephConfig) +pub async fn run_validator_node(aleph_config: AlephConfig) where B: Block, H: ExHashT, C: crate::ClientForAleph + Send + Sync + 'static, C::Api: aleph_primitives::AlephSessionApi, + BB: BlockchainBackend + 'static, BE: Backend + 'static, SC: SelectChain + 'static, {