@@ -765,43 +765,58 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*beaco
765765 var bodies = make ([]* beacon.ExecutionPayloadBodyV1 , len (hashes ))
766766 for i , hash := range hashes {
767767 block := api .eth .BlockChain ().GetBlockByHash (hash )
768- bodies [i ] = getBody (block )
768+ bodies [i ] = api . getBody (block )
769769 }
770770 return bodies
771771}
772772
773773// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
774774// 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
786795}
787796
788- func getBody (block * types.Block ) * beacon.ExecutionPayloadBodyV1 {
797+ func ( api * ConsensusAPI ) getBody (block * types.Block ) * beacon.ExecutionPayloadBodyV1 {
789798 if block == nil {
790799 return nil
791800 }
792801
793802 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
796806 )
797807
798808 for j , tx := range body .Transactions {
799809 data , _ := tx .MarshalBinary ()
800810 txs [j ] = hexutil .Bytes (data )
801811 }
802812
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+
803818 return & beacon.ExecutionPayloadBodyV1 {
804819 TransactionData : txs ,
805- Withdrawals : body . Withdrawals ,
820+ Withdrawals : withdrawals ,
806821 }
807822}
0 commit comments