mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Merge all block unblinding code into a single unblinder struct (#12240)
Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
This commit is contained in:
@@ -36,7 +36,7 @@ func (e executionPayload) IsNil() bool {
|
||||
}
|
||||
|
||||
// IsBlinded returns true if the underlying data is blinded.
|
||||
func (e executionPayload) IsBlinded() bool {
|
||||
func (executionPayload) IsBlinded() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -146,18 +146,18 @@ func (e executionPayload) Transactions() ([][]byte, error) {
|
||||
}
|
||||
|
||||
// TransactionsRoot --
|
||||
func (e executionPayload) TransactionsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayload) TransactionsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// Withdrawals --
|
||||
func (e executionPayload) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayload) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// WithdrawalsRoot --
|
||||
func (e executionPayload) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayload) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PbBellatrix --
|
||||
@@ -167,12 +167,12 @@ func (e executionPayload) PbBellatrix() (*enginev1.ExecutionPayload, error) {
|
||||
|
||||
// PbCapella --
|
||||
func (executionPayload) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// ValueInGwei --
|
||||
func (executionPayload) ValueInGwei() (uint64, error) {
|
||||
return 0, consensus_types.ErrUnsupportedGetter
|
||||
return 0, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// executionPayloadHeader is a convenience wrapper around a blinded beacon block body's execution header data structure
|
||||
@@ -197,7 +197,7 @@ func (e executionPayloadHeader) IsNil() bool {
|
||||
}
|
||||
|
||||
// IsBlinded returns true if the underlying data is a header.
|
||||
func (e executionPayloadHeader) IsBlinded() bool {
|
||||
func (executionPayloadHeader) IsBlinded() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ func (e executionPayloadHeader) BlockHash() []byte {
|
||||
|
||||
// Transactions --
|
||||
func (executionPayloadHeader) Transactions() ([][]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// TransactionsRoot --
|
||||
@@ -312,28 +312,28 @@ func (e executionPayloadHeader) TransactionsRoot() ([]byte, error) {
|
||||
}
|
||||
|
||||
// Withdrawals --
|
||||
func (e executionPayloadHeader) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayloadHeader) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// WithdrawalsRoot --
|
||||
func (e executionPayloadHeader) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayloadHeader) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PbCapella --
|
||||
func (executionPayloadHeader) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PbBellatrix --
|
||||
func (executionPayloadHeader) PbBellatrix() (*enginev1.ExecutionPayload, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// ValueInGwei --
|
||||
func (executionPayloadHeader) ValueInGwei() (uint64, error) {
|
||||
return 0, consensus_types.ErrUnsupportedGetter
|
||||
return 0, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PayloadToHeader converts `payload` into execution payload header format.
|
||||
@@ -387,7 +387,7 @@ func (e executionPayloadCapella) IsNil() bool {
|
||||
}
|
||||
|
||||
// IsBlinded returns true if the underlying data is blinded.
|
||||
func (e executionPayloadCapella) IsBlinded() bool {
|
||||
func (executionPayloadCapella) IsBlinded() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -497,8 +497,8 @@ func (e executionPayloadCapella) Transactions() ([][]byte, error) {
|
||||
}
|
||||
|
||||
// TransactionsRoot --
|
||||
func (e executionPayloadCapella) TransactionsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayloadCapella) TransactionsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// Withdrawals --
|
||||
@@ -507,8 +507,8 @@ func (e executionPayloadCapella) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
}
|
||||
|
||||
// WithdrawalsRoot --
|
||||
func (e executionPayloadCapella) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayloadCapella) WithdrawalsRoot() ([]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PbCapella --
|
||||
@@ -518,7 +518,7 @@ func (e executionPayloadCapella) PbCapella() (*enginev1.ExecutionPayloadCapella,
|
||||
|
||||
// PbBellatrix --
|
||||
func (executionPayloadCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// ValueInGwei --
|
||||
@@ -549,7 +549,7 @@ func (e executionPayloadHeaderCapella) IsNil() bool {
|
||||
}
|
||||
|
||||
// IsBlinded returns true if the underlying data is blinded.
|
||||
func (e executionPayloadHeaderCapella) IsBlinded() bool {
|
||||
func (executionPayloadHeaderCapella) IsBlinded() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ func (e executionPayloadHeaderCapella) BlockHash() []byte {
|
||||
|
||||
// Transactions --
|
||||
func (executionPayloadHeaderCapella) Transactions() ([][]byte, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// TransactionsRoot --
|
||||
@@ -664,8 +664,8 @@ func (e executionPayloadHeaderCapella) TransactionsRoot() ([]byte, error) {
|
||||
}
|
||||
|
||||
// Withdrawals --
|
||||
func (e executionPayloadHeaderCapella) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
func (executionPayloadHeaderCapella) Withdrawals() ([]*enginev1.Withdrawal, error) {
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// WithdrawalsRoot --
|
||||
@@ -675,12 +675,12 @@ func (e executionPayloadHeaderCapella) WithdrawalsRoot() ([]byte, error) {
|
||||
|
||||
// PbCapella --
|
||||
func (executionPayloadHeaderCapella) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// PbBellatrix --
|
||||
func (executionPayloadHeaderCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
|
||||
return nil, consensus_types.ErrUnsupportedGetter
|
||||
return nil, consensus_types.ErrUnsupportedField
|
||||
}
|
||||
|
||||
// ValueInGwei --
|
||||
@@ -756,7 +756,7 @@ func IsEmptyExecutionData(data interfaces.ExecutionData) (bool, error) {
|
||||
|
||||
txs, err := data.Transactions()
|
||||
switch {
|
||||
case errors.Is(err, consensus_types.ErrUnsupportedGetter):
|
||||
case errors.Is(err, consensus_types.ErrUnsupportedField):
|
||||
case err != nil:
|
||||
return false, err
|
||||
default:
|
||||
|
||||
@@ -211,16 +211,16 @@ func Test_executionPayload_Pb(t *testing.T) {
|
||||
assert.DeepEqual(t, payload.Proto(), pb)
|
||||
|
||||
_, err = payload.PbCapella()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
}
|
||||
|
||||
func Test_executionPayloadHeader_Pb(t *testing.T) {
|
||||
payload := createWrappedPayloadHeader(t)
|
||||
_, err := payload.PbBellatrix()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
|
||||
_, err = payload.PbCapella()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
}
|
||||
|
||||
func Test_executionPayloadCapella_Pb(t *testing.T) {
|
||||
@@ -230,16 +230,16 @@ func Test_executionPayloadCapella_Pb(t *testing.T) {
|
||||
assert.DeepEqual(t, payload.Proto(), pb)
|
||||
|
||||
_, err = payload.PbBellatrix()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
}
|
||||
|
||||
func Test_executionPayloadHeaderCapella_Pb(t *testing.T) {
|
||||
payload := createWrappedPayloadHeaderCapella(t)
|
||||
_, err := payload.PbBellatrix()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
|
||||
_, err = payload.PbCapella()
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
|
||||
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
|
||||
}
|
||||
|
||||
func createWrappedPayload(t testing.TB) interfaces.ExecutionData {
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
var (
|
||||
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
|
||||
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
|
||||
// ErrUnsupportedGetter is returned when a getter access is not supported for a specific beacon block version.
|
||||
ErrUnsupportedGetter = errors.New("unsupported getter")
|
||||
// ErrUnsupportedField is returned when a getter/setter access is not supported.
|
||||
ErrUnsupportedField = errors.New("unsupported getter")
|
||||
)
|
||||
|
||||
// ErrNotSupported constructs a message informing about an unsupported field access.
|
||||
func ErrNotSupported(funcName string, ver int) error {
|
||||
return errors2.Wrap(ErrUnsupportedGetter, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
|
||||
return errors2.Wrap(ErrUnsupportedField, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user