Skip to content

Commit

Permalink
Merge pull request #137 from jtraglia/fix-api-v1-electra
Browse files Browse the repository at this point in the history
Use electra.AttesterSlashing in api/v1/electra
  • Loading branch information
mcdee authored May 8, 2024
2 parents 3117883 + fe247b6 commit 6fd8b5e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/v1/electra/blindedbeaconblockbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type BlindedBeaconBlockBody struct {
ETH1Data *phase0.ETH1Data
Graffiti [32]byte `ssz-size:"32"`
ProposerSlashings []*phase0.ProposerSlashing `ssz-max:"16"`
AttesterSlashings []*phase0.AttesterSlashing `ssz-max:"1"`
AttesterSlashings []*electra.AttesterSlashing `ssz-max:"1"`
Attestations []*electra.Attestation `ssz-max:"8"`
Deposits []*phase0.Deposit `ssz-max:"16"`
VoluntaryExits []*phase0.SignedVoluntaryExit `ssz-max:"16"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1/electra/blindedbeaconblockbody_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type blindedBeaconBlockBodyJSON struct {
ETH1Data *phase0.ETH1Data `json:"eth1_data"`
Graffiti string `json:"graffiti"`
ProposerSlashings []*phase0.ProposerSlashing `json:"proposer_slashings"`
AttesterSlashings []*phase0.AttesterSlashing `json:"attester_slashings"`
AttesterSlashings []*electra.AttesterSlashing `json:"attester_slashings"`
Attestations []*electra.Attestation `json:"attestations"`
Deposits []*phase0.Deposit `json:"deposits"`
VoluntaryExits []*phase0.SignedVoluntaryExit `json:"voluntary_exits"`
Expand Down
4 changes: 2 additions & 2 deletions api/v1/electra/blindedbeaconblockbody_ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/v1/electra/blindedbeaconblockbody_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type blindedBeaconBlockBodyYAML struct {
ETH1Data *phase0.ETH1Data `yaml:"eth1_data"`
Graffiti string `yaml:"graffiti"`
ProposerSlashings []*phase0.ProposerSlashing `yaml:"proposer_slashings"`
AttesterSlashings []*phase0.AttesterSlashing `yaml:"attester_slashings"`
AttesterSlashings []*electra.AttesterSlashing `yaml:"attester_slashings"`
Attestations []*electra.Attestation `yaml:"attestations"`
Deposits []*phase0.Deposit `yaml:"deposits"`
VoluntaryExits []*phase0.SignedVoluntaryExit `yaml:"voluntary_exits"`
Expand Down
42 changes: 37 additions & 5 deletions api/versionedsignedblindedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,32 +268,64 @@ func (v *VersionedSignedBlindedBeaconBlock) StateRoot() (phase0.Root, error) {
}

// AttesterSlashings returns the attester slashings of the beacon block.
func (v *VersionedSignedBlindedBeaconBlock) AttesterSlashings() ([]*phase0.AttesterSlashing, error) {
func (v *VersionedSignedBlindedBeaconBlock) AttesterSlashings() ([]spec.VersionedAttesterSlashing, error) {
switch v.Version {
case spec.DataVersionBellatrix:
if v.Bellatrix == nil {
return nil, ErrDataMissing
}

return v.Bellatrix.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Bellatrix.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Bellatrix.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionBellatrix,
Bellatrix: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionCapella:
if v.Capella == nil {
return nil, ErrDataMissing
}

return v.Capella.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Capella.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Capella.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionCapella,
Capella: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionDeneb:
if v.Deneb == nil {
return nil, ErrDataMissing
}

return v.Deneb.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Deneb.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Deneb.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionDeneb,
Deneb: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionElectra:
if v.Electra == nil {
return nil, ErrDataMissing
}

return v.Electra.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Electra.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Electra.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionElectra,
Electra: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
default:
return nil, ErrUnsupportedVersion
}
Expand Down
42 changes: 37 additions & 5 deletions api/versionedsignedblindedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,36 +276,68 @@ func (v *VersionedSignedBlindedProposal) StateRoot() (phase0.Root, error) {
}

// AttesterSlashings returns the attester slashings of the blinded proposal.
func (v *VersionedSignedBlindedProposal) AttesterSlashings() ([]*phase0.AttesterSlashing, error) {
func (v *VersionedSignedBlindedProposal) AttesterSlashings() ([]spec.VersionedAttesterSlashing, error) {
switch v.Version {
case spec.DataVersionBellatrix:
if v.Bellatrix == nil {
return nil, ErrDataMissing
}

return v.Bellatrix.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Bellatrix.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Bellatrix.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionBellatrix,
Bellatrix: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionCapella:
if v.Capella == nil {
return nil, ErrDataMissing
}

return v.Capella.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Capella.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Capella.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionCapella,
Capella: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionDeneb:
if v.Deneb == nil ||
v.Deneb.Message == nil ||
v.Deneb.Message.Body == nil {
return nil, ErrDataMissing
}

return v.Deneb.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Deneb.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Deneb.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionDeneb,
Deneb: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
case spec.DataVersionElectra:
if v.Electra == nil ||
v.Electra.Message == nil ||
v.Electra.Message.Body == nil {
return nil, ErrDataMissing
}

return v.Electra.Message.Body.AttesterSlashings, nil
versionedAttesterSlashings := make([]spec.VersionedAttesterSlashing, len(v.Electra.Message.Body.AttesterSlashings))
for i, attesterSlashing := range v.Electra.Message.Body.AttesterSlashings {
versionedAttesterSlashings[i] = spec.VersionedAttesterSlashing{
Version: spec.DataVersionElectra,
Electra: attesterSlashing,
}
}

return versionedAttesterSlashings, nil
default:
return nil, ErrUnsupportedVersion
}
Expand Down

0 comments on commit 6fd8b5e

Please sign in to comment.