Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payload attribute computations in event handler #14963

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Conversation

kasey
Copy link
Contributor

@kasey kasey commented Feb 19, 2025

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

This fixes the payload attribute event bugs referenced here:
#14644 (comment)

Other notes for review

Further testing is required, particularly if head is far behind, process_slots can timeout and trigger errors in the event stream response, which may need additional handling.

Acknowledgements

@kasey kasey requested a review from a team as a code owner February 19, 2025 21:54
@james-prysm james-prysm changed the title WIP: payload attribute computations in event handler payload attribute computations in event handler Mar 3, 2025
@james-prysm james-prysm added API Api related tasks Bug Something isn't working labels Mar 3, 2025
}
}()
if lr == nil {
log.Warn("event stream skipping a nil lazy event reader callback")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Warn("event stream skipping a nil lazy event reader callback")
log.Warn("Event stream skipping a nil lazy event reader callback")

r := lr()
if r == nil {
log.Warn("event stream skipping a nil event reader")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Warn("event stream skipping a nil event reader")
log.Warn("Event stream skipping a nil event reader")

// all of the checked fields empty, so the logical short circuit should hit immediately.
func needsFill(ev payloadattribute.EventData) bool {
return ev.HeadState == nil || ev.HeadState.IsNil() ||
ev.HeadState.LatestBlockHeader() == nil || ev.HeadState.LatestBlockHeader() == nil ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ev.HeadState.LatestBlockHeader() == nil is checked twice

attr, err := s.computePayloadAttributes(ctx, ev)
ev.HeadState, err = s.HeadFetcher.HeadState(ctx)
if err != nil {
return ev, errors.Wrap(err, "Could not get head state")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not get head state")
return ev, errors.Wrap(err, "could not get head state")


ev.HeadBlock, err = s.HeadFetcher.HeadBlock(ctx)
if err != nil {
return ev, errors.Wrap(err, "Could not look up head block")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not look up head block")
return ev, errors.Wrap(err, "could not look up head block")

}
ev.HeadRoot, err = ev.HeadBlock.Block().HashTreeRoot()
if err != nil {
return ev, errors.Wrap(err, "Could not compute head block root")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not compute head block root")
return ev, errors.Wrap(err, "could not compute head block root")


hsr, err := ev.HeadState.LatestBlockHeader().HashTreeRoot()
if err != nil {
return ev, errors.Wrap(err, "Could not compute latest block header root")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not compute latest block header root")
return ev, errors.Wrap(err, "could not compute latest block header root")

if err != nil {
return ev, errors.Wrap(err, "Could not compute payload attributes")
return ev, errors.Wrap(err, "Could not run process blocks on head state into the proposal slot epoch")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not run process blocks on head state into the proposal slot epoch")
return ev, errors.Wrap(err, "could not run process blocks on head state into the proposal slot epoch")


payload, err := ev.HeadBlock.Block().Body().Execution()
if err != nil {
return ev, errors.Wrap(err, "Could not get execution payload for head block")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ev, errors.Wrap(err, "Could not get execution payload for head block")
return ev, errors.Wrap(err, "could not get execution payload for head block")

Comment on lines +177 to +179
// the fcu args have differing amounts of completeness based on the code path,
// and there is work we only want to do if a client is actually listening to the events beacon api endpoint.
// temporary solution: just fire a blank event and fill in the details in the api handler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the cfg parameter means that in case of firing from notifyForkchoiceUpdate you have to do extra work in the handler, since you need to recompute what you already have available. What about leaving the parameter and filling event data only when cfg != nil? You can then pass nil as the value in lateBlockTasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants