mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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:
@@ -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 = ðpb.SignedBlindedBeaconBlockBellatrix{}
|
||||
if err := rawBlock.UnmarshalSSZ(enc[len(bellatrixBlindKey):]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
// Marshal block bytes to phase 0 beacon block.
|
||||
rawBlock = ðpb.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:
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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[:]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestBellatrixSignedBlindedBeaconBlock_Version(t *testing.T) {
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBlindedBeaconBlockBellatrix{Block: ðpb.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(ðpb.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) {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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(ðpb.SignedBlindedBeaconBlockBellatrix{})
|
||||
}
|
||||
|
||||
// NewBlindedBeaconBlockBellatrixV2 creates a blinded beacon block with minimum marshalable fields.
|
||||
func NewBlindedBeaconBlockBellatrixV2() *v2.SignedBlindedBeaconBlockBellatrix {
|
||||
return HydrateV2SignedBlindedBeaconBlockBellatrix(&v2.SignedBlindedBeaconBlockBellatrix{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user