@@ -765,43 +765,58 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*beaco
765
765
var bodies = make ([]* beacon.ExecutionPayloadBodyV1 , len (hashes ))
766
766
for i , hash := range hashes {
767
767
block := api .eth .BlockChain ().GetBlockByHash (hash )
768
- bodies [i ] = getBody (block )
768
+ bodies [i ] = api . getBody (block )
769
769
}
770
770
return bodies
771
771
}
772
772
773
773
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
774
774
// of block bodies by the engine api.
775
- func (api * ConsensusAPI ) GetPayloadBodiesByRangeV1 (start , count uint64 ) []* beacon.ExecutionPayloadBodyV1 {
776
- if api .eth .BlockChain ().CurrentBlock ().NumberU64 () < start {
777
- // Return [] if the requested range is past our latest block
778
- return []* beacon.ExecutionPayloadBodyV1 {}
779
- }
780
- bodies := make ([]* beacon.ExecutionPayloadBodyV1 , count )
781
- for i := uint64 (0 ); i < count ; i ++ {
782
- block := api .eth .BlockChain ().GetBlockByNumber (start + i )
783
- bodies [i ] = getBody (block )
784
- }
785
- return bodies
775
+ func (api * ConsensusAPI ) GetPayloadBodiesByRangeV1 (start , count uint64 ) ([]* beacon.ExecutionPayloadBodyV1 , error ) {
776
+ if start == 0 || count == 0 || count > 1024 {
777
+ return nil , beacon .InvalidParams .With (fmt .Errorf ("invalid start or count, start: %v count: %v" , start , count ))
778
+ }
779
+ current := api .eth .BlockChain ().CurrentBlock ().NumberU64 ()
780
+ // Return [] if the requested range is past our latest block
781
+ if current < start {
782
+ return []* beacon.ExecutionPayloadBodyV1 {}, nil
783
+ }
784
+ // limit count up until current
785
+ end := start + count
786
+ if end > current {
787
+ end = current
788
+ }
789
+ var bodies []* beacon.ExecutionPayloadBodyV1
790
+ for i := uint64 (start ); i < end ; i ++ {
791
+ block := api .eth .BlockChain ().GetBlockByNumber (i )
792
+ bodies = append (bodies , api .getBody (block ))
793
+ }
794
+ return bodies , nil
786
795
}
787
796
788
- func getBody (block * types.Block ) * beacon.ExecutionPayloadBodyV1 {
797
+ func ( api * ConsensusAPI ) getBody (block * types.Block ) * beacon.ExecutionPayloadBodyV1 {
789
798
if block == nil {
790
799
return nil
791
800
}
792
801
793
802
var (
794
- body = block .Body ()
795
- txs = make ([]hexutil.Bytes , len (body .Transactions ))
803
+ body = block .Body ()
804
+ txs = make ([]hexutil.Bytes , len (body .Transactions ))
805
+ withdrawals = body .Withdrawals
796
806
)
797
807
798
808
for j , tx := range body .Transactions {
799
809
data , _ := tx .MarshalBinary ()
800
810
txs [j ] = hexutil .Bytes (data )
801
811
}
802
812
813
+ // Post-shanghai withdrawals MUST be set to empty slice instead of nil
814
+ if withdrawals == nil && api .eth .APIBackend .ChainConfig ().IsShanghai (block .Time ()) {
815
+ withdrawals = make ([]* types.Withdrawal , 0 )
816
+ }
817
+
803
818
return & beacon.ExecutionPayloadBodyV1 {
804
819
TransactionData : txs ,
805
- Withdrawals : body . Withdrawals ,
820
+ Withdrawals : withdrawals ,
806
821
}
807
822
}
0 commit comments