@@ -47,10 +47,6 @@ enum RequestState<E: EthSpec> {
4747 Sent ( HashMap < Hash256 , Arc < BlockResult < E > > > ) ,
4848}
4949
50- struct BodiesByHash < E : EthSpec > {
51- hashes : Option < Vec < ExecutionBlockHash > > ,
52- state : RequestState < E > ,
53- }
5450struct BodiesByRange < E : EthSpec > {
5551 start : u64 ,
5652 count : u64 ,
@@ -179,109 +175,6 @@ fn reconstruct_blocks<E: EthSpec>(
179175 }
180176}
181177
182- impl < E : EthSpec > BodiesByHash < E > {
183- pub fn new ( maybe_block_parts : Option < BlockParts < E > > ) -> Self {
184- if let Some ( block_parts) = maybe_block_parts {
185- Self {
186- hashes : Some ( vec ! [ block_parts. block_hash( ) ] ) ,
187- state : RequestState :: UnSent ( vec ! [ block_parts] ) ,
188- }
189- } else {
190- Self {
191- hashes : None ,
192- state : RequestState :: UnSent ( vec ! [ ] ) ,
193- }
194- }
195- }
196-
197- pub fn is_unsent ( & self ) -> bool {
198- matches ! ( self . state, RequestState :: UnSent ( _) )
199- }
200-
201- pub fn push_block_parts ( & mut self , block_parts : BlockParts < E > ) -> Result < ( ) , BlockParts < E > > {
202- if self
203- . hashes
204- . as_ref ( )
205- . map_or ( false , |hashes| hashes. len ( ) == 32 )
206- {
207- // this request is full
208- return Err ( block_parts) ;
209- }
210- match & mut self . state {
211- RequestState :: Sent ( _) => Err ( block_parts) ,
212- RequestState :: UnSent ( blocks_parts_vec) => {
213- self . hashes
214- . get_or_insert ( vec ! [ ] )
215- . push ( block_parts. block_hash ( ) ) ;
216- blocks_parts_vec. push ( block_parts) ;
217-
218- Ok ( ( ) )
219- }
220- }
221- }
222-
223- async fn execute ( & mut self , execution_layer : & ExecutionLayer < E > , log : & Logger ) {
224- if let RequestState :: UnSent ( block_parts_ref) = & mut self . state {
225- if let Some ( hashes) = self . hashes . take ( ) {
226- let block_parts_vec = std:: mem:: take ( block_parts_ref) ;
227- let mut block_map = HashMap :: new ( ) ;
228- match execution_layer
229- . get_payload_bodies_by_hash ( hashes. clone ( ) )
230- . await
231- {
232- Ok ( bodies) => {
233- let mut body_map = hashes
234- . into_iter ( )
235- . zip ( bodies. into_iter ( ) . chain ( std:: iter:: repeat ( None ) ) )
236- . collect :: < HashMap < _ , _ > > ( ) ;
237-
238- let mut with_bodies = HashMap :: new ( ) ;
239- for mut block_parts in block_parts_vec {
240- with_bodies
241- // it's possible the same block is requested twice, using
242- // or_insert_with() skips duplicates
243- . entry ( block_parts. root ( ) )
244- . or_insert_with ( || {
245- block_parts. body = body_map
246- . remove ( & block_parts. block_hash ( ) )
247- . flatten ( )
248- . map ( Box :: new) ;
249-
250- block_parts
251- } ) ;
252- }
253-
254- reconstruct_blocks ( & mut block_map, with_bodies, log) ;
255- }
256- Err ( e) => {
257- let block_result =
258- Arc :: new ( Err ( Error :: BlocksByHashFailure ( Box :: new ( e) ) . into ( ) ) ) ;
259- debug ! ( log, "Payload bodies by hash failure" ; "error" => ?block_result) ;
260- for block_parts in block_parts_vec {
261- block_map. insert ( block_parts. root ( ) , block_result. clone ( ) ) ;
262- }
263- }
264- }
265- self . state = RequestState :: Sent ( block_map) ;
266- }
267- }
268- }
269-
270- pub async fn get_block_result (
271- & mut self ,
272- root : & Hash256 ,
273- execution_layer : & ExecutionLayer < E > ,
274- log : & Logger ,
275- ) -> Option < Arc < BlockResult < E > > > {
276- self . execute ( execution_layer, log) . await ;
277- if let RequestState :: Sent ( map) = & self . state {
278- return map. get ( root) . cloned ( ) ;
279- }
280- // Shouldn't reach this point
281- None
282- }
283- }
284-
285178impl < E : EthSpec > BodiesByRange < E > {
286179 pub fn new ( maybe_block_parts : Option < BlockParts < E > > ) -> Self {
287180 if let Some ( block_parts) = maybe_block_parts {
@@ -398,16 +291,12 @@ impl<E: EthSpec> BodiesByRange<E> {
398291
399292#[ derive( Clone ) ]
400293enum EngineRequest < E : EthSpec > {
401- ByHash ( Arc < RwLock < BodiesByHash < E > > > ) ,
402294 ByRange ( Arc < RwLock < BodiesByRange < E > > > ) ,
403295 // When we already have the data or there's an error
404296 NoRequest ( Arc < RwLock < HashMap < Hash256 , Arc < BlockResult < E > > > > > ) ,
405297}
406298
407299impl < E : EthSpec > EngineRequest < E > {
408- pub fn new_by_hash ( ) -> Self {
409- Self :: ByHash ( Arc :: new ( RwLock :: new ( BodiesByHash :: new ( None ) ) ) )
410- }
411300 pub fn new_by_range ( ) -> Self {
412301 Self :: ByRange ( Arc :: new ( RwLock :: new ( BodiesByRange :: new ( None ) ) ) )
413302 }
@@ -417,22 +306,13 @@ impl<E: EthSpec> EngineRequest<E> {
417306
418307 pub async fn is_unsent ( & self ) -> bool {
419308 match self {
420- Self :: ByHash ( bodies_by_hash) => bodies_by_hash. read ( ) . await . is_unsent ( ) ,
421309 Self :: ByRange ( bodies_by_range) => bodies_by_range. read ( ) . await . is_unsent ( ) ,
422310 Self :: NoRequest ( _) => false ,
423311 }
424312 }
425313
426314 pub async fn push_block_parts ( & mut self , block_parts : BlockParts < E > , log : & Logger ) {
427315 match self {
428- Self :: ByHash ( bodies_by_hash) => {
429- let mut request = bodies_by_hash. write ( ) . await ;
430- if let Err ( block_parts) = request. push_block_parts ( block_parts) {
431- drop ( request) ;
432- let new_by_hash = BodiesByHash :: new ( Some ( block_parts) ) ;
433- * self = Self :: ByHash ( Arc :: new ( RwLock :: new ( new_by_hash) ) ) ;
434- }
435- }
436316 Self :: ByRange ( bodies_by_range) => {
437317 let mut request = bodies_by_range. write ( ) . await ;
438318
@@ -469,14 +349,6 @@ impl<E: EthSpec> EngineRequest<E> {
469349 "beacon_block_streamer" => "push_block_result called on ByRange" ,
470350 ) ;
471351 }
472- Self :: ByHash ( _) => {
473- // this should _never_ happen
474- crit ! (
475- log,
476- "Please notify the devs" ;
477- "beacon_block_streamer" => "push_block_result called on ByHash" ,
478- ) ;
479- }
480352 Self :: NoRequest ( results) => {
481353 results. write ( ) . await . insert ( root, Arc :: new ( block_result) ) ;
482354 }
@@ -497,13 +369,6 @@ impl<E: EthSpec> EngineRequest<E> {
497369 . get_block_result ( root, execution_layer, log)
498370 . await
499371 }
500- Self :: ByHash ( by_hash) => {
501- by_hash
502- . write ( )
503- . await
504- . get_block_result ( root, execution_layer, log)
505- . await
506- }
507372 Self :: NoRequest ( map) => map. read ( ) . await . get ( root) . cloned ( ) ,
508373 }
509374 . unwrap_or_else ( || {
0 commit comments