Handle blind block for DB (#10580)

* Handle blind block for DB

* Update blinded_beacon_block_bellatrix_test.go

* Update blocks_test.go

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terencechain
2022-05-03 09:55:59 -07:00
committed by GitHub
parent 59041cf868
commit d4fa490dec
9 changed files with 42 additions and 8 deletions

View File

@@ -705,6 +705,11 @@ func unmarshalBlock(_ context.Context, enc []byte) (interfaces.SignedBeaconBlock
if err := rawBlock.UnmarshalSSZ(enc[len(bellatrixKey):]); err != nil {
return nil, err
}
case hasBellatrixBlindKey(enc):
rawBlock = &ethpb.SignedBlindedBeaconBlockBellatrix{}
if err := rawBlock.UnmarshalSSZ(enc[len(bellatrixBlindKey):]); err != nil {
return nil, err
}
default:
// Marshal block bytes to phase 0 beacon block.
rawBlock = &ethpb.SignedBeaconBlock{}
@@ -722,6 +727,8 @@ func marshalBlock(_ context.Context, blk interfaces.SignedBeaconBlock) ([]byte,
return nil, err
}
switch blk.Version() {
case version.BellatrixBlind:
return snappy.Encode(nil, append(bellatrixBlindKey, obj...)), nil
case version.Bellatrix:
return snappy.Encode(nil, append(bellatrixKey, obj...)), nil
case version.Altair:

View File

@@ -56,6 +56,17 @@ var blockTests = []struct {
return wrapper.WrappedSignedBeaconBlock(b)
},
},
{
name: "bellatrix blind",
newBlock: func(slot types.Slot, root []byte) (interfaces.SignedBeaconBlock, error) {
b := util.NewBlindedBeaconBlockBellatrix()
b.Block.Slot = slot
if root != nil {
b.Block.ParentRoot = root
}
return wrapper.WrappedSignedBeaconBlock(b)
},
},
}
func TestStore_SaveBackfillBlockRoot(t *testing.T) {

View File

@@ -16,3 +16,10 @@ func hasBellatrixKey(enc []byte) bool {
}
return bytes.Equal(enc[:len(bellatrixKey)], bellatrixKey)
}
func hasBellatrixBlindKey(enc []byte) bool {
if len(bellatrixBlindKey) >= len(enc) {
return false
}
return bytes.Equal(enc[:len(bellatrixBlindKey)], bellatrixBlindKey)
}

View File

@@ -48,8 +48,9 @@ var (
// Below keys are used to identify objects are to be fork compatible.
// Objects that are only compatible with specific forks should be prefixed with such keys.
altairKey = []byte("altair")
bellatrixKey = []byte("merge")
altairKey = []byte("altair")
bellatrixKey = []byte("merge")
bellatrixBlindKey = []byte("blind-bellatrix")
// block root included in the beacon state used by weak subjectivity initial sync
originCheckpointBlockRootKey = []byte("origin-checkpoint-block-root")
// block root tracking the progress of backfill, or pointing at genesis if backfill has not been initiated

View File

@@ -674,7 +674,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
blk.Block.Slot = 5
blk.Block.ParentRoot = bsRoot[:]
blk.Block.Body.ExecutionPayload.Transactions = transactions
blindedBlk := util.NewBlindedBeaconBlockBellatrix()
blindedBlk := util.NewBlindedBeaconBlockBellatrixV2()
blindedBlk.Message.Slot = 5
blindedBlk.Message.ParentRoot = bsRoot[:]
blindedBlk.Message.Body.ExecutionPayloadHeader.TransactionsRoot = transactionsRoot[:]

View File

@@ -110,7 +110,7 @@ func (signedBlindedBeaconBlockBellatrix) PbAltairBlock() (*eth.SignedBeaconBlock
// Version of the underlying protobuf object.
func (signedBlindedBeaconBlockBellatrix) Version() int {
return version.Bellatrix
return version.BellatrixBlind
}
// Header converts the underlying protobuf object from blinded block to header format.
@@ -225,7 +225,7 @@ func (w blindedBeaconBlockBellatrix) Proto() proto.Message {
// Version of the underlying protobuf object.
func (blindedBeaconBlockBellatrix) Version() int {
return version.Bellatrix
return version.BellatrixBlind
}
// AsSignRequestObject returns the underlying sign request object.

View File

@@ -149,7 +149,7 @@ func TestBellatrixSignedBlindedBeaconBlock_Version(t *testing.T) {
wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBlindedBeaconBlockBellatrix{Block: &ethpb.BlindedBeaconBlockBellatrix{}})
require.NoError(t, err)
assert.Equal(t, version.Bellatrix, wsb.Version())
assert.Equal(t, version.BellatrixBlind, wsb.Version())
}
func TestBellatrixBlindedBeaconBlock_Slot(t *testing.T) {
@@ -243,7 +243,7 @@ func TestBellatrixBlindedBeaconBlock_Version(t *testing.T) {
wb, err := wrapper.WrappedBeaconBlock(&ethpb.BlindedBeaconBlockBellatrix{})
require.NoError(t, err)
assert.Equal(t, version.Bellatrix, wb.Version())
assert.Equal(t, version.BellatrixBlind, wb.Version())
}
func TestBellatrixBlindedBeaconBlockBody_RandaoReveal(t *testing.T) {

View File

@@ -4,6 +4,7 @@ const (
Phase0 = iota
Altair
Bellatrix
BellatrixBlind
)
func String(version int) string {
@@ -14,6 +15,8 @@ func String(version int) string {
return "altair"
case Bellatrix:
return "bellatrix"
case BellatrixBlind:
return "bellatrix-blind"
default:
return "unknown version"
}

View File

@@ -11,6 +11,11 @@ func NewBeaconBlockBellatrix() *ethpb.SignedBeaconBlockBellatrix {
}
// NewBlindedBeaconBlockBellatrix creates a blinded beacon block with minimum marshalable fields.
func NewBlindedBeaconBlockBellatrix() *v2.SignedBlindedBeaconBlockBellatrix {
func NewBlindedBeaconBlockBellatrix() *ethpb.SignedBlindedBeaconBlockBellatrix {
return HydrateSignedBlindedBeaconBlockBellatrix(&ethpb.SignedBlindedBeaconBlockBellatrix{})
}
// NewBlindedBeaconBlockBellatrixV2 creates a blinded beacon block with minimum marshalable fields.
func NewBlindedBeaconBlockBellatrixV2() *v2.SignedBlindedBeaconBlockBellatrix {
return HydrateV2SignedBlindedBeaconBlockBellatrix(&v2.SignedBlindedBeaconBlockBellatrix{})
}