diff --git a/cl/cltypes/beacon_block.go b/cl/cltypes/beacon_block.go index 480f203a24e..558712098e0 100644 --- a/cl/cltypes/beacon_block.go +++ b/cl/cltypes/beacon_block.go @@ -517,6 +517,10 @@ func (b *BeaconBody) GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExecutionC return b.ExecutionChanges } +func (b *BeaconBody) GetExecutionRequests() *ExecutionRequests { + return b.ExecutionRequests +} + type DenebBeaconBlock struct { Block *BeaconBlock `json:"block"` KZGProofs *solid.ListSSZ[*KZGProof] `json:"kzg_proofs"` diff --git a/cl/cltypes/beacon_block_blinded.go b/cl/cltypes/beacon_block_blinded.go index 17215ad5b77..a3df5f05441 100644 --- a/cl/cltypes/beacon_block_blinded.go +++ b/cl/cltypes/beacon_block_blinded.go @@ -485,3 +485,7 @@ func (b *BlindedBeaconBody) GetBlobKzgCommitments() *solid.ListSSZ[*KZGCommitmen func (b *BlindedBeaconBody) GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExecutionChange] { return b.ExecutionChanges } + +func (b *BlindedBeaconBody) GetExecutionRequests() *ExecutionRequests { + return b.ExecutionRequests +} diff --git a/cl/cltypes/beacon_block_interface.go b/cl/cltypes/beacon_block_interface.go index 4d5bf1e5d78..6f84c857492 100644 --- a/cl/cltypes/beacon_block_interface.go +++ b/cl/cltypes/beacon_block_interface.go @@ -28,4 +28,5 @@ type GenericBeaconBody interface { GetVoluntaryExits() *solid.ListSSZ[*SignedVoluntaryExit] GetBlobKzgCommitments() *solid.ListSSZ[*KZGCommitment] GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExecutionChange] + GetExecutionRequests() *ExecutionRequests } diff --git a/cl/transition/machine/block.go b/cl/transition/machine/block.go index a5fec45be58..d67c759dfc6 100644 --- a/cl/transition/machine/block.go +++ b/cl/transition/machine/block.go @@ -131,13 +131,9 @@ func ProcessOperations(impl BlockOperationProcessor, s abstract.BeaconState, blo } signatures, messages, publicKeys = append(signatures, sigs...), append(messages, msgs...), append(publicKeys, pubKeys...) - if err := solid.RangeErr[*cltypes.AttesterSlashing](blockBody.GetAttesterSlashings(), func(index int, slashing *cltypes.AttesterSlashing, length int) error { - if err = impl.ProcessAttesterSlashing(s, slashing); err != nil { - return fmt.Errorf("ProcessAttesterSlashing: %s", err) - } - return nil - }); err != nil { - return nil, nil, nil, err + // attester slashings + if err := forEachProcess(s, blockBody.GetAttesterSlashings(), impl.ProcessAttesterSlashing); err != nil { + return nil, nil, nil, fmt.Errorf("ProcessProposerSlashing: %s", err) } // Process each attestations @@ -146,13 +142,8 @@ func ProcessOperations(impl BlockOperationProcessor, s abstract.BeaconState, blo } // Process each deposit - if err := solid.RangeErr[*cltypes.Deposit](blockBody.GetDeposits(), func(index int, deposit *cltypes.Deposit, length int) error { - if err = impl.ProcessDeposit(s, deposit); err != nil { - return fmt.Errorf("ProcessDeposit: %s", err) - } - return nil - }); err != nil { - return nil, nil, nil, err + if err := forEachProcess(s, blockBody.GetDeposits(), impl.ProcessDeposit); err != nil { + return nil, nil, nil, fmt.Errorf("ProcessDeposit: %s", err) } // Process each voluntary exit. @@ -173,9 +164,30 @@ func ProcessOperations(impl BlockOperationProcessor, s abstract.BeaconState, blo } signatures, messages, publicKeys = append(signatures, sigs...), append(messages, msgs...), append(publicKeys, pubKeys...) + if s.Version() >= clparams.ElectraVersion { + if err := forEachProcess(s, blockBody.GetExecutionRequests().Deposits, impl.ProcessDepositRequest); err != nil { + return nil, nil, nil, fmt.Errorf("ProcessDepositRequest: %s", err) + } + if err := forEachProcess(s, blockBody.GetExecutionRequests().Withdrawals, impl.ProcessWithdrawalRequest); err != nil { + return nil, nil, nil, fmt.Errorf("ProcessWithdrawalRequest: %s", err) + } + if err := forEachProcess(s, blockBody.GetExecutionRequests().Consolidations, impl.ProcessConsolidationRequest); err != nil { + return nil, nil, nil, fmt.Errorf("ProcessConsolidationRequest: %s", err) + } + } + return } +func forEachProcess[T solid.EncodableHashableSSZ]( + s abstract.BeaconState, + list *solid.ListSSZ[T], + f func(s abstract.BeaconState, item T) error) error { + return solid.RangeErr(list, func(index int, item T, length int) error { + return f(s, item) + }) +} + func processRandao(impl BlockProcessor, s abstract.BeaconState, body cltypes.GenericBeaconBody, block cltypes.GenericBeaconBlock) (sigs [][]byte, msgs [][]byte, pubKeys [][]byte, err error) { // Process RANDAO reveal. proposerIndex := block.GetProposerIndex() @@ -285,9 +297,9 @@ func processBlsToExecutionChanges(impl BlockOperationProcessor, s abstract.Beaco return err } - // Perform full validation if requested. - wc := validator.WithdrawalCredentials() if impl.FullValidate() { + // Perform full validation if requested. + wc := validator.WithdrawalCredentials() // Check the validator's withdrawal credentials prefix. if wc[0] != byte(beaconConfig.BLSWithdrawalPrefixByte) { return errors.New("invalid withdrawal credentials prefix")