@@ -603,80 +603,72 @@ impl RollupBoostServer {
603
603
payload_id : PayloadId ,
604
604
version : Version ,
605
605
) -> RpcResult < OpExecutionPayloadEnvelope > {
606
- let execution_mode = self . execution_mode ( ) ;
607
- let l2_client_future = self . l2_client . get_payload ( payload_id, version) ;
606
+ let l2_fut = self . l2_client . get_payload ( payload_id, version) ;
608
607
609
- // if mode is `disabled` dont await the builder payload
610
- let ( payload, context) = if execution_mode. is_disabled ( ) {
611
- let result = match l2_client_future. await {
608
+ // If execution mode is disabled, return the l2 payload without sending
609
+ // the request to the builder
610
+ if self . execution_mode ( ) . is_disabled ( ) {
611
+ return match l2_fut. await {
612
612
Ok ( payload) => {
613
613
self . probes . set_health ( Health :: Healthy ) ;
614
- Ok ( ( payload, PayloadSource :: L2 ) )
615
- }
616
- Err ( e) => {
617
- self . probes . set_health ( Health :: ServiceUnavailable ) ;
618
- Err ( e)
614
+ tracing:: Span :: current ( ) . record ( "payload_source" , "L2" ) ;
615
+ counter ! ( "rpc.blocks_created" , "source" => "L2" ) . increment ( 1 ) ;
616
+
617
+ let execution_payload = ExecutionPayload :: from ( payload. clone ( ) ) ;
618
+ info ! (
619
+ message = "returning block" ,
620
+ "hash" = %execution_payload. block_hash( ) ,
621
+ "number" = %execution_payload. block_number( ) ,
622
+ context = "L2" ,
623
+ %payload_id,
624
+ ) ;
625
+
626
+ Ok ( payload)
619
627
}
628
+
629
+ Err ( e) => Err ( e. into ( ) ) ,
620
630
} ;
621
- result
622
- } else {
623
- // if mode is `enabled` or `dry_run` await the builder + L2 payload
624
- let builder_client_future = Box :: pin ( async move {
625
- if let Some ( cause) = self . payload_trace_context . trace_id ( & payload_id) {
626
- tracing:: Span :: current ( ) . follows_from ( cause) ;
627
- }
631
+ }
628
632
629
- if !self . payload_trace_context . has_builder_payload ( & payload_id) {
630
- // block builder won't build a block without attributes
631
- info ! ( message = "builder has no payload, skipping get_payload call to builder" ) ;
632
- return RpcResult :: Ok ( None ) ;
633
- }
633
+ // Forward the get payload request to the builder
634
+ let builder_fut = async {
635
+ if let Some ( cause) = self . payload_trace_context . trace_id ( & payload_id) {
636
+ tracing:: Span :: current ( ) . follows_from ( cause) ;
637
+ }
638
+ if !self . payload_trace_context . has_builder_payload ( & payload_id) {
639
+ info ! ( message = "builder has no payload, skipping get_payload call to builder" ) ;
640
+ return RpcResult :: Ok ( None ) ;
641
+ }
634
642
635
- let builder = self . builder_client . clone ( ) ;
636
- let payload = builder. get_payload ( payload_id, version) . await ?;
643
+ // Get payload and validate with the local l2 client
644
+ let payload = self . builder_client . get_payload ( payload_id, version) . await ?;
645
+ let _ = self
646
+ . l2_client
647
+ . new_payload ( NewPayload :: from ( payload. clone ( ) ) )
648
+ . await ?;
637
649
638
- // Send the payload to the local execution engine with engine_newPayload to validate the block from the builder.
639
- // Otherwise, we do not want to risk the network to a halt since op-node will not be able to propose the block.
640
- // If validation fails, return the local block since that one has already been validated.
641
- let _ = self
642
- . l2_client
643
- . new_payload ( NewPayload :: from ( payload. clone ( ) ) )
644
- . await ?;
650
+ Ok ( Some ( payload) )
651
+ } ;
645
652
646
- Ok ( Some ( payload) )
647
- } ) ;
653
+ let ( l2_payload, builder_payload) = tokio:: join!( l2_fut, builder_fut) ;
648
654
649
- let ( l2_payload, builder_payload) =
650
- tokio:: join!( l2_client_future, builder_client_future) ;
651
- let result = match ( builder_payload, l2_payload, execution_mode. is_dry_run ( ) ) {
652
- ( Ok ( Some ( _) ) , Ok ( l2) , true ) => {
653
- // if builder and l2 is okay and `is_dry_run`, then always return L2 payload with signal `Healthy`
654
- self . probes . set_health ( Health :: Healthy ) ;
655
- Ok ( ( l2, PayloadSource :: L2 ) )
656
- }
657
- ( _, Ok ( l2) , true ) => {
658
- // if builder has failed/errored and l2 is okay and `is_dry_run`, then always return L2 payload, but signal `PartialContent`
659
- self . probes . set_health ( Health :: PartialContent ) ;
660
- Ok ( ( l2, PayloadSource :: L2 ) )
661
- }
662
- ( Ok ( Some ( builder) ) , Ok ( _) , false ) => {
663
- // if builder and L2 is okay and `is_dry_run` is false, then always return builder payload i.e. `Enabled` Mode with signal `Healthy`
664
- self . probes . set_health ( Health :: Healthy ) ;
665
- Ok ( ( builder, PayloadSource :: Builder ) )
666
- }
667
- ( _, Ok ( l2) , false ) => {
668
- // builder failed to return/errored and `l2_payload` is ok and `is_dry_run` is false, then always return L2 payload with signal `PartialContent`
669
- self . probes . set_health ( Health :: PartialContent ) ;
670
- Ok ( ( l2, PayloadSource :: L2 ) )
671
- }
672
- ( _, Err ( e) , _) => {
673
- // l2 failed to return a payload
674
- self . probes . set_health ( Health :: ServiceUnavailable ) ;
675
- Err ( e)
655
+ // Evaluate the builder and l2 response and select the final payload
656
+ let ( payload, context) = {
657
+ let l2_payload =
658
+ l2_payload. inspect_err ( |_| self . probes . set_health ( Health :: ServiceUnavailable ) ) ?;
659
+ self . probes . set_health ( Health :: Healthy ) ;
660
+
661
+ if let Ok ( Some ( payload) ) = builder_payload {
662
+ if self . execution_mode ( ) . is_dry_run ( ) {
663
+ ( l2_payload, PayloadSource :: L2 )
664
+ } else {
665
+ ( payload, PayloadSource :: Builder )
676
666
}
677
- } ;
678
- result
679
- } ?;
667
+ } else {
668
+ self . probes . set_health ( Health :: PartialContent ) ;
669
+ ( l2_payload, PayloadSource :: L2 )
670
+ }
671
+ } ;
680
672
681
673
tracing:: Span :: current ( ) . record ( "payload_source" , context. to_string ( ) ) ;
682
674
// To maintain backwards compatibility with old metrics, we need to record blocks built
0 commit comments