Skip to content

Commit

Permalink
consensus: Make BlockVerifier respond with the BlockHeaderHash
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jun 11, 2020
1 parent b9449b3 commit 9e1f5f5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions zebra-consensus/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<dyn Error + Send + Sync + 'static>;
type Error = Box<dyn error::Error + Send + Sync + 'static>;

/// The BlockVerifier service implementation.
impl Service<Block> for BlockVerifier {
type Response = Response;
type Error = ServiceError;
type Error = Error;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

Expand All @@ -52,22 +51,27 @@ impl Service<Block> 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) })
}
}

/// Initialise the BlockVerifier service.
pub fn init() -> impl Service<
Block,
Response = Response,
Error = ServiceError,
Future = impl Future<Output = Result<Response, ServiceError>>,
Error = Error,
Future = impl Future<Output = Result<Response, Error>>,
> + Send
+ Clone
+ 'static {
Expand Down

0 comments on commit 9e1f5f5

Please sign in to comment.