Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electra minimal preset fixes & add Consolidations getter #140

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/holiman/uint256 v1.2.4
github.com/huandu/go-clone v1.6.0
github.com/huandu/go-clone/generic v1.6.0
github.com/pk910/dynamic-ssz v0.0.3
github.com/pk910/dynamic-ssz v0.0.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dz
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pk910/dynamic-ssz v0.0.3 h1:fCWzFowq9P6SYCc7NtJMkZcIHk+r5hSVD+32zVi6Aio=
github.com/pk910/dynamic-ssz v0.0.3/go.mod h1:b6CrLaB2X7pYA+OSEEbkgXDEcRnjLOZIxZTsMuO/Y9c=
github.com/pk910/dynamic-ssz v0.0.4 h1:DT29+1055tCEPCaR4V/ez+MOKW7BzBsmjyFvBRqx0ME=
github.com/pk910/dynamic-ssz v0.0.4/go.mod h1:b6CrLaB2X7pYA+OSEEbkgXDEcRnjLOZIxZTsMuO/Y9c=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
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
Loading