mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
remove usages of params from proto packages (#15403)
* remove usages of params from proto packages * make it harder to mess up the order of request limit args * remove errant edit (Terence review) * fix missed updates after sig change --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package enginev1
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -23,7 +22,14 @@ const (
|
||||
ConsolidationRequestType
|
||||
)
|
||||
|
||||
func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequests, error) {
|
||||
// ExecutionRequestConfig ensures that we don't mix up the execution request params
|
||||
type ExecutionRequestLimits struct {
|
||||
Deposits uint64
|
||||
Withdrawals uint64
|
||||
Consolidations uint64
|
||||
}
|
||||
|
||||
func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests(limits ExecutionRequestLimits) (*ExecutionRequests, error) {
|
||||
requests := &ExecutionRequests{}
|
||||
var prevTypeNum *uint8
|
||||
for i := range ebe.ExecutionRequests {
|
||||
@@ -37,19 +43,19 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
|
||||
prevTypeNum = &requestType
|
||||
switch requestType {
|
||||
case DepositRequestType:
|
||||
drs, err := unmarshalDeposits(requestListInSSZBytes)
|
||||
drs, err := unmarshalDeposits(requestListInSSZBytes, limits.Deposits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requests.Deposits = drs
|
||||
case WithdrawalRequestType:
|
||||
wrs, err := unmarshalWithdrawals(requestListInSSZBytes)
|
||||
wrs, err := unmarshalWithdrawals(requestListInSSZBytes, limits.Withdrawals)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requests.Withdrawals = wrs
|
||||
case ConsolidationRequestType:
|
||||
crs, err := unmarshalConsolidations(requestListInSSZBytes)
|
||||
crs, err := unmarshalConsolidations(requestListInSSZBytes, limits.Consolidations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,33 +67,33 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
|
||||
return requests, nil
|
||||
}
|
||||
|
||||
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) {
|
||||
func unmarshalDeposits(requestListInSSZBytes []byte, maxDepositRequests uint64) ([]*DepositRequest, error) {
|
||||
if len(requestListInSSZBytes) < drSize {
|
||||
return nil, fmt.Errorf("invalid deposit requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), drSize)
|
||||
}
|
||||
maxSSZsize := uint64(drSize) * params.BeaconConfig().MaxDepositRequestsPerPayload
|
||||
maxSSZsize := uint64(drSize) * maxDepositRequests
|
||||
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
|
||||
return nil, fmt.Errorf("invalid deposit requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
|
||||
}
|
||||
return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} })
|
||||
}
|
||||
|
||||
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) {
|
||||
func unmarshalWithdrawals(requestListInSSZBytes []byte, maxWithdrawals uint64) ([]*WithdrawalRequest, error) {
|
||||
if len(requestListInSSZBytes) < wrSize {
|
||||
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), wrSize)
|
||||
}
|
||||
maxSSZsize := uint64(wrSize) * params.BeaconConfig().MaxWithdrawalRequestsPerPayload
|
||||
maxSSZsize := uint64(wrSize) * maxWithdrawals
|
||||
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
|
||||
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
|
||||
}
|
||||
return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
|
||||
}
|
||||
|
||||
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) {
|
||||
func unmarshalConsolidations(requestListInSSZBytes []byte, maxConsolidations uint64) ([]*ConsolidationRequest, error) {
|
||||
if len(requestListInSSZBytes) < crSize {
|
||||
return nil, fmt.Errorf("invalid consolidation requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), crSize)
|
||||
}
|
||||
maxSSZsize := uint64(crSize) * params.BeaconConfig().MaxConsolidationsRequestsPerPayload
|
||||
maxSSZsize := uint64(crSize) * maxConsolidations
|
||||
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
|
||||
return nil, fmt.Errorf("invalid consolidation requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user