Remove blind field from block type (#13389)

* Init

* Init

* Fix tests
This commit is contained in:
terence
2023-12-29 13:28:19 -08:00
committed by GitHub
parent d4cc6fcf4a
commit 1c9ded4684
14 changed files with 36 additions and 69 deletions

View File

@@ -412,7 +412,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
require.ErrorContains(t, "not a bellatrix payload", err)
})
t.Run("not blinded", func(t *testing.T) {
sbb, err := blocks.NewSignedBeaconBlock(&eth.SignedBeaconBlockBellatrix{Block: &eth.BeaconBlockBellatrix{Body: &eth.BeaconBlockBodyBellatrix{}}})
sbb, err := blocks.NewSignedBeaconBlock(&eth.SignedBeaconBlockBellatrix{Block: &eth.BeaconBlockBellatrix{Body: &eth.BeaconBlockBodyBellatrix{ExecutionPayload: &v1.ExecutionPayload{}}}})
require.NoError(t, err)
_, _, err = (&Client{}).SubmitBlindedBlock(ctx, sbb)
require.ErrorIs(t, err, errNotBlinded)

View File

@@ -23,6 +23,7 @@ go_library(
"//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/metadata:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@@ -6,6 +6,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/metadata"
)
@@ -45,17 +46,17 @@ func InitializeDataMaps() {
},
bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) {
return blocks.NewSignedBeaconBlock(
&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{Body: &ethpb.BeaconBlockBodyBellatrix{}}},
&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{Body: &ethpb.BeaconBlockBodyBellatrix{ExecutionPayload: &enginev1.ExecutionPayload{}}}},
)
},
bytesutil.ToBytes4(params.BeaconConfig().CapellaForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) {
return blocks.NewSignedBeaconBlock(
&ethpb.SignedBeaconBlockCapella{Block: &ethpb.BeaconBlockCapella{Body: &ethpb.BeaconBlockBodyCapella{}}},
&ethpb.SignedBeaconBlockCapella{Block: &ethpb.BeaconBlockCapella{Body: &ethpb.BeaconBlockBodyCapella{ExecutionPayload: &enginev1.ExecutionPayloadCapella{}}}},
)
},
bytesutil.ToBytes4(params.BeaconConfig().DenebForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) {
return blocks.NewSignedBeaconBlock(
&ethpb.SignedBeaconBlockDeneb{Block: &ethpb.BeaconBlockDeneb{Body: &ethpb.BeaconBlockBodyDeneb{}}},
&ethpb.SignedBeaconBlockDeneb{Block: &ethpb.BeaconBlockDeneb{Body: &ethpb.BeaconBlockBodyDeneb{ExecutionPayload: &enginev1.ExecutionPayloadDeneb{}}}},
)
},
}

View File

@@ -86,10 +86,8 @@ func setExecutionData(ctx context.Context, blk interfaces.SignedBeaconBlock, loc
// If we can't get the builder value, just use local block.
if higherValueBuilder && withdrawalsMatched { // Builder value is higher and withdrawals match.
blk.SetBlinded(true)
if err := setBuilderExecution(blk, builderPayload, builderKzgCommitments); err != nil {
log.WithError(err).Warn("Proposer: failed to set builder payload")
blk.SetBlinded(false)
return setLocalExecution(blk, localPayload)
} else {
return nil
@@ -110,10 +108,8 @@ func setExecutionData(ctx context.Context, blk interfaces.SignedBeaconBlock, loc
)
return setLocalExecution(blk, localPayload)
default: // Bellatrix case.
blk.SetBlinded(true)
if err := setBuilderExecution(blk, builderPayload, builderKzgCommitments); err != nil {
log.WithError(err).Warn("Proposer: failed to set builder payload")
blk.SetBlinded(false)
return setLocalExecution(blk, localPayload)
} else {
return nil
@@ -315,9 +311,6 @@ func setExecution(blk interfaces.SignedBeaconBlock, execution interfaces.Executi
return errors.New("execution is nil")
}
// Set the blinded status of the block
blk.SetBlinded(isBlinded)
// Set the execution data for the block
errMessage := "failed to set local execution"
if isBlinded {

View File

@@ -10,6 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/config/params"
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/testing/require"
)
@@ -98,7 +99,7 @@ func TestExtractBlockDataType(t *testing.T) {
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
},
want: func() interfaces.ReadOnlySignedBeaconBlock {
wsb, err := blocks.NewSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{Body: &ethpb.BeaconBlockBodyBellatrix{}}})
wsb, err := blocks.NewSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{Body: &ethpb.BeaconBlockBodyBellatrix{ExecutionPayload: &enginev1.ExecutionPayload{}}}})
require.NoError(t, err)
return wsb
}(),

