From 4181c8a5d5a53d3b322e066f3b34446c84568193 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 10 Jun 2020 14:54:35 +1000 Subject: [PATCH] consensus: Make BlockVerifier respond with the BlockHeaderHash Part of #428. --- zebra-consensus/src/verify.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/zebra-consensus/src/verify.rs b/zebra-consensus/src/verify.rs index 3379d1c2..7a230d76 100644 --- a/zebra-consensus/src/verify.rs +++ b/zebra-consensus/src/verify.rs @@ -9,14 +9,14 @@ //! verification. use std::{ - error::Error, + error, future::Future, pin::Pin, task::{Context, Poll}, }; use tower::{buffer::Buffer, Service}; -use zebra_chain::block::Block; +use zebra_chain::block::{Block, BlockHeaderHash}; mod script; mod transaction; @@ -29,17 +29,16 @@ mod transaction; struct BlockVerifier {} /// The result type for the BlockVerifier Service. -// TODO(teor): Response = BlockHeaderHash -type Response = (); +type Response = BlockHeaderHash; /// The error type for the BlockVerifier Service. // TODO(jlusby): Error = Report ? -type ServiceError = Box; +type Error = Box; /// The BlockVerifier service implementation. impl Service for BlockVerifier { type Response = Response; - type Error = ServiceError; + type Error = Error; type Future = Pin> + Send + 'static>>; @@ -52,13 +51,18 @@ impl Service for BlockVerifier { fn call(&mut self, block: Block) -> Self::Future { let mut state_service = zebra_state::in_memory::init(); - // Ignore errors, they are already handled correctly. - // AddBlock discards invalid blocks. + let header_hash: BlockHeaderHash = (&block).into(); + + // 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 { block: block.into(), }); - Box::pin(async { Ok(()) }) + Box::pin(async move { Ok(header_hash) }) } } @@ -66,8 +70,8 @@ impl Service for BlockVerifier { pub fn init() -> impl Service< Block, Response = Response, - Error = ServiceError, - Future = impl Future>, + Error = Error, + Future = impl Future>, > + Send + Clone + 'static {