1
1
use crate :: client:: auth:: { AuthClientLayer , AuthClientService } ;
2
2
use 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 } ;
5
5
use 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 } ;
8
9
use alloy_rpc_types_engine:: {
9
- ExecutionPayloadV3 , ForkchoiceState , ForkchoiceUpdated , PayloadAttributes , PayloadId ,
10
- PayloadStatus , PayloadStatusEnum ,
10
+ ForkchoiceState , ForkchoiceUpdated , PayloadAttributes , PayloadId , PayloadStatus ,
11
+ PayloadStatusEnum ,
11
12
} ;
13
+ use bytes:: BytesMut ;
12
14
use jsonrpsee:: http_client:: { HttpClient , transport:: HttpBackend } ;
13
15
use jsonrpsee:: proc_macros:: rpc;
14
16
use 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 ;
16
19
use proxy:: { DynHandlerFn , start_proxy_server} ;
17
20
use serde_json:: Value ;
18
21
use std:: collections:: { HashMap , HashSet } ;
@@ -469,6 +472,7 @@ pub struct EngineApi {
469
472
pub engine_api_client : HttpClient < AuthClientService < HttpBackend > > ,
470
473
}
471
474
475
+ // TODO: Use client/rpc.rs instead
472
476
impl EngineApi {
473
477
pub fn new ( url : & str , secret : & str ) -> Result < Self , Box < dyn std:: error:: Error > > {
474
478
let secret_layer = AuthClientLayer :: new ( JwtSecret :: from_str ( secret) ?) ;
@@ -483,26 +487,39 @@ impl EngineApi {
483
487
} )
484
488
}
485
489
486
- pub async fn get_payload_v3 (
490
+ pub async fn get_payload (
487
491
& self ,
492
+ version : Version ,
488
493
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
+ }
491
503
}
492
504
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
+ }
506
523
}
507
524
508
525
pub async fn update_forkchoice (
@@ -686,6 +703,7 @@ pub struct SimpleBlockGenerator {
686
703
engine_api : EngineApi ,
687
704
latest_hash : B256 ,
688
705
timestamp : u64 ,
706
+ version : Version ,
689
707
}
690
708
691
709
impl SimpleBlockGenerator {
@@ -695,6 +713,7 @@ impl SimpleBlockGenerator {
695
713
engine_api,
696
714
latest_hash : B256 :: ZERO , // temporary value
697
715
timestamp : 0 , // temporary value
716
+ version : Version :: V3 ,
698
717
}
699
718
}
700
719
@@ -711,6 +730,14 @@ impl SimpleBlockGenerator {
711
730
& mut self ,
712
731
empty_blocks : bool ,
713
732
) -> 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
+
714
741
// Submit forkchoice update with payload attributes for the next block
715
742
let result = self
716
743
. engine_api
@@ -725,7 +752,7 @@ impl SimpleBlockGenerator {
725
752
prev_randao : B256 :: ZERO ,
726
753
suggested_fee_recipient : Default :: default ( ) ,
727
754
} ,
728
- transactions : None ,
755
+ transactions : txns ,
729
756
no_tx_pool : Some ( empty_blocks) ,
730
757
gas_limit : Some ( 10000000000 ) ,
731
758
eip_1559_params : None ,
@@ -739,23 +766,23 @@ impl SimpleBlockGenerator {
739
766
tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 1 ) ) . await ;
740
767
}
741
768
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 ?;
743
773
744
774
// Submit the new payload to the node
745
775
let validation_status = self
746
776
. engine_api
747
- . new_payload ( payload. execution_payload . clone ( ) , vec ! [ ] , B256 :: ZERO )
777
+ . new_payload ( NewPayload :: from ( payload. clone ( ) ) )
748
778
. await ?;
749
779
750
780
if validation_status. status != PayloadStatusEnum :: Valid {
751
781
return Err ( eyre:: eyre!( "Invalid payload status" ) ) ;
752
782
}
753
783
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 ( ) ;
759
786
760
787
// Update the chain's head
761
788
self . engine_api
@@ -764,11 +791,7 @@ impl SimpleBlockGenerator {
764
791
765
792
// Update internal state
766
793
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 ( ) ;
772
795
773
796
// Check who built the block in the rollup-boost logs
774
797
let block_creator = self
@@ -826,3 +849,25 @@ impl BlockBuilderCreatorValidator {
826
849
Ok ( None )
827
850
}
828
851
}
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