fixed master (#6465)

* fixed master

* Revert "Merge pull request #6370 from paritytech/light-poa"

This reverts commit 3c60f99def, reversing
changes made to b731ccea18.
This commit is contained in:
Marek Kotewicz
2017-09-05 14:53:09 +02:00
committed by Arkadiy Paronyan
parent e5bbabb2ba
commit 899538ae25
41 changed files with 265 additions and 1269 deletions

View File

@@ -30,7 +30,7 @@ use util::kvdb::{Database, DatabaseConfig};
use cache::Cache;
use parking_lot::Mutex;
use super::{ChainDataFetcher, Client, Config as ClientConfig};
use super::{Client, Config as ClientConfig};
/// Errors on service initialization.
#[derive(Debug)]
@@ -51,14 +51,14 @@ impl fmt::Display for Error {
}
/// Light client service.
pub struct Service<T> {
client: Arc<Client<T>>,
pub struct Service {
client: Arc<Client>,
io_service: IoService<ClientIoMessage>,
}
impl<T: ChainDataFetcher> Service<T> {
impl Service {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, fetcher: T, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
pub fn start(config: ClientConfig, spec: &Spec, path: &Path, cache: Arc<Mutex<Cache>>) -> Result<Self, Error> {
// initialize database.
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
@@ -81,14 +81,10 @@ impl<T: ChainDataFetcher> Service<T> {
db,
db::COL_LIGHT_CHAIN,
spec,
fetcher,
io_service.channel(),
cache,
).map_err(Error::Database)?);
io_service.register_handler(Arc::new(ImportBlocks(client.clone()))).map_err(Error::Io)?;
spec.engine.register_client(Arc::downgrade(&client) as _);
Ok(Service {
client: client,
io_service: io_service,
@@ -101,14 +97,14 @@ impl<T: ChainDataFetcher> Service<T> {
}
/// Get a handle to the client.
pub fn client(&self) -> &Arc<Client<T>> {
pub fn client(&self) -> &Arc<Client> {
&self.client
}
}
struct ImportBlocks<T>(Arc<Client<T>>);
struct ImportBlocks(Arc<Client>);
impl<T: ChainDataFetcher> IoHandler<ClientIoMessage> for ImportBlocks<T> {
impl IoHandler<ClientIoMessage> for ImportBlocks {
fn message(&self, _io: &IoContext<ClientIoMessage>, message: &ClientIoMessage) {
if let ClientIoMessage::BlockVerified = *message {
self.0.import_verified();
@@ -124,7 +120,6 @@ mod tests {
use std::sync::Arc;
use cache::Cache;
use client::fetch;
use time::Duration;
use parking_lot::Mutex;
@@ -134,6 +129,6 @@ mod tests {
let temp_path = RandomTempPath::new();
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
Service::start(Default::default(), &spec, fetch::unavailable(), temp_path.as_path(), cache).unwrap();
Service::start(Default::default(), &spec, temp_path.as_path(), cache).unwrap();
}
}