start import queue in chain_ops as well

This commit is contained in:
Robert Habermeier
2018-10-17 16:09:05 -07:00
parent e7a50ff52a
commit fa62c8e9df
2 changed files with 15 additions and 7 deletions
+5 -5
View File
@@ -251,15 +251,15 @@ pub trait Link<B: BlockT>: Send {
/// Get chain reference. /// Get chain reference.
fn chain(&self) -> &Client<B>; fn chain(&self) -> &Client<B>;
/// Block imported. /// Block imported.
fn block_imported(&self, hash: &B::Hash, number: NumberFor<B>); fn block_imported(&self, _hash: &B::Hash, _number: NumberFor<B>) { }
/// Maintain sync. /// Maintain sync.
fn maintain_sync(&self); fn maintain_sync(&self) { }
/// Disconnect from peer. /// Disconnect from peer.
fn useless_peer(&self, who: NodeIndex, reason: &str); fn useless_peer(&self, _who: NodeIndex, _reason: &str) { }
/// Disconnect from peer and restart sync. /// Disconnect from peer and restart sync.
fn note_useless_and_restart_sync(&self, who: NodeIndex, reason: &str); fn note_useless_and_restart_sync(&self, _who: NodeIndex, _reason: &str) { }
/// Restart sync. /// Restart sync.
fn restart(&self); fn restart(&self) { }
} }
/// A link implementation that connects to the network. /// A link implementation that connects to the network.
+10 -2
View File
@@ -23,7 +23,7 @@ use serde_json;
use client::BlockOrigin; use client::BlockOrigin;
use runtime_primitives::generic::{SignedBlock, BlockId}; use runtime_primitives::generic::{SignedBlock, BlockId};
use runtime_primitives::traits::{As, Block, Header}; use runtime_primitives::traits::{As, Block, Header};
use network::import_queue::{ImportQueue, BlockData}; use network::import_queue::{ImportQueue, Link, BlockData};
use network::message; use network::message;
use components::{self, Components, ServiceFactory, FactoryFullConfiguration, FactoryBlockNumber, RuntimeGenesis}; use components::{self, Components, ServiceFactory, FactoryFullConfiguration, FactoryBlockNumber, RuntimeGenesis};
use new_client; use new_client;
@@ -87,8 +87,16 @@ pub fn export_blocks<F, E, W>(config: FactoryFullConfiguration<F>, exit: E, mut
pub fn import_blocks<F, E, R>(config: FactoryFullConfiguration<F>, exit: E, mut input: R) -> error::Result<()> pub fn import_blocks<F, E, R>(config: FactoryFullConfiguration<F>, exit: E, mut input: R) -> error::Result<()>
where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read, where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read,
{ {
use network::ClientHandle;
struct DummyLink<T>(::std::sync::Arc<T>);
impl<B: Block, T: ClientHandle<B>> Link<B> for DummyLink<T> {
fn chain(&self) -> &ClientHandle<B> { &*self.0 }
}
let client = new_client::<F>(&config)?; let client = new_client::<F>(&config)?;
let queue = components::FullComponents::<F>::build_import_queue(&config, client.clone())?; let queue = components::FullComponents::<F>::build_import_queue(&config, client.clone())?;
queue.start(DummyLink(client.clone()))?;
let (exit_send, exit_recv) = std::sync::mpsc::channel(); let (exit_send, exit_recv) = std::sync::mpsc::channel();
::std::thread::spawn(move || { ::std::thread::spawn(move || {
@@ -98,7 +106,7 @@ pub fn import_blocks<F, E, R>(config: FactoryFullConfiguration<F>, exit: E, mut
let count: u32 = Decode::decode(&mut input).ok_or("Error reading file")?; let count: u32 = Decode::decode(&mut input).ok_or("Error reading file")?;
info!("Importing {} blocks", count); info!("Importing {} blocks", count);
let mut block_count = 0; let mut block_count = 0;
for b in 0 .. count { for b in 0 .. count {
if exit_recv.try_recv().is_ok() { if exit_recv.try_recv().is_ok() {
break; break;