diff --git a/go.mod b/go.mod index e7bb7283..60c23ab3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 758c6a71..6185469c 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/http/beaconstate.go b/http/beaconstate.go index ab3e6e34..7c46978e 100644 --- a/http/beaconstate.go +++ b/http/beaconstate.go @@ -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: diff --git a/http/proposal.go b/http/proposal.go index 80f08d56..ccab2683 100644 --- a/http/proposal.go +++ b/http/proposal.go @@ -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) diff --git a/http/signedbeaconblock.go b/http/signedbeaconblock.go index e231004d..45b9d06f 100644 --- a/http/signedbeaconblock.go +++ b/http/signedbeaconblock.go @@ -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) diff --git a/spec/versionedbeaconblock.go b/spec/versionedbeaconblock.go index f878ec9b..a390121c 100644 --- a/spec/versionedbeaconblock.go +++ b/spec/versionedbeaconblock.go @@ -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 {