mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
[Feature] - Store Only Blinded Beacon Blocks Post-Merge (#11010)
* add in flags * add sync and db items * bring over all other changes * enable on * use feature flag * powchain * builds * fix up tests * pass iface * gaz * enable bellatrix blind in unmarshal only behind flag * poolside * pass rpc tests * rebuilds * naming * cleaner func * check needs resync * idiomatic * gaz * rem * build * nicer * build * cleaner * surface error * wrapping * unmarshal logs * fix up * cleaner * log * builds * Update beacon-chain/blockchain/execution_engine.go Co-authored-by: terencechain <terence@prysmaticlabs.com> * terence feedback * test added for resync * nil check * fmt Co-authored-by: terencechain <terence@prysmaticlabs.com>
This commit is contained in:
@@ -14,6 +14,8 @@ var (
|
||||
// This allows us to create a generic beacon block interface that is implemented by different
|
||||
// fork versions of beacon blocks.
|
||||
ErrUnsupportedField = errors.New("unsupported field for block type")
|
||||
// ErrUnsupportedVersion for beacon block methods.
|
||||
ErrUnsupportedVersion = errors.New("unsupported beacon block version")
|
||||
// ErrUnsupportedSignedBeaconBlock is returned when the struct type is not a supported signed
|
||||
// beacon block type.
|
||||
ErrUnsupportedSignedBeaconBlock = errors.New("unsupported signed beacon block")
|
||||
@@ -208,55 +210,6 @@ func BuildSignedBeaconBlockFromExecutionPayload(
|
||||
return wrappedBellatrixSignedBeaconBlock(bellatrixFullBlock)
|
||||
}
|
||||
|
||||
// WrapSignedBlindedBeaconBlock converts a signed beacon block into a blinded format.
|
||||
func WrapSignedBlindedBeaconBlock(blk interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
|
||||
if err := BeaconBlockIsNil(blk); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if blk.Block().IsBlinded() {
|
||||
return blk, nil
|
||||
}
|
||||
b := blk.Block()
|
||||
payload, err := b.Body().Execution()
|
||||
switch {
|
||||
case errors.Is(err, ErrUnsupportedField):
|
||||
return nil, ErrUnsupportedSignedBeaconBlock
|
||||
case err != nil:
|
||||
return nil, errors.Wrap(err, "could not get execution payload")
|
||||
default:
|
||||
}
|
||||
syncAgg, err := b.Body().SyncAggregate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
header, err := PayloadToHeader(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blindedBlock := ð.SignedBlindedBeaconBlockBellatrix{
|
||||
Block: ð.BlindedBeaconBlockBellatrix{
|
||||
Slot: b.Slot(),
|
||||
ProposerIndex: b.ProposerIndex(),
|
||||
ParentRoot: b.ParentRoot(),
|
||||
StateRoot: b.StateRoot(),
|
||||
Body: ð.BlindedBeaconBlockBodyBellatrix{
|
||||
RandaoReveal: b.Body().RandaoReveal(),
|
||||
Eth1Data: b.Body().Eth1Data(),
|
||||
Graffiti: b.Body().Graffiti(),
|
||||
ProposerSlashings: b.Body().ProposerSlashings(),
|
||||
AttesterSlashings: b.Body().AttesterSlashings(),
|
||||
Attestations: b.Body().Attestations(),
|
||||
Deposits: b.Body().Deposits(),
|
||||
VoluntaryExits: b.Body().VoluntaryExits(),
|
||||
SyncAggregate: syncAgg,
|
||||
ExecutionPayloadHeader: header,
|
||||
},
|
||||
},
|
||||
Signature: blk.Signature(),
|
||||
}
|
||||
return wrappedBellatrixSignedBlindedBeaconBlock(blindedBlock)
|
||||
}
|
||||
|
||||
func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
|
||||
if gb == nil {
|
||||
return nil, ErrNilObjectWrapped
|
||||
|
||||
@@ -112,6 +112,10 @@ func (altairSignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeac
|
||||
return nil, ErrUnsupportedBlindedBellatrixBlock
|
||||
}
|
||||
|
||||
func (altairSignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
|
||||
return nil, ErrUnsupportedVersion
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (altairSignedBeaconBlock) Version() int {
|
||||
return version.Altair
|
||||
|
||||
@@ -107,6 +107,44 @@ func (bellatrixSignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair,
|
||||
return nil, ErrUnsupportedAltairBlock
|
||||
}
|
||||
|
||||
func (w bellatrixSignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
|
||||
if w.Block().IsNil() {
|
||||
return nil, errors.New("cannot convert nil block to blinded format")
|
||||
}
|
||||
payload := w.b.Block.Body.ExecutionPayload
|
||||
wrappedPayload, err := WrappedExecutionPayload(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
header, err := PayloadToHeader(wrappedPayload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return signedBlindedBeaconBlockBellatrix{
|
||||
b: ð.SignedBlindedBeaconBlockBellatrix{
|
||||
Block: ð.BlindedBeaconBlockBellatrix{
|
||||
Slot: w.b.Block.Slot,
|
||||
ProposerIndex: w.b.Block.ProposerIndex,
|
||||
ParentRoot: w.b.Block.ParentRoot,
|
||||
StateRoot: w.b.Block.StateRoot,
|
||||
Body: ð.BlindedBeaconBlockBodyBellatrix{
|
||||
RandaoReveal: w.b.Block.Body.RandaoReveal,
|
||||
Eth1Data: w.b.Block.Body.Eth1Data,
|
||||
Graffiti: w.b.Block.Body.Graffiti,
|
||||
ProposerSlashings: w.b.Block.Body.ProposerSlashings,
|
||||
AttesterSlashings: w.b.Block.Body.AttesterSlashings,
|
||||
Attestations: w.b.Block.Body.Attestations,
|
||||
Deposits: w.b.Block.Body.Deposits,
|
||||
VoluntaryExits: w.b.Block.Body.VoluntaryExits,
|
||||
SyncAggregate: w.b.Block.Body.SyncAggregate,
|
||||
ExecutionPayloadHeader: header,
|
||||
},
|
||||
},
|
||||
Signature: w.b.Signature,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (bellatrixSignedBeaconBlock) Version() int {
|
||||
return version.Bellatrix
|
||||
|
||||
@@ -108,6 +108,10 @@ func (Phase0SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeac
|
||||
return nil, ErrUnsupportedBlindedBellatrixBlock
|
||||
}
|
||||
|
||||
func (Phase0SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
|
||||
return nil, ErrUnsupportedVersion
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (Phase0SignedBeaconBlock) Version() int {
|
||||
return version.Phase0
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestWrapSignedBlindedBeaconBlock(t *testing.T) {
|
||||
|
||||
blk, err := wrapper.WrappedSignedBeaconBlock(bellatrixBlk)
|
||||
require.NoError(t, err)
|
||||
builtBlock, err := wrapper.WrapSignedBlindedBeaconBlock(blk)
|
||||
builtBlock, err := blk.ToBlinded()
|
||||
require.NoError(t, err)
|
||||
|
||||
got, err := builtBlock.Block().Body().Execution()
|
||||
|
||||
@@ -107,6 +107,10 @@ func (signedBlindedBeaconBlockBellatrix) PbAltairBlock() (*eth.SignedBeaconBlock
|
||||
return nil, ErrUnsupportedAltairBlock
|
||||
}
|
||||
|
||||
func (signedBlindedBeaconBlockBellatrix) ToBlinded() (interfaces.SignedBeaconBlock, error) {
|
||||
return nil, ErrUnsupportedVersion
|
||||
}
|
||||
|
||||
// Version of the underlying protobuf object.
|
||||
func (signedBlindedBeaconBlockBellatrix) Version() int {
|
||||
return version.BellatrixBlind
|
||||
|
||||
Reference in New Issue
Block a user