Skip to content

Commit

Permalink
Use badger for blinded blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
syjn99 committed Feb 4, 2025
1 parent 5b68423 commit 24d1ba3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 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 hasBadgerKey(enc):
protoState := &ethpb.BeaconStateBadger{}
if err := protoState.UnmarshalSSZ(enc[len(badgerKey):]); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal encoding for Badger")
}
ok, err := s.isStateValidatorMigrationOver()
if err != nil {
return nil, err
}
if ok {
protoState.Validators = validatorEntries
}
return statenative.InitializeFromProtoUnsafeBadger(protoState)
case hasElectraKey(enc):
protoState := &ethpb.BeaconStateElectra{}
if err := protoState.UnmarshalSSZ(enc[len(electraKey):]); err != nil {
Expand Down
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
PayloadToHeaderBadger = 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
37 changes: 36 additions & 1 deletion consensus-types/blocks/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,49 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
return nil, err
}

if b.version >= version.Badger {
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 := PayloadToHeaderBadger(payload)
if err != nil {
return nil, errors.Wrap(err, "payload to header badger")
}

return initBlindedSignedBlockFromProtoBadger(
&eth.SignedBlindedBeaconBlockBadger{
Message: &eth.BlindedBeaconBlockBadger{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyBadger{
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,
ExecutionPayloadHeader: header,
BlobKzgCommitments: b.block.body.blobKzgCommitments,
ExecutionRequests: b.block.body.executionRequests,
},
},
Signature: b.signature[:],
})
}

if b.version >= version.Alpaca {
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
3 changes: 1 addition & 2 deletions consensus-types/blocks/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,6 @@ func initBlindedBlockFromProtoBadger(pb *eth.BlindedBeaconBlockBadger) (*BeaconB
return b, nil
}


func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
Expand Down Expand Up @@ -1411,4 +1410,4 @@ func initBlindedBlockBodyFromProtoBadger(pb *eth.BlindedBeaconBlockBodyBadger) (
executionRequests: er,
}
return b, nil
}
}

0 comments on commit 24d1ba3

Please sign in to comment.