From ba75c14cfd21df86ea7a491f07be7988efa44ddd Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 8 Feb 2021 10:47:25 +1000 Subject: [PATCH] Use `ServiceExt::oneshot` in the checkpoint verifier And clean up the `std::future`/`futures` imports. --- zebra-consensus/src/checkpoint.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index f519a2c3648..2385a8f0ee5 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -15,19 +15,18 @@ use std::{ collections::{BTreeMap, HashSet}, - future::Future, ops::{Bound, Bound::*}, pin::Pin, sync::Arc, task::{Context, Poll}, }; -use futures_util::FutureExt; +use futures::{Future, FutureExt, TryFutureExt}; use thiserror::Error; use tokio::sync::oneshot; use tower::{Service, ServiceExt}; - use tracing::instrument; + use zebra_chain::{ block::{self, Block}, parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH}, @@ -881,7 +880,7 @@ where // commit-if-verified logic. This task will always execute, except if // the program is interrupted, in which case there is no longer a // checkpoint verifier to keep in sync with the state. - let mut state_service = self.state_service.clone(); + let state_service = self.state_service.clone(); let commit_finalized_block = tokio::spawn(async move { let hash = rx .await @@ -893,14 +892,10 @@ where // as a finalized block, or exit the program, so .expect rather than // propagate errors from the state service. match state_service - .ready_and() - .await + .oneshot(zs::Request::CommitFinalizedBlock(block.into())) .map_err(VerifyCheckpointError::CommitFinalized) - .expect("state service readiness failed: verified checkpoints must be committed transactionally") - .call(zs::Request::CommitFinalizedBlock(block.into())) .await - .map_err(VerifyCheckpointError::CommitFinalized) - .expect("state service request failed: verified checkpoints must be committed transactionally") + .expect("state service commit block failed: verified checkpoints must be committed transactionally") { zs::Response::Committed(committed_hash) => { assert_eq!(committed_hash, hash, "state must commit correct hash");