mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
improving the error messages for execution request deserialization (#14962)
* improving the error messages for execution request deserialization * changelog
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
### Changed
|
||||||
|
|
||||||
|
- execution requests errors on ssz length have been improved
|
||||||
@@ -63,30 +63,33 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
|
|||||||
|
|
||||||
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) {
|
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) {
|
||||||
if len(requestListInSSZBytes) < drSize {
|
if len(requestListInSSZBytes) < drSize {
|
||||||
return nil, fmt.Errorf("invalid deposit requests length, requests should be at least the size of %d", drSize)
|
return nil, fmt.Errorf("invalid deposit requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), drSize)
|
||||||
}
|
}
|
||||||
if uint64(len(requestListInSSZBytes)) > uint64(drSize)*params.BeaconConfig().MaxDepositRequestsPerPayload {
|
maxSSZsize := uint64(drSize) * params.BeaconConfig().MaxDepositRequestsPerPayload
|
||||||
return nil, fmt.Errorf("invalid deposit requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), drSize)
|
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{} })
|
return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) {
|
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) {
|
||||||
if len(requestListInSSZBytes) < wrSize {
|
if len(requestListInSSZBytes) < wrSize {
|
||||||
return nil, fmt.Errorf("invalid withdrawal requests length, requests should be at least the size of %d", wrSize)
|
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), wrSize)
|
||||||
}
|
}
|
||||||
if uint64(len(requestListInSSZBytes)) > uint64(wrSize)*params.BeaconConfig().MaxWithdrawalRequestsPerPayload {
|
maxSSZsize := uint64(wrSize) * params.BeaconConfig().MaxWithdrawalRequestsPerPayload
|
||||||
return nil, fmt.Errorf("invalid withdrawal requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), wrSize)
|
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{} })
|
return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) {
|
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) {
|
||||||
if len(requestListInSSZBytes) < crSize {
|
if len(requestListInSSZBytes) < crSize {
|
||||||
return nil, fmt.Errorf("invalid consolidation requests length, requests should be at least the size of %d", crSize)
|
return nil, fmt.Errorf("invalid consolidation requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), crSize)
|
||||||
}
|
}
|
||||||
if uint64(len(requestListInSSZBytes)) > uint64(crSize)*params.BeaconConfig().MaxConsolidationsRequestsPerPayload {
|
maxSSZsize := uint64(crSize) * params.BeaconConfig().MaxConsolidationsRequestsPerPayload
|
||||||
return nil, fmt.Errorf("invalid consolidation requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), crSize)
|
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)
|
||||||
}
|
}
|
||||||
return unmarshalItems(requestListInSSZBytes, crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} })
|
return unmarshalItems(requestListInSSZBytes, crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
|
|||||||
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
|
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
|
||||||
}
|
}
|
||||||
_, err = ebe.GetDecodedExecutionRequests()
|
_, err = ebe.GetDecodedExecutionRequests()
|
||||||
require.ErrorContains(t, "invalid deposit requests length", err)
|
require.ErrorContains(t, "invalid deposit requests SSZ size", err)
|
||||||
})
|
})
|
||||||
t.Run("If deposit requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
t.Run("If deposit requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
||||||
requests := make([]*enginev1.DepositRequest, params.BeaconConfig().MaxDepositRequestsPerPayload+1)
|
requests := make([]*enginev1.DepositRequest, params.BeaconConfig().MaxDepositRequestsPerPayload+1)
|
||||||
@@ -143,7 +143,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = ebe.GetDecodedExecutionRequests()
|
_, err = ebe.GetDecodedExecutionRequests()
|
||||||
require.ErrorContains(t, "invalid deposit requests length, requests should not be more than the max per payload", err)
|
require.ErrorContains(t, "invalid deposit requests SSZ size, requests should not be more than the max per payload", err)
|
||||||
})
|
})
|
||||||
t.Run("If withdrawal requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
t.Run("If withdrawal requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
||||||
requests := make([]*enginev1.WithdrawalRequest, params.BeaconConfig().MaxWithdrawalRequestsPerPayload+1)
|
requests := make([]*enginev1.WithdrawalRequest, params.BeaconConfig().MaxWithdrawalRequestsPerPayload+1)
|
||||||
@@ -162,7 +162,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = ebe.GetDecodedExecutionRequests()
|
_, err = ebe.GetDecodedExecutionRequests()
|
||||||
require.ErrorContains(t, "invalid withdrawal requests length, requests should not be more than the max per payload", err)
|
require.ErrorContains(t, "invalid withdrawal requests SSZ size, requests should not be more than the max per payload", err)
|
||||||
})
|
})
|
||||||
t.Run("If consolidation requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
t.Run("If consolidation requests are over the max allowed per payload then we should error", func(t *testing.T) {
|
||||||
requests := make([]*enginev1.ConsolidationRequest, params.BeaconConfig().MaxConsolidationsRequestsPerPayload+1)
|
requests := make([]*enginev1.ConsolidationRequest, params.BeaconConfig().MaxConsolidationsRequestsPerPayload+1)
|
||||||
@@ -181,7 +181,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = ebe.GetDecodedExecutionRequests()
|
_, err = ebe.GetDecodedExecutionRequests()
|
||||||
require.ErrorContains(t, "invalid consolidation requests length, requests should not be more than the max per payload", err)
|
require.ErrorContains(t, "invalid consolidation requests SSZ size, requests should not be more than the max per payload", err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user