Skip to content

Commit

Permalink
Rename structs to remove module's name
Browse files Browse the repository at this point in the history
To follow this convention RFC: rust-lang/rfcs#356
  • Loading branch information
dconnolly committed Jul 7, 2020
1 parent cf809ee commit 01e9e8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions zebra-consensus/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
//! verification.
mod block;
mod redjubjub;
pub mod redjubjub;
mod script;
mod transaction;

pub use self::redjubjub::{RedJubjubItem, RedJubjubVerifier};
pub use block::init;
22 changes: 12 additions & 10 deletions zebra-consensus/src/verify/redjubjub.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Async RedJubjub batch verifier service
use std::{
future::Future,
mem,
Expand All @@ -6,13 +8,13 @@ use std::{
};

use rand::thread_rng;
use redjubjub::*;
use redjubjub::{batch, *};
use tokio::sync::broadcast::{channel, RecvError, Sender};
use tower::Service;
use tower_batch::BatchControl;

/// RedJubjub signature verifier service
pub struct RedJubjubVerifier {
pub struct Verifier {
batch: batch::Verifier,
// This uses a "broadcast" channel, which is an mpmc channel. Tokio also
// provides a spmc channel, "watch", but it only keeps the latest value, so
Expand All @@ -22,7 +24,7 @@ pub struct RedJubjubVerifier {
}

#[allow(clippy::new_without_default)]
impl RedJubjubVerifier {
impl Verifier {
/// Create a new RedJubjubVerifier instance
pub fn new() -> Self {
let batch = batch::Verifier::default();
Expand All @@ -33,9 +35,9 @@ impl RedJubjubVerifier {
}

/// Type alias to clarify that this batch::Item is a RedJubjubItem
pub type RedJubjubItem = batch::Item;
pub type Item = batch::Item;

impl Service<BatchControl<RedJubjubItem>> for RedJubjubVerifier {
impl Service<BatchControl<Item>> for Verifier {
type Response = ();
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'static>>;
Expand All @@ -44,7 +46,7 @@ impl Service<BatchControl<RedJubjubItem>> for RedJubjubVerifier {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: BatchControl<RedJubjubItem>) -> Self::Future {
fn call(&mut self, req: BatchControl<Item>) -> Self::Future {
match req {
BatchControl::Item(item) => {
tracing::trace!("got item");
Expand Down Expand Up @@ -74,7 +76,7 @@ impl Service<BatchControl<RedJubjubItem>> for RedJubjubVerifier {
}
}

impl Drop for RedJubjubVerifier {
impl Drop for Verifier {
fn drop(&mut self) {
// We need to flush the current batch in case there are still any pending futures.
let batch = mem::take(&mut self.batch);
Expand All @@ -95,7 +97,7 @@ mod tests {

async fn sign_and_verify<V>(mut verifier: V, n: usize) -> Result<(), V::Error>
where
V: Service<RedJubjubItem, Response = ()>,
V: Service<Item, Response = ()>,
{
let rng = thread_rng();
let mut results = FuturesUnordered::new();
Expand Down Expand Up @@ -136,7 +138,7 @@ mod tests {

// Use a very long max_latency and a short timeout to check that
// flushing is happening based on hitting max_items.
let verifier = Batch::new(RedJubjubVerifier::new(), 10, Duration::from_secs(1000));
let verifier = Batch::new(Verifier::new(), 10, Duration::from_secs(1000));
timeout(Duration::from_secs(5), sign_and_verify(verifier, 100)).await?
}

Expand All @@ -147,7 +149,7 @@ mod tests {

// Use a very high max_items and a short timeout to check that
// flushing is happening based on hitting max_latency.
let verifier = Batch::new(RedJubjubVerifier::new(), 100, Duration::from_millis(500));
let verifier = Batch::new(Verifier::new(), 100, Duration::from_millis(500));
timeout(Duration::from_secs(5), sign_and_verify(verifier, 10)).await?
}
}

0 comments on commit 01e9e8a

Please sign in to comment.