@@ -15,9 +15,11 @@ import (
1515 "github.com/prysmaticlabs/prysm/v3/config/params"
1616 consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
1717 "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
18+ payloadattribute "github.com/prysmaticlabs/prysm/v3/consensus-types/payload-attribute"
1819 types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
1920 "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
2021 enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
22+ "github.com/prysmaticlabs/prysm/v3/runtime/version"
2123 "github.com/prysmaticlabs/prysm/v3/time/slots"
2224 "github.com/sirupsen/logrus"
2325 "go.opencensus.io/trace"
@@ -67,10 +69,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *notifyForkcho
6769 }
6870
6971 nextSlot := s .CurrentSlot () + 1 // Cache payload ID for next slot proposer.
70- hasAttr , attr , proposerId , err := s .getPayloadAttribute (ctx , arg .headState , nextSlot )
71- if err != nil {
72- log .WithError (err ).Error ("Could not get head payload attribute" )
73- }
72+ hasAttr , attr , proposerId := s .getPayloadAttribute (ctx , arg .headState , nextSlot )
7473
7574 payloadID , lastValidHash , err := s .cfg .ExecutionEngineCaller .ForkchoiceUpdated (ctx , fcs , attr )
7675 if err != nil {
@@ -149,7 +148,8 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *notifyForkcho
149148 log .WithError (err ).Error ("Could not set head root to valid" )
150149 return nil , nil
151150 }
152- if hasAttr && payloadID != nil { // If the forkchoice update call has an attribute, update the proposer payload ID cache.
151+ // If the forkchoice update call has an attribute, update the proposer payload ID cache.
152+ if hasAttr && payloadID != nil {
153153 var pId [8 ]byte
154154 copy (pId [:], payloadID [:])
155155 s .cfg .ProposerSlotIndexCache .SetProposerAndPayloadIDs (nextSlot , proposerId , pId , arg .headRoot )
@@ -250,22 +250,25 @@ func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int,
250250
251251// getPayloadAttributes returns the payload attributes for the given state and slot.
252252// The attribute is required to initiate a payload build process in the context of an `engine_forkchoiceUpdated` call.
253- func (s * Service ) getPayloadAttribute (ctx context.Context , st state.BeaconState , slot types.Slot ) (bool , * enginev1.PayloadAttributes , types.ValidatorIndex , error ) {
253+ func (s * Service ) getPayloadAttribute (ctx context.Context , st state.BeaconState , slot types.Slot ) (bool , payloadattribute.Attributer , types.ValidatorIndex ) {
254+ emptyAttri := payloadattribute .EmptyWithVersion (st .Version ())
254255 // Root is `[32]byte{}` since we are retrieving proposer ID of a given slot. During insertion at assignment the root was not known.
255256 proposerID , _ , ok := s .cfg .ProposerSlotIndexCache .GetProposerPayloadIDs (slot , [32 ]byte {} /* root */ )
256257 if ! ok { // There's no need to build attribute if there is no proposer for slot.
257- return false , nil , 0 , nil
258+ return false , emptyAttri , 0
258259 }
259260
260261 // Get previous randao.
261262 st = st .Copy ()
262263 st , err := transition .ProcessSlotsIfPossible (ctx , st , slot )
263264 if err != nil {
264- return false , nil , 0 , err
265+ log .WithError (err ).Error ("Could not process slots to get payload attribute" )
266+ return false , emptyAttri , 0
265267 }
266268 prevRando , err := helpers .RandaoMix (st , time .CurrentEpoch (st ))
267269 if err != nil {
268- return false , nil , 0 , nil
270+ log .WithError (err ).Error ("Could not get randao mix to get payload attribute" )
271+ return false , emptyAttri , 0
269272 }
270273
271274 // Get fee recipient.
@@ -283,22 +286,53 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState,
283286 "Please refer to our documentation for instructions" )
284287 }
285288 case err != nil :
286- return false , nil , 0 , errors .Wrap (err , "could not get fee recipient in db" )
289+ log .WithError (err ).Error ("Could not get fee recipient to get payload attribute" )
290+ return false , emptyAttri , 0
287291 default :
288292 feeRecipient = recipient
289293 }
290294
291295 // Get timestamp.
292296 t , err := slots .ToTime (uint64 (s .genesisTime .Unix ()), slot )
293297 if err != nil {
294- return false , nil , 0 , err
298+ log .WithError (err ).Error ("Could not get timestamp to get payload attribute" )
299+ return false , emptyAttri , 0
295300 }
296- attr := & enginev1.PayloadAttributes {
297- Timestamp : uint64 (t .Unix ()),
298- PrevRandao : prevRando ,
299- SuggestedFeeRecipient : feeRecipient .Bytes (),
301+
302+ var attr payloadattribute.Attributer
303+ switch st .Version () {
304+ case version .Capella :
305+ withdrawals , err := st .ExpectedWithdrawals ()
306+ if err != nil {
307+ log .WithError (err ).Error ("Could not get expected withdrawals to get payload attribute" )
308+ return false , emptyAttri , 0
309+ }
310+ attr , err = payloadattribute .New (& enginev1.PayloadAttributesV2 {
311+ Timestamp : uint64 (t .Unix ()),
312+ PrevRandao : prevRando ,
313+ SuggestedFeeRecipient : feeRecipient .Bytes (),
314+ Withdrawals : withdrawals ,
315+ })
316+ if err != nil {
317+ log .WithError (err ).Error ("Could not get payload attribute" )
318+ return false , emptyAttri , 0
319+ }
320+ case version .Bellatrix :
321+ attr , err = payloadattribute .New (& enginev1.PayloadAttributes {
322+ Timestamp : uint64 (t .Unix ()),
323+ PrevRandao : prevRando ,
324+ SuggestedFeeRecipient : feeRecipient .Bytes (),
325+ })
326+ if err != nil {
327+ log .WithError (err ).Error ("Could not get payload attribute" )
328+ return false , emptyAttri , 0
329+ }
330+ default :
331+ log .WithField ("version" , st .Version ()).Error ("Could not get payload attribute due to unknown state version" )
332+ return false , emptyAttri , 0
300333 }
301- return true , attr , proposerID , nil
334+
335+ return true , attr , proposerID
302336}
303337
304338// removeInvalidBlockAndState removes the invalid block and its corresponding state from the cache and DB.
0 commit comments