View File

@@ -318,7 +318,7 @@ func Test_NewBeaconBlockBody(t *testing.T) {
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Bellatrix, b.version)
assert.Equal(t, true, b.isBlinded)
assert.Equal(t, true, b.IsBlinded())
})
t.Run("BeaconBlockBodyCapella", func(t *testing.T) {
pb := &eth.BeaconBlockBodyCapella{}
@@ -335,7 +335,7 @@ func Test_NewBeaconBlockBody(t *testing.T) {
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Capella, b.version)
assert.Equal(t, true, b.isBlinded)
assert.Equal(t, true, b.IsBlinded())
})
t.Run("BeaconBlockBodyDeneb", func(t *testing.T) {
pb := &eth.BeaconBlockBodyDeneb{}
@@ -352,7 +352,7 @@ func Test_NewBeaconBlockBody(t *testing.T) {
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Deneb, b.version)
assert.Equal(t, true, b.isBlinded)
assert.Equal(t, true, b.IsBlinded())
})
t.Run("nil", func(t *testing.T) {
_, err := NewBeaconBlockBody(nil)
@@ -388,7 +388,7 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Bellatrix, sb.Version())
})
t.Run("BellatrixBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix, isBlinded: true}}
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
@@ -403,7 +403,7 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Capella, sb.Version())
})
t.Run("CapellaBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella, isBlinded: true}}
b := &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
@@ -418,7 +418,7 @@ func Test_BuildSignedBeaconBlock(t *testing.T) {
assert.Equal(t, version.Deneb, sb.Version())
})
t.Run("DenebBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Deneb, body: &BeaconBlockBody{version: version.Deneb, isBlinded: true}}
b := &BeaconBlock{version: version.Deneb, body: &BeaconBlockBody{version: version.Deneb}}
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())

View File

@@ -340,7 +340,7 @@ func (b *SignedBeaconBlock) Version() int {
// IsBlinded metadata on whether a block is blinded
func (b *SignedBeaconBlock) IsBlinded() bool {
return b.block.body.isBlinded
return b.version >= version.Bellatrix && b.block.body.executionPayload == nil
}
// ValueInGwei metadata on the payload value returned by the builder. Value is 0 by default if local.
@@ -612,7 +612,7 @@ func (b *BeaconBlock) IsNil() bool {
// IsBlinded checks if the beacon block is a blinded block.
func (b *BeaconBlock) IsBlinded() bool {
return b.body.isBlinded
return b.version >= version.Bellatrix && b.body.executionPayload == nil
}
// Version of the underlying protobuf object.
@@ -1011,7 +1011,7 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
case version.Phase0, version.Altair:
return nil, consensus_types.ErrNotSupported("Execution", b.version)
case version.Bellatrix:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeader
var ok bool
if b.executionPayloadHeader != nil {
@@ -1032,7 +1032,7 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
}
return WrappedExecutionPayload(p)
case version.Capella:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeaderCapella
var ok bool
if b.executionPayloadHeader != nil {
@@ -1053,7 +1053,7 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
}
return WrappedExecutionPayloadCapella(p, 0)
case version.Deneb:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeaderDeneb
var ok bool
if b.executionPayloadHeader != nil {
@@ -1114,17 +1114,17 @@ func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error)
case version.Altair:
return pb.(*eth.BeaconBlockBodyAltair).HashTreeRoot()
case version.Bellatrix:
if b.isBlinded {
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockBodyBellatrix).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyBellatrix).HashTreeRoot()
case version.Capella:
if b.isBlinded {
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockBodyCapella).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyCapella).HashTreeRoot()
case version.Deneb:
if b.isBlinded {
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockBodyDeneb).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyDeneb).HashTreeRoot()
@@ -1132,3 +1132,8 @@ func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error)
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
}
}
// IsBlinded checks if the beacon block body is a blinded block body.
func (b *BeaconBlockBody) IsBlinded() bool {
return b.version >= version.Bellatrix && b.executionPayload == nil
}

