defer payload attribute computation (#14644)

* defer payload attribute computation

* fire payload event on skipped slots

* changelog

* fix test and missing version attr

* fix lint

* deepsource

* mv head block lookup for missed slots to streamer

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2024-11-19 10:49:52 -06:00
committed by GitHub
parent 9de75b5376
commit 8d6577be84
11 changed files with 288 additions and 119 deletions

View File

@@ -10,8 +10,12 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/consensus-types/payload-attribute",
visibility = ["//visibility:public"],
deps = [
"//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//runtime/version:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@@ -38,6 +38,16 @@ func (a *data) Withdrawals() ([]*enginev1.Withdrawal, error) {
return a.withdrawals, nil
}
func (a *data) ParentBeaconBlockRoot() ([]byte, error) {
if len(a.parentBeaconBlockRoot) == 0 {
return nil, errNoParentRoot
}
if a.version < version.Deneb {
return nil, consensus_types.ErrNotSupported("ParentBeaconBlockRoot", a.version)
}
return a.parentBeaconBlockRoot, nil
}
// PbV1 returns the payload attribute in version 1.
func (a *data) PbV1() (*enginev1.PayloadAttributes, error) {
if a == nil {
@@ -97,6 +107,9 @@ func (a *data) PbV3() (*enginev1.PayloadAttributesV3, error) {
// IsEmpty returns whether the given payload attribute is empty
func (a *data) IsEmpty() bool {
if a == nil {
return true
}
if len(a.PrevRandao()) != 0 {
return false
}

View File

@@ -10,6 +10,7 @@ type Attributer interface {
Timestamp() uint64
SuggestedFeeRecipient() []byte
Withdrawals() ([]*enginev1.Withdrawal, error)
ParentBeaconBlockRoot() ([]byte, error)
PbV1() (*enginev1.PayloadAttributes, error)
PbV2() (*enginev1.PayloadAttributesV2, error)
PbV3() (*enginev1.PayloadAttributesV3, error)

View File

@@ -2,7 +2,11 @@ package payloadattribute
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
@@ -23,6 +27,7 @@ type data struct {
var (
errNilPayloadAttribute = errors.New("received nil payload attribute")
errUnsupportedPayloadAttribute = errors.New("unsupported payload attribute")
errNoParentRoot = errors.New("parent root is empty")
)
// New returns a new payload attribute with the given input object.
@@ -89,3 +94,16 @@ func initPayloadAttributeFromV3(a *enginev1.PayloadAttributesV3) (Attributer, er
parentBeaconBlockRoot: a.ParentBeaconBlockRoot,
}, nil
}
// EventData holds the values for a PayloadAttributes event.
type EventData struct {
ProposerIndex primitives.ValidatorIndex
ProposalSlot primitives.Slot
ParentBlockNumber uint64
ParentBlockRoot []byte
ParentBlockHash []byte
Attributer Attributer
HeadState state.BeaconState
HeadBlock interfaces.ReadOnlySignedBeaconBlock
HeadRoot [field_params.RootLength]byte
}