Skip to content

Commit

Permalink
fire payload event on skipped slots
Browse files Browse the repository at this point in the history
  • Loading branch information
kasey committed Nov 16, 2024
1 parent 8222cb2 commit 4edea3c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
54 changes: 31 additions & 23 deletions beacon-chain/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/async/event"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed"
Expand Down Expand Up @@ -71,29 +72,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *fcuConfig) (*
if arg.attributes == nil {
arg.attributes = payloadattribute.EmptyWithVersion(headBlk.Version())
}
go func() {
pidx, err := helpers.BeaconProposerIndex(ctx, arg.headState)
if err != nil {
log.WithError(err).
WithField("head_root", arg.headRoot[:]).
Error("Could not get proposer index for PayloadAttributes event")
return
}
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.PayloadAttributes,
Data: payloadattribute.EventData{
ProposerIndex: pidx,
ProposalSlot: arg.headState.Slot(),
ParentBlockNumber: headPayload.BlockNumber(),
ParentBlockRoot: arg.headRoot[:],
ParentBlockHash: headPayload.BlockHash(),
Attributer: arg.attributes,
HeadRoot: arg.headRoot,
HeadState: arg.headState,
HeadBlock: arg.headBlock,
},
})
}()
go firePayloadAttributesEvent(ctx, s.cfg.StateNotifier.StateFeed(), arg)
payloadID, lastValidHash, err := s.cfg.ExecutionEngineCaller.ForkchoiceUpdated(ctx, fcs, arg.attributes)
if err != nil {
switch {
Expand Down Expand Up @@ -192,6 +171,35 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *fcuConfig) (*
return payloadID, nil
}

func firePayloadAttributesEvent(ctx context.Context, f event.SubscriberSender, cfg *fcuConfig) {
pidx, err := helpers.BeaconProposerIndex(ctx, cfg.headState)
if err != nil {
log.WithError(err).
WithField("head_root", cfg.headRoot[:]).
Error("Could not get proposer index for PayloadAttributes event")
return
}
headPayload, err := cfg.headBlock.Block().Body().Execution()
if err != nil {
log.WithError(err).Error("Could not get execution payload for head block")
return
}
f.Send(&feed.Event{
Type: statefeed.PayloadAttributes,
Data: payloadattribute.EventData{
ProposerIndex: pidx,
ProposalSlot: cfg.headState.Slot(),
ParentBlockNumber: headPayload.BlockNumber(),
ParentBlockRoot: cfg.headRoot[:],
ParentBlockHash: headPayload.BlockHash(),
Attributer: cfg.attributes,
HeadRoot: cfg.headRoot,
HeadState: cfg.headState,
HeadBlock: cfg.headBlock,
},
})
}

// getPayloadHash returns the payload hash given the block root.
// if the block is before bellatrix fork epoch, it returns the zero hash.
func (s *Service) getPayloadHash(ctx context.Context, root []byte) ([32]byte, error) {
Expand Down
9 changes: 5 additions & 4 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,6 @@ func (s *Service) lateBlockTasks(ctx context.Context) {
}

attribute := s.getPayloadAttribute(ctx, headState, s.CurrentSlot()+1, headRoot[:])
// return early if we are not proposing next slot
if attribute.IsEmpty() {
return
}

s.headLock.RLock()
headBlock, err := s.headBlock()
Expand All @@ -663,6 +659,11 @@ func (s *Service) lateBlockTasks(ctx context.Context) {
headBlock: headBlock,
attributes: attribute,
}
// return early if we are not proposing next slot
if attribute.IsEmpty() {
go firePayloadAttributesEvent(ctx, s.cfg.StateNotifier.StateFeed(), fcuArgs)
return
}
_, err = s.notifyForkchoiceUpdate(ctx, fcuArgs)
if err != nil {
log.WithError(err).Debug("could not perform late block tasks: failed to update forkchoice with engine")
Expand Down

0 comments on commit 4edea3c

Please sign in to comment.