@@ -94,49 +94,32 @@ impl BlockQueue {
9494#[ derive( Debug ) ]
9595pub ( crate ) struct Request {
9696 hash : BlockHash ,
97- recipient : BlockRecipient ,
97+ recipient : oneshot :: Sender < Result < IndexedBlock , FetchBlockError > > ,
9898}
9999
100100impl Request {
101- fn new ( hash : BlockHash ) -> Self {
102- Self {
103- hash,
104- recipient : BlockRecipient :: Event ,
105- }
106- }
107-
108101 fn from_block_request (
109102 block_request : ClientRequest < BlockHash , Result < IndexedBlock , FetchBlockError > > ,
110103 ) -> Self {
111104 let ( hash, oneshot) = block_request. into_values ( ) ;
112105 Self {
113106 hash,
114- recipient : BlockRecipient :: Client ( oneshot) ,
107+ recipient : oneshot,
115108 }
116109 }
117110}
118111
119- impl From < BlockHash > for Request {
120- fn from ( value : BlockHash ) -> Self {
121- Request :: new ( value)
122- }
123- }
124-
125112impl From < ClientRequest < BlockHash , Result < IndexedBlock , FetchBlockError > > > for Request {
126113 fn from ( value : ClientRequest < BlockHash , Result < IndexedBlock , FetchBlockError > > ) -> Self {
127114 Request :: from_block_request ( value)
128115 }
129116}
130117
131- #[ derive( Debug ) ]
132- pub ( crate ) enum BlockRecipient {
133- Client ( oneshot:: Sender < Result < IndexedBlock , FetchBlockError > > ) ,
134- Event ,
135- }
136-
137118#[ derive( Debug ) ]
138119pub ( crate ) enum ProcessBlockResponse {
139- Accepted { block_recipient : BlockRecipient } ,
120+ Accepted {
121+ block_recipient : oneshot:: Sender < Result < IndexedBlock , FetchBlockError > > ,
122+ } ,
140123 LateResponse ,
141124 UnknownHash ,
142125}
@@ -161,14 +144,26 @@ mod test {
161144 [ hash_1, hash_2, hash_3]
162145 }
163146
147+ trait DummyRequestExt {
148+ fn dummy_request ( & self ) -> Request ;
149+ }
150+
151+ impl DummyRequestExt for BlockHash {
152+ fn dummy_request ( & self ) -> Request {
153+ let ( tx, _rx) = oneshot:: channel ( ) ;
154+ let client_request = ClientRequest :: new ( * self , tx) ;
155+ Request :: from_block_request ( client_request)
156+ }
157+ }
158+
164159 #[ test]
165160 fn test_block_queue ( ) {
166161 let [ hash_1, hash_2, hash_3] = three_block_hashes ( ) ;
167162 let mut queue = BlockQueue :: new ( ) ;
168- queue. add ( hash_1) ;
169- queue. add ( hash_2) ;
170- queue. add ( hash_3) ;
171- queue. add ( hash_1) ;
163+ queue. add ( hash_1. dummy_request ( ) ) ;
164+ queue. add ( hash_2. dummy_request ( ) ) ;
165+ queue. add ( hash_3. dummy_request ( ) ) ;
166+ queue. add ( hash_1. dummy_request ( ) ) ;
172167 assert_eq ! ( queue. queue. len( ) , 4 ) ;
173168 assert_eq ! ( queue. pop( ) , Some ( hash_1) ) ;
174169 assert_eq ! ( queue. pop( ) , None ) ;
@@ -201,9 +196,9 @@ mod test {
201196 async fn test_laggy_peer ( ) {
202197 let [ hash_1, hash_2, hash_3] = three_block_hashes ( ) ;
203198 let mut queue = BlockQueue :: new ( ) ;
204- queue. add ( hash_1) ;
205- queue. add ( hash_2) ;
206- queue. add ( hash_3) ;
199+ queue. add ( hash_1. dummy_request ( ) ) ;
200+ queue. add ( hash_2. dummy_request ( ) ) ;
201+ queue. add ( hash_3. dummy_request ( ) ) ;
207202 assert_eq ! ( queue. queue. len( ) , 3 ) ;
208203 assert_eq ! ( queue. pop( ) , Some ( hash_1) ) ;
209204 tokio:: time:: sleep ( Duration :: from_secs ( 6 ) ) . await ;
@@ -241,10 +236,10 @@ mod test {
241236 fn test_blocks_removed ( ) {
242237 let [ hash_1, hash_2, hash_3] = three_block_hashes ( ) ;
243238 let mut queue = BlockQueue :: new ( ) ;
244- queue. add ( hash_1) ;
245- queue. add ( hash_2) ;
246- queue. add ( hash_3) ;
247- queue. add ( hash_1) ;
239+ queue. add ( hash_1. dummy_request ( ) ) ;
240+ queue. add ( hash_2. dummy_request ( ) ) ;
241+ queue. add ( hash_3. dummy_request ( ) ) ;
242+ queue. add ( hash_1. dummy_request ( ) ) ;
248243 assert_eq ! ( queue. queue. len( ) , 4 ) ;
249244 assert_eq ! ( queue. pop( ) , Some ( hash_1) ) ;
250245 assert_eq ! (
0 commit comments