consensus: Make BlockVerifier respond with the BlockHeaderHash

Part of #428.
This commit is contained in:
teor 2020-06-10 14:54:35 +10:00 committed by Henry de Valence
parent c019726fb1
commit 4181c8a5d5
1 changed files with 15 additions and 11 deletions

View File

@ -9,14 +9,14 @@
//! verification. //! verification.
use std::{ use std::{
error::Error, error,
future::Future, future::Future,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tower::{buffer::Buffer, Service}; use tower::{buffer::Buffer, Service};
use zebra_chain::block::Block; use zebra_chain::block::{Block, BlockHeaderHash};
mod script; mod script;
mod transaction; mod transaction;
@ -29,17 +29,16 @@ mod transaction;
struct BlockVerifier {} struct BlockVerifier {}
/// The result type for the BlockVerifier Service. /// The result type for the BlockVerifier Service.
// TODO(teor): Response = BlockHeaderHash type Response = BlockHeaderHash;
type Response = ();
/// The error type for the BlockVerifier Service. /// The error type for the BlockVerifier Service.
// TODO(jlusby): Error = Report ? // TODO(jlusby): Error = Report ?
type ServiceError = Box<dyn Error + Send + Sync + 'static>; type Error = Box<dyn error::Error + Send + Sync + 'static>;
/// The BlockVerifier service implementation. /// The BlockVerifier service implementation.
impl Service<Block> for BlockVerifier { impl Service<Block> for BlockVerifier {
type Response = Response; type Response = Response;
type Error = ServiceError; type Error = Error;
type Future = type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>; Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
@ -52,13 +51,18 @@ impl Service<Block> for BlockVerifier {
fn call(&mut self, block: Block) -> Self::Future { fn call(&mut self, block: Block) -> Self::Future {
let mut state_service = zebra_state::in_memory::init(); let mut state_service = zebra_state::in_memory::init();
// Ignore errors, they are already handled correctly. let header_hash: BlockHeaderHash = (&block).into();
// AddBlock discards invalid blocks.
// Ignore errors for now.
// TODO(jlusby): Error = Report, handle errors from state_service.
// TODO(teor):
// - handle chain reorgs, adjust state_service "unique block height" conditions
// - handle block validation errors (including errors in the block's transactions)
let _ = state_service.call(zebra_state::Request::AddBlock { let _ = state_service.call(zebra_state::Request::AddBlock {
block: block.into(), block: block.into(),
}); });
Box::pin(async { Ok(()) }) Box::pin(async move { Ok(header_hash) })
} }
} }
@ -66,8 +70,8 @@ impl Service<Block> for BlockVerifier {
pub fn init() -> impl Service< pub fn init() -> impl Service<
Block, Block,
Response = Response, Response = Response,
Error = ServiceError, Error = Error,
Future = impl Future<Output = Result<Response, ServiceError>>, Future = impl Future<Output = Result<Response, Error>>,
> + Send > + Send
+ Clone + Clone
+ 'static { + 'static {