@@ -60,7 +60,6 @@ pub trait PayloadBuilder: Send + Sync + Clone {
60
60
pub struct BlockPayloadJobGenerator < Client , Builder > {
61
61
/// The client that can interact with the chain.
62
62
client : Client ,
63
-
64
63
/// The configuration for the job generator.
65
64
_config : BasicPayloadJobGeneratorConfig ,
66
65
/// The type responsible for building payloads.
@@ -399,7 +398,7 @@ mod tests {
399
398
use alloy_eips:: eip7685:: Requests ;
400
399
use alloy_primitives:: U256 ;
401
400
use rand:: thread_rng;
402
- use reth:: tasks:: TokioTaskExecutor ;
401
+ use reth:: tasks:: { TaskSpawner , TokioTaskExecutor } ;
403
402
use reth_chain_state:: ExecutedBlockWithTrieUpdates ;
404
403
use reth_node_api:: NodePrimitives ;
405
404
use reth_optimism_payload_builder:: payload:: OpPayloadBuilderAttributes ;
@@ -482,13 +481,15 @@ mod tests {
482
481
struct MockBuilder < N > {
483
482
events : Arc < Mutex < Vec < BlockEvent > > > ,
484
483
_marker : std:: marker:: PhantomData < N > ,
484
+ executor : TokioTaskExecutor ,
485
485
}
486
486
487
487
impl < N > MockBuilder < N > {
488
488
fn new ( ) -> Self {
489
489
Self {
490
490
events : Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ,
491
491
_marker : std:: marker:: PhantomData ,
492
+ executor : TokioTaskExecutor :: default ( ) ,
492
493
}
493
494
}
494
495
@@ -550,16 +551,23 @@ mod tests {
550
551
) {
551
552
self . new_event ( BlockEvent :: Started ) ;
552
553
553
- loop {
554
- if args. cancel . is_cancelled ( ) {
555
- self . new_event ( BlockEvent :: Cancelled ) ;
556
- let _ = tx. send ( Ok ( ( ) ) ) ;
557
- return ;
554
+ let events = self . events . clone ( ) ;
555
+
556
+ self . executor . spawn_blocking ( Box :: pin ( async move {
557
+ loop {
558
+ if args. cancel . is_cancelled ( ) {
559
+ // copy of new_events to resolve the problem with self-reference on spawn
560
+ let mut events = events. lock ( ) . unwrap ( ) ;
561
+ events. push ( BlockEvent :: Cancelled ) ;
562
+ let _ = tx. send ( Ok ( ( ) ) ) ;
563
+ return ;
564
+ }
565
+
566
+ // Small sleep to prevent tight loop
567
+ tokio:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
558
568
}
569
+ } ) ) ;
559
570
560
- // Small sleep to prevent tight loop
561
- std:: thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
562
- }
563
571
}
564
572
}
565
573
@@ -588,7 +596,6 @@ mod tests {
588
596
#[ tokio:: test]
589
597
async fn test_payload_generator ( ) -> eyre:: Result < ( ) > {
590
598
let mut rng = thread_rng ( ) ;
591
-
592
599
let client = MockEthProvider :: default ( ) ;
593
600
let config = BasicPayloadJobGeneratorConfig :: default ( ) ;
594
601
let builder = MockBuilder :: < OpPrimitives > :: new ( ) ;
0 commit comments