View File

@@ -200,7 +200,6 @@ func Test_BeaconBlock_Copy(t *testing.T) {
b.version = version.Bellatrix
b.body.version = b.version
b.body.isBlinded = true
cp, err = b.Copy()
require.NoError(t, err)
assert.NotEqual(t, cp, b)
@@ -232,17 +231,6 @@ func Test_BeaconBlock_Copy(t *testing.T) {
gas, err := e.ExcessBlobGas()
require.NoError(t, err)
require.DeepEqual(t, gas, uint64(123))
b.body.isBlinded = true
cp, err = b.Copy()
require.NoError(t, err)
assert.NotEqual(t, cp, b)
assert.NotEqual(t, cp.Body(), bb)
e, err = cp.Body().Execution()
require.NoError(t, err)
gas, err = e.ExcessBlobGas()
require.NoError(t, err)
require.DeepEqual(t, gas, uint64(223))
}
func Test_BeaconBlock_IsNil(t *testing.T) {
@@ -263,8 +251,9 @@ func Test_BeaconBlock_IsNil(t *testing.T) {
func Test_BeaconBlock_IsBlinded(t *testing.T) {
b := &SignedBeaconBlock{block: &BeaconBlock{body: &BeaconBlockBody{}}}
assert.Equal(t, false, b.IsBlinded())
b.SetBlinded(true)
assert.Equal(t, true, b.IsBlinded())
b1 := &SignedBeaconBlock{version: version.Bellatrix, block: &BeaconBlock{body: &BeaconBlockBody{executionPayloadHeader: executionPayloadHeader{}}}}
assert.Equal(t, true, b1.IsBlinded())
}
func Test_BeaconBlock_Version(t *testing.T) {
@@ -433,7 +422,7 @@ func Test_BeaconBlockBody_Execution(t *testing.T) {
executionCapellaHeader := &pb.ExecutionPayloadHeaderCapella{BlockNumber: 1}
eCapellaHeader, err := WrappedExecutionPayloadHeaderCapella(executionCapellaHeader, 0)
require.NoError(t, err)
bb = &SignedBeaconBlock{version: version.Capella, block: &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella, isBlinded: true}}}
bb = &SignedBeaconBlock{version: version.Capella, block: &BeaconBlock{version: version.Capella, body: &BeaconBlockBody{version: version.Capella}}}
require.NoError(t, bb.SetExecution(eCapellaHeader))
result, err = bb.Block().Body().Execution()
require.NoError(t, err)
@@ -454,7 +443,7 @@ func Test_BeaconBlockBody_Execution(t *testing.T) {
executionDenebHeader := &pb.ExecutionPayloadHeaderDeneb{BlockNumber: 1, ExcessBlobGas: 223}
eDenebHeader, err := WrappedExecutionPayloadHeaderDeneb(executionDenebHeader, 0)
require.NoError(t, err)
bb = &SignedBeaconBlock{version: version.Deneb, block: &BeaconBlock{version: version.Deneb, body: &BeaconBlockBody{version: version.Deneb, isBlinded: true}}}
bb = &SignedBeaconBlock{version: version.Deneb, block: &BeaconBlock{version: version.Deneb, body: &BeaconBlockBody{version: version.Deneb}}}
require.NoError(t, bb.SetExecution(eDenebHeader))
result, err = bb.Block().Body().Execution()
require.NoError(t, err)

View File

@@ -313,7 +313,7 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
SyncAggregate: b.syncAggregate,
}, nil
case version.Bellatrix:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeader
var ok bool
if b.executionPayloadHeader != nil {
@@ -356,7 +356,7 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
ExecutionPayload: p,
}, nil
case version.Capella:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeaderCapella
var ok bool
if b.executionPayloadHeader != nil {
@@ -401,7 +401,7 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
BlsToExecutionChanges: b.blsToExecutionChanges,
}, nil
case version.Deneb:
if b.isBlinded {
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeaderDeneb
var ok bool
if b.executionPayloadHeader != nil {
@@ -755,7 +755,6 @@ func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, er
b := &BeaconBlockBody{
version: version.Phase0,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -775,7 +774,6 @@ func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBo
b := &BeaconBlockBody{
version: version.Altair,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -801,7 +799,6 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
}
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -828,7 +825,6 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
}
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -855,7 +851,6 @@ func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlock
}
b := &BeaconBlockBody{
version: version.Capella,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -883,7 +878,6 @@ func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella)
}
b := &BeaconBlockBody{
version: version.Capella,
isBlinded: true,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -911,7 +905,6 @@ func initBlockBodyFromProtoDeneb(pb *eth.BeaconBlockBodyDeneb) (*BeaconBlockBody
}
b := &BeaconBlockBody{
version: version.Deneb,
isBlinded: false,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
@@ -940,7 +933,6 @@ func initBlindedBlockBodyFromProtoDeneb(pb *eth.BlindedBeaconBlockBodyDeneb) (*B
}
b := &BeaconBlockBody{
version: version.Deneb,
isBlinded: true,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),

View File

@@ -1312,7 +1312,6 @@ func bodyBlindedBellatrix(t *testing.T) *BeaconBlockBody {
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
@@ -1360,7 +1359,6 @@ func bodyBlindedCapella(t *testing.T) *BeaconBlockBody {
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Capella,
isBlinded: true,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],
@@ -1410,7 +1408,6 @@ func bodyBlindedDeneb(t *testing.T) *BeaconBlockBody {
require.NoError(t, err)
return &BeaconBlockBody{
version: version.Deneb,
isBlinded: true,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.root[:],

View File

@@ -38,12 +38,6 @@ func (b *SignedBeaconBlock) SetStateRoot(root []byte) {
copy(b.block.stateRoot[:], root)
}
// SetBlinded sets the blinded flag of the beacon block.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetBlinded(blinded bool) {
b.block.body.isBlinded = blinded
}
// SetRandaoReveal sets the randao reveal in the block body.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetRandaoReveal(r []byte) {
@@ -108,7 +102,7 @@ func (b *SignedBeaconBlock) SetExecution(e interfaces.ExecutionData) error {
if b.version == version.Phase0 || b.version == version.Altair {
return consensus_types.ErrNotSupported("Execution", b.version)
}
if b.block.body.isBlinded {
if e.IsBlinded() {
b.block.body.executionPayloadHeader = e
return nil
}

View File

@@ -36,7 +36,6 @@ var (
// BeaconBlockBody is the main beacon block body structure. It can represent any block type.
type BeaconBlockBody struct {
version int
isBlinded bool
randaoReveal [field_params.BLSSignatureLength]byte
eth1Data *eth.Eth1Data
graffiti [field_params.RootLength]byte

View File

@@ -91,7 +91,6 @@ type SignedBeaconBlock interface {
SetGraffiti([]byte)
SetEth1Data(*ethpb.Eth1Data)
SetRandaoReveal([]byte)
SetBlinded(bool)
SetStateRoot([]byte)
SetParentRoot([]byte)
SetProposerIndex(idx primitives.ValidatorIndex)

View File

@@ -197,10 +197,6 @@ func (BeaconBlock) SetParentRoot(_ []byte) {
panic("implement me")
}
func (BeaconBlock) SetBlinded(_ bool) {
panic("implement me")
}
func (BeaconBlock) Copy() (interfaces.ReadOnlyBeaconBlock, error) {
panic("implement me")
}