1
+ //! Async RedJubjub batch verifier service
2
+
1
3
use std:: {
2
4
future:: Future ,
3
5
mem,
@@ -6,13 +8,13 @@ use std::{
6
8
} ;
7
9
8
10
use rand:: thread_rng;
9
- use redjubjub:: * ;
11
+ use redjubjub:: { batch , * } ;
10
12
use tokio:: sync:: broadcast:: { channel, RecvError , Sender } ;
11
13
use tower:: Service ;
12
14
use tower_batch:: BatchControl ;
13
15
14
16
/// RedJubjub signature verifier service
15
- pub struct RedJubjubVerifier {
17
+ pub struct Verifier {
16
18
batch : batch:: Verifier ,
17
19
// This uses a "broadcast" channel, which is an mpmc channel. Tokio also
18
20
// provides a spmc channel, "watch", but it only keeps the latest value, so
@@ -22,7 +24,7 @@ pub struct RedJubjubVerifier {
22
24
}
23
25
24
26
#[ allow( clippy:: new_without_default) ]
25
- impl RedJubjubVerifier {
27
+ impl Verifier {
26
28
/// Create a new RedJubjubVerifier instance
27
29
pub fn new ( ) -> Self {
28
30
let batch = batch:: Verifier :: default ( ) ;
@@ -33,9 +35,9 @@ impl RedJubjubVerifier {
33
35
}
34
36
35
37
/// Type alias to clarify that this batch::Item is a RedJubjubItem
36
- pub type RedJubjubItem = batch:: Item ;
38
+ pub type Item = batch:: Item ;
37
39
38
- impl Service < BatchControl < RedJubjubItem > > for RedJubjubVerifier {
40
+ impl Service < BatchControl < Item > > for Verifier {
39
41
type Response = ( ) ;
40
42
type Error = Error ;
41
43
type Future = Pin < Box < dyn Future < Output = Result < ( ) , Error > > + Send + ' static > > ;
@@ -44,7 +46,7 @@ impl Service<BatchControl<RedJubjubItem>> for RedJubjubVerifier {
44
46
Poll :: Ready ( Ok ( ( ) ) )
45
47
}
46
48
47
- fn call ( & mut self , req : BatchControl < RedJubjubItem > ) -> Self :: Future {
49
+ fn call ( & mut self , req : BatchControl < Item > ) -> Self :: Future {
48
50
match req {
49
51
BatchControl :: Item ( item) => {
50
52
tracing:: trace!( "got item" ) ;
@@ -74,7 +76,7 @@ impl Service<BatchControl<RedJubjubItem>> for RedJubjubVerifier {
74
76
}
75
77
}
76
78
77
- impl Drop for RedJubjubVerifier {
79
+ impl Drop for Verifier {
78
80
fn drop ( & mut self ) {
79
81
// We need to flush the current batch in case there are still any pending futures.
80
82
let batch = mem:: take ( & mut self . batch ) ;
@@ -95,7 +97,7 @@ mod tests {
95
97
96
98
async fn sign_and_verify < V > ( mut verifier : V , n : usize ) -> Result < ( ) , V :: Error >
97
99
where
98
- V : Service < RedJubjubItem , Response = ( ) > ,
100
+ V : Service < Item , Response = ( ) > ,
99
101
{
100
102
let rng = thread_rng ( ) ;
101
103
let mut results = FuturesUnordered :: new ( ) ;
@@ -136,7 +138,7 @@ mod tests {
136
138
137
139
// Use a very long max_latency and a short timeout to check that
138
140
// flushing is happening based on hitting max_items.
139
- let verifier = Batch :: new ( RedJubjubVerifier :: new ( ) , 10 , Duration :: from_secs ( 1000 ) ) ;
141
+ let verifier = Batch :: new ( Verifier :: new ( ) , 10 , Duration :: from_secs ( 1000 ) ) ;
140
142
timeout ( Duration :: from_secs ( 5 ) , sign_and_verify ( verifier, 100 ) ) . await ?
141
143
}
142
144
@@ -147,7 +149,7 @@ mod tests {
147
149
148
150
// Use a very high max_items and a short timeout to check that
149
151
// flushing is happening based on hitting max_latency.
150
- let verifier = Batch :: new ( RedJubjubVerifier :: new ( ) , 100 , Duration :: from_millis ( 500 ) ) ;
152
+ let verifier = Batch :: new ( Verifier :: new ( ) , 100 , Duration :: from_millis ( 500 ) ) ;
151
153
timeout ( Duration :: from_secs ( 5 ) , sign_and_verify ( verifier, 10 ) ) . await ?
152
154
}
153
155
}
0 commit comments