Skip to content

Commit

Permalink
fix for decoding electra structs with minimal preset, add Consolidati…
Browse files Browse the repository at this point in the history
…ons() getter
  • Loading branch information
pk910 committed May 14, 2024
1 parent b23aaa2 commit 4d9677b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
7 changes: 6 additions & 1 deletion http/beaconstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ func (s *Service) beaconStateFromSSZ(ctx context.Context, res *httpResponse) (*a
}
case spec.DataVersionElectra:
response.Data.Electra = &electra.BeaconState{}
if err := response.Data.Electra.UnmarshalSSZ(res.body); err != nil {
if s.customSpecSupport {
err = dynSSZ.UnmarshalSSZ(response.Data.Electra, res.body)
} else {
err = response.Data.Electra.UnmarshalSSZ(res.body)
}
if err != nil {
return nil, errors.Join(errors.New("failed to decode electra beacon state"), err)
}
default:
Expand Down
12 changes: 10 additions & 2 deletions http/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,18 @@ func (s *Service) beaconBlockProposalFromSSZ(ctx context.Context,
case spec.DataVersionElectra:
if response.Data.Blinded {
response.Data.ElectraBlinded = &apiv1electra.BlindedBeaconBlock{}
err = response.Data.ElectraBlinded.UnmarshalSSZ(res.body)
if s.customSpecSupport {
err = dynSSZ.UnmarshalSSZ(response.Data.ElectraBlinded, res.body)
} else {
err = response.Data.ElectraBlinded.UnmarshalSSZ(res.body)
}
} else {
response.Data.Electra = &apiv1electra.BlockContents{}
err = response.Data.Electra.UnmarshalSSZ(res.body)
if s.customSpecSupport {
err = dynSSZ.UnmarshalSSZ(response.Data.Electra, res.body)
} else {
err = response.Data.Electra.UnmarshalSSZ(res.body)
}
}
default:
return nil, fmt.Errorf("unhandled block proposal version %s", res.consensusVersion)
Expand Down
9 changes: 7 additions & 2 deletions http/signedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ func (s *Service) signedBeaconBlockFromSSZ(ctx context.Context,
}
case spec.DataVersionElectra:
response.Data.Electra = &electra.SignedBeaconBlock{}
if err := response.Data.Electra.UnmarshalSSZ(res.body); err != nil {
return nil, errors.Join(errors.New("failed to decode electra signed block contents"), err)
if s.customSpecSupport {
err = dynSSZ.UnmarshalSSZ(response.Data.Electra, res.body)
} else {
err = response.Data.Electra.UnmarshalSSZ(res.body)
}
if err != nil {
return nil, errors.Join(errors.New("failed to decode deneb signed block contents"), err)
}
default:
return nil, fmt.Errorf("unhandled block version %s", res.consensusVersion)
Expand Down
24 changes: 24 additions & 0 deletions spec/versionedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,30 @@ func (v *VersionedBeaconBlock) ProposerSlashings() ([]*phase0.ProposerSlashing,
}
}

// Consolidations returns the consolidations of the beacon block.
func (v *VersionedBeaconBlock) Consolidations() ([]*electra.SignedConsolidation, error) {
switch v.Version {
case DataVersionPhase0:
return nil, errors.New("consolidations not available in phase0 block")
case DataVersionAltair:
return nil, errors.New("consolidations not available in altair block")
case DataVersionBellatrix:
return nil, errors.New("consolidations not available in bellatrix block")
case DataVersionCapella:
return nil, errors.New("consolidations not available in capella block")
case DataVersionDeneb:
return nil, errors.New("consolidations not available in deneb block")
case DataVersionElectra:
if v.Electra == nil || v.Electra.Body == nil {
return nil, errors.New("no electra block")
}

return v.Electra.Body.Consolidations, nil
default:
return nil, errors.New("unknown version")
}
}

// String returns a string version of the structure.
func (v *VersionedBeaconBlock) String() string {
switch v.Version {
Expand Down

0 comments on commit 4d9677b

Please sign in to comment.