Skip to content

Commit

Permalink
ToBlinded: Use Fulu. (#14797)
Browse files Browse the repository at this point in the history
* `ToBlinded`: Use Fulu.

* Fix Sammy's comment.

* `unmarshalState`: Use `hasFuluKey`.
  • Loading branch information
nalepae authored Jan 15, 2025
1 parent ef293e5 commit e07341e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
13 changes: 13 additions & 0 deletions beacon-chain/db/kv/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,19 @@ func (s *Store) unmarshalState(_ context.Context, enc []byte, validatorEntries [
}

switch {
case hasFuluKey(enc):
protoState := &ethpb.BeaconStateFulu{}
if err := protoState.UnmarshalSSZ(enc[len(fuluKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for Electra")
}
ok, err := s.isStateValidatorMigrationOver()
if err != nil {
return nil, err
}
if ok {
protoState.Validators = validatorEntries
}
return statenative.InitializeFromProtoUnsafeFulu(protoState)
case hasElectraKey(enc):
protoState := &ethpb.BeaconStateElectra{}
if err := protoState.UnmarshalSSZ(enc[len(electraKey):]); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions changelog/manu_fulu_to_blinded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- `ToBlinded`: Use Fulu struct for Fulu (instead of Electra)
2 changes: 1 addition & 1 deletion config/params/mainnet_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,5 @@ func FillTestVersions(c *BeaconChainConfig, b byte) {
c.CapellaForkVersion[0] = 3
c.DenebForkVersion[0] = 4
c.ElectraForkVersion[0] = 5
c.FuluForkVersion[0] = 5
c.FuluForkVersion[0] = 6
}
5 changes: 4 additions & 1 deletion consensus-types/blocks/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ func PayloadToHeaderDeneb(payload interfaces.ExecutionData) (*enginev1.Execution
}, nil
}

var PayloadToHeaderElectra = PayloadToHeaderDeneb
var (
PayloadToHeaderElectra = PayloadToHeaderDeneb
PayloadToHeaderFulu = PayloadToHeaderDeneb
)

// IsEmptyExecutionData checks if an execution data is empty underneath. If a single field has
// a non-zero value, this function will return false.
Expand Down
43 changes: 40 additions & 3 deletions consensus-types/blocks/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,51 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
return nil, err
}

if b.version >= version.Fulu {
p, ok := payload.Proto().(*enginev1.ExecutionPayloadDeneb)
if !ok {
return nil, fmt.Errorf("%T is not an execution payload header of Deneb version", p)
}
header, err := PayloadToHeaderFulu(payload)
if err != nil {
return nil, errors.Wrap(err, "payload to header fulu")
}

return initBlindedSignedBlockFromProtoFulu(
&eth.SignedBlindedBeaconBlockFulu{
Message: &eth.BlindedBeaconBlockFulu{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyFulu{
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashingsElectra,
Attestations: b.block.body.attestationsElectra,
Deposits: b.block.body.deposits,
VoluntaryExits: b.block.body.voluntaryExits,
SyncAggregate: b.block.body.syncAggregate,
ExecutionPayloadHeader: header,
BlsToExecutionChanges: b.block.body.blsToExecutionChanges,
BlobKzgCommitments: b.block.body.blobKzgCommitments,
ExecutionRequests: b.block.body.executionRequests,
},
},
Signature: b.signature[:],
})
}

if b.version >= version.Electra {
p, ok := payload.Proto().(*enginev1.ExecutionPayloadDeneb)
if !ok {
return nil, fmt.Errorf("%T is not an execution payload header of Deneb version", p)
}
header, err := PayloadToHeaderElectra(payload)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "payload to header electra")
}
return initBlindedSignedBlockFromProtoElectra(
&eth.SignedBlindedBeaconBlockElectra{
Expand Down Expand Up @@ -206,7 +243,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
case *enginev1.ExecutionPayload:
header, err := PayloadToHeader(payload)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "payload to header")
}
return initBlindedSignedBlockFromProtoBellatrix(
&eth.SignedBlindedBeaconBlockBellatrix{
Expand Down Expand Up @@ -261,7 +298,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
case *enginev1.ExecutionPayloadDeneb:
header, err := PayloadToHeaderDeneb(payload)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "payload to header deneb")
}
return initBlindedSignedBlockFromProtoDeneb(
&eth.SignedBlindedBeaconBlockDeneb{
Expand Down

0 comments on commit e07341e

Please sign in to comment.