Skip to content

Commit

Permalink
process operations
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Nov 5, 2024
1 parent bff0e55 commit 4496a21
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 4 additions & 0 deletions cl/cltypes/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions cl/cltypes/beacon_block_blinded.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions cl/cltypes/beacon_block_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ type GenericBeaconBody interface {
GetVoluntaryExits() *solid.ListSSZ[*SignedVoluntaryExit]
GetBlobKzgCommitments() *solid.ListSSZ[*KZGCommitment]
GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExecutionChange]
GetExecutionRequests() *ExecutionRequests
}
44 changes: 28 additions & 16 deletions cl/transition/machine/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4496a21

Please sign in to comment.