prysm-pulse/beacon-chain/state/state-native/setters_payload_header.go
terencechain d17996f8b0
Update to V4 🚀 (#12134)
* Update V3 from V4

* Fix build v3 -> v4

* Update ssz

* Update beacon_chain.pb.go

* Fix formatter import

* Update update-mockgen.sh comment to v4

* Fix conflicts. Pass build and tests

* Fix test
2023-03-17 18:52:56 +00:00

51 lines
1.8 KiB
Go

package state_native
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
consensusblocks "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
_ "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
// SetLatestExecutionPayloadHeader for the beacon state.
func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionData) error {
b.lock.Lock()
defer b.lock.Unlock()
if b.version < version.Bellatrix {
return errNotSupported("SetLatestExecutionPayloadHeader", b.version)
}
switch header := val.Proto().(type) {
case *enginev1.ExecutionPayload:
latest, err := consensusblocks.PayloadToHeader(val)
if err != nil {
return errors.Wrap(err, "could not convert payload to header")
}
b.latestExecutionPayloadHeader = latest
b.markFieldAsDirty(types.LatestExecutionPayloadHeader)
return nil
case *enginev1.ExecutionPayloadCapella:
latest, err := consensusblocks.PayloadToHeaderCapella(val)
if err != nil {
return errors.Wrap(err, "could not convert payload to header")
}
b.latestExecutionPayloadHeaderCapella = latest
b.markFieldAsDirty(types.LatestExecutionPayloadHeaderCapella)
return nil
case *enginev1.ExecutionPayloadHeader:
b.latestExecutionPayloadHeader = header
b.markFieldAsDirty(types.LatestExecutionPayloadHeader)
return nil
case *enginev1.ExecutionPayloadHeaderCapella:
b.latestExecutionPayloadHeaderCapella = header
b.markFieldAsDirty(types.LatestExecutionPayloadHeaderCapella)
return nil
default:
return errors.New("value must be an execution payload header")
}
}