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

Use electra.AttesterSlashing in api/v1/electra #137

Merged
merged 1 commit into from
May 8, 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 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
Loading