11use crate :: client:: auth:: { AuthClientLayer , AuthClientService } ;
22use crate :: debug_api:: DebugClient ;
3- use crate :: server:: EngineApiClient ;
4- use crate :: server:: PayloadSource ;
3+ use crate :: server:: { EngineApiClient , OpExecutionPayloadEnvelope , Version } ;
4+ use crate :: server:: { NewPayload , PayloadSource } ;
55use alloy_eips:: BlockNumberOrTag ;
6- use alloy_primitives:: B256 ;
7- use alloy_rpc_types_engine:: JwtSecret ;
6+ use alloy_eips:: eip2718:: Encodable2718 ;
7+ use alloy_primitives:: { B256 , Bytes , TxKind , U256 , address, hex} ;
8+ use alloy_rpc_types_engine:: { ExecutionPayload , JwtSecret } ;
89use alloy_rpc_types_engine:: {
9- ExecutionPayloadV3 , ForkchoiceState , ForkchoiceUpdated , PayloadAttributes , PayloadId ,
10- PayloadStatus , PayloadStatusEnum ,
10+ ForkchoiceState , ForkchoiceUpdated , PayloadAttributes , PayloadId , PayloadStatus ,
11+ PayloadStatusEnum ,
1112} ;
13+ use bytes:: BytesMut ;
1214use jsonrpsee:: http_client:: { HttpClient , transport:: HttpBackend } ;
1315use jsonrpsee:: proc_macros:: rpc;
1416use lazy_static:: lazy_static;
15- use op_alloy_rpc_types_engine:: { OpExecutionPayloadEnvelopeV3 , OpPayloadAttributes } ;
17+ use op_alloy_consensus:: TxDeposit ;
18+ use op_alloy_rpc_types_engine:: OpPayloadAttributes ;
1619use proxy:: { DynHandlerFn , start_proxy_server} ;
1720use serde_json:: Value ;
1821use std:: collections:: { HashMap , HashSet } ;
@@ -469,6 +472,7 @@ pub struct EngineApi {
469472 pub engine_api_client : HttpClient < AuthClientService < HttpBackend > > ,
470473}
471474
475+ // TODO: Use client/rpc.rs instead
472476impl EngineApi {
473477 pub fn new ( url : & str , secret : & str ) -> Result < Self , Box < dyn std:: error:: Error > > {
474478 let secret_layer = AuthClientLayer :: new ( JwtSecret :: from_str ( secret) ?) ;
@@ -483,26 +487,39 @@ impl EngineApi {
483487 } )
484488 }
485489
486- pub async fn get_payload_v3 (
490+ pub async fn get_payload (
487491 & self ,
492+ version : Version ,
488493 payload_id : PayloadId ,
489- ) -> eyre:: Result < OpExecutionPayloadEnvelopeV3 > {
490- Ok ( EngineApiClient :: get_payload_v3 ( & self . engine_api_client , payload_id) . await ?)
494+ ) -> eyre:: Result < OpExecutionPayloadEnvelope > {
495+ match version {
496+ Version :: V3 => Ok ( OpExecutionPayloadEnvelope :: V3 (
497+ EngineApiClient :: get_payload_v3 ( & self . engine_api_client , payload_id) . await ?,
498+ ) ) ,
499+ Version :: V4 => Ok ( OpExecutionPayloadEnvelope :: V4 (
500+ EngineApiClient :: get_payload_v4 ( & self . engine_api_client , payload_id) . await ?,
501+ ) ) ,
502+ }
491503 }
492504
493- pub async fn new_payload (
494- & self ,
495- payload : ExecutionPayloadV3 ,
496- versioned_hashes : Vec < B256 > ,
497- parent_beacon_block_root : B256 ,
498- ) -> eyre:: Result < PayloadStatus > {
499- Ok ( EngineApiClient :: new_payload_v3 (
500- & self . engine_api_client ,
501- payload,
502- versioned_hashes,
503- parent_beacon_block_root,
504- )
505- . await ?)
505+ pub async fn new_payload ( & self , payload : NewPayload ) -> eyre:: Result < PayloadStatus > {
506+ match payload {
507+ NewPayload :: V3 ( new_payload) => Ok ( EngineApiClient :: new_payload_v3 (
508+ & self . engine_api_client ,
509+ new_payload. payload ,
510+ new_payload. versioned_hashes ,
511+ new_payload. parent_beacon_block_root ,
512+ )
513+ . await ?) ,
514+ NewPayload :: V4 ( new_payload) => Ok ( EngineApiClient :: new_payload_v4 (
515+ & self . engine_api_client ,
516+ new_payload. payload ,
517+ new_payload. versioned_hashes ,
518+ new_payload. parent_beacon_block_root ,
519+ new_payload. execution_requests ,
520+ )
521+ . await ?) ,
522+ }
506523 }
507524
508525 pub async fn update_forkchoice (
@@ -686,6 +703,7 @@ pub struct SimpleBlockGenerator {
686703 engine_api : EngineApi ,
687704 latest_hash : B256 ,
688705 timestamp : u64 ,
706+ version : Version ,
689707}
690708
691709impl SimpleBlockGenerator {
@@ -695,6 +713,7 @@ impl SimpleBlockGenerator {
695713 engine_api,
696714 latest_hash : B256 :: ZERO , // temporary value
697715 timestamp : 0 , // temporary value
716+ version : Version :: V3 ,
698717 }
699718 }
700719
@@ -711,6 +730,14 @@ impl SimpleBlockGenerator {
711730 & mut self ,
712731 empty_blocks : bool ,
713732 ) -> eyre:: Result < ( B256 , PayloadSource ) > {
733+ let txns = match self . version {
734+ Version :: V4 => {
735+ let tx = create_deposit_tx ( ) ;
736+ Some ( vec ! [ tx] )
737+ }
738+ _ => None ,
739+ } ;
740+
714741 // Submit forkchoice update with payload attributes for the next block
715742 let result = self
716743 . engine_api
@@ -725,7 +752,7 @@ impl SimpleBlockGenerator {
725752 prev_randao : B256 :: ZERO ,
726753 suggested_fee_recipient : Default :: default ( ) ,
727754 } ,
728- transactions : None ,
755+ transactions : txns ,
729756 no_tx_pool : Some ( empty_blocks) ,
730757 gas_limit : Some ( 10000000000 ) ,
731758 eip_1559_params : None ,
@@ -739,23 +766,23 @@ impl SimpleBlockGenerator {
739766 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 1 ) ) . await ;
740767 }
741768
742- let payload = self . engine_api . get_payload_v3 ( payload_id) . await ?;
769+ let payload = self
770+ . engine_api
771+ . get_payload ( self . version , payload_id)
772+ . await ?;
743773
744774 // Submit the new payload to the node
745775 let validation_status = self
746776 . engine_api
747- . new_payload ( payload. execution_payload . clone ( ) , vec ! [ ] , B256 :: ZERO )
777+ . new_payload ( NewPayload :: from ( payload. clone ( ) ) )
748778 . await ?;
749779
750780 if validation_status. status != PayloadStatusEnum :: Valid {
751781 return Err ( eyre:: eyre!( "Invalid payload status" ) ) ;
752782 }
753783
754- let new_block_hash = payload
755- . execution_payload
756- . payload_inner
757- . payload_inner
758- . block_hash ;
784+ let execution_payload = ExecutionPayload :: from ( payload) ;
785+ let new_block_hash = execution_payload. block_hash ( ) ;
759786
760787 // Update the chain's head
761788 self . engine_api
@@ -764,11 +791,7 @@ impl SimpleBlockGenerator {
764791
765792 // Update internal state
766793 self . latest_hash = new_block_hash;
767- self . timestamp = payload
768- . execution_payload
769- . payload_inner
770- . payload_inner
771- . timestamp ;
794+ self . timestamp = execution_payload. timestamp ( ) ;
772795
773796 // Check who built the block in the rollup-boost logs
774797 let block_creator = self
@@ -826,3 +849,25 @@ impl BlockBuilderCreatorValidator {
826849 Ok ( None )
827850 }
828851}
852+
853+ fn create_deposit_tx ( ) -> Bytes {
854+ const ISTHMUS_DATA : & [ u8 ] = & hex ! (
855+ "098999be00000558000c5fc500000000000000030000000067a9f765000000000000002900000000000000000000000000000000000000000000000000000000006a6d09000000000000000000000000000000000000000000000000000000000000000172fcc8e8886636bdbe96ba0e4baab67ea7e7811633f52b52e8cf7a5123213b6f000000000000000000000000d3f2c5afb2d76f5579f326b0cd7da5f5a4126c3500004e2000000000000001f4"
856+ ) ;
857+
858+ let deposit_tx = TxDeposit {
859+ source_hash : B256 :: default ( ) ,
860+ from : address ! ( "DeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001" ) ,
861+ to : TxKind :: Call ( address ! ( "4200000000000000000000000000000000000015" ) ) ,
862+ mint : None ,
863+ value : U256 :: default ( ) ,
864+ gas_limit : 210000 ,
865+ is_system_transaction : true ,
866+ input : ISTHMUS_DATA . into ( ) ,
867+ } ;
868+
869+ let mut buffer_without_header = BytesMut :: new ( ) ;
870+ deposit_tx. encode_2718 ( & mut buffer_without_header) ;
871+
872+ buffer_without_header. to_vec ( ) . into ( )
873+ }
0 commit comments