Skip to content

Commit

Permalink
Use ServiceExt::oneshot in the checkpoint verifier
Browse files Browse the repository at this point in the history
And clean up the `std::future`/`futures` imports.
  • Loading branch information
teor2345 committed Feb 8, 2021
1 parent 1c8c435 commit ba75c14
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions zebra-consensus/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand Down

0 comments on commit ba75c14

Please sign in to comment.