serve epoch signals over network and check them
This commit is contained in:
@@ -16,9 +16,13 @@
|
||||
|
||||
//! Trait for fetching chain data.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ethcore::engines::{Engine, StateDependentProof};
|
||||
use ethcore::header::Header;
|
||||
use ethcore::receipt::Receipt;
|
||||
use futures::future::IntoFuture;
|
||||
use util::H256;
|
||||
|
||||
/// Provides full chain data.
|
||||
pub trait ChainDataFetcher: Send + Sync + 'static {
|
||||
@@ -39,7 +43,7 @@ pub trait ChainDataFetcher: Send + Sync + 'static {
|
||||
fn block_receipts(&self, header: &Header) -> Self::Receipts;
|
||||
|
||||
/// Fetch epoch transition proof at given header.
|
||||
fn epoch_transition(&self, header: &Header) -> Self::Transition;
|
||||
fn epoch_transition(&self, hash: H256, engine: Arc<Engine>, checker: Arc<StateDependentProof>) -> Self::Transition;
|
||||
}
|
||||
|
||||
/// Fetcher implementation which cannot fetch anything.
|
||||
@@ -63,7 +67,7 @@ impl ChainDataFetcher for Unavailable {
|
||||
Err("fetching block receipts unavailable")
|
||||
}
|
||||
|
||||
fn epoch_transition(&self, _header: &Header) -> Self::Body {
|
||||
fn epoch_transition(&self, _h: H256, _e: Arc<Engine>, _check: Arc<StateDependentProof>) -> Self::Transition {
|
||||
Err("fetching epoch transition proofs unavailable")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,14 +508,11 @@ impl<T: ChainDataFetcher> Client<T> {
|
||||
let proof = match proof {
|
||||
Proof::Known(known) => known,
|
||||
Proof::WithState(state_dependent) => {
|
||||
loop {
|
||||
let proof = self.fetcher.epoch_transition(header).into_future().wait()?;
|
||||
match state_dependent.check_proof(&*self.engine, &proof) {
|
||||
Ok(()) => break proof,
|
||||
Err(e) =>
|
||||
debug!(target: "client", "Fetched bad epoch transition proof from network: {}", e),
|
||||
}
|
||||
}
|
||||
self.fetcher.epoch_transition(
|
||||
header.hash(),
|
||||
self.engine.clone(),
|
||||
state_dependent
|
||||
).into_future().wait()?
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user