Skip to content

Commit

Permalink
Rebase and linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 10, 2024
1 parent dae6e2b commit b23aaa2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/v1/electra/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package electra

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblockcontents_ssz.go
//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella,../../../spec/deneb,../../../spec/electra -path . --suffix ssz -objs BlindedBeaconBlock,BlindedBeaconBlockBody,BlockContents,SignedBlindedBeaconBlock,SignedBlockContents
Expand Down
5 changes: 4 additions & 1 deletion api/versionedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,10 @@ func (v *VersionedProposal) payloadPresent() bool {
return v.ElectraBlinded != nil && v.ElectraBlinded.Body != nil && v.ElectraBlinded.Body.ExecutionPayloadHeader != nil
}

return v.Electra != nil && v.Electra.Block != nil && v.Electra.Block.Body != nil && v.Electra.Block.Body.ExecutionPayload != nil
return v.Electra != nil &&
v.Electra.Block != nil &&
v.Electra.Block.Body != nil &&
v.Electra.Block.Body.ExecutionPayload != nil
}

return false
Expand Down
10 changes: 8 additions & 2 deletions http/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,15 @@ func (s *Service) beaconBlockProposalFromJSON(res *httpResponse) (*api.Response[
}
case spec.DataVersionElectra:
if response.Data.Blinded {
response.Data.ElectraBlinded, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), &apiv1electra.BlindedBeaconBlock{})
response.Data.ElectraBlinded, response.Metadata, err = decodeJSONResponse(
bytes.NewReader(res.body),
&apiv1electra.BlindedBeaconBlock{},
)
} else {
response.Data.Electra, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), &apiv1electra.BlockContents{})
response.Data.Electra, response.Metadata, err = decodeJSONResponse(
bytes.NewReader(res.body),
&apiv1electra.BlockContents{},
)
}
default:
err = fmt.Errorf("unsupported version %s", res.consensusVersion)
Expand Down
12 changes: 6 additions & 6 deletions spec/electra/beaconstate_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) {
for i := range b.Slashings {
slashings[i] = fmt.Sprintf("%d", b.Slashings[i])
}
PreviousEpochParticipation := make([]string, len(b.PreviousEpochParticipation))
previousEpochParticipation := make([]string, len(b.PreviousEpochParticipation))
for i := range b.PreviousEpochParticipation {
PreviousEpochParticipation[i] = fmt.Sprintf("%d", b.PreviousEpochParticipation[i])
previousEpochParticipation[i] = fmt.Sprintf("%d", b.PreviousEpochParticipation[i])
}
CurrentEpochParticipation := make([]string, len(b.CurrentEpochParticipation))
currentEpochParticipation := make([]string, len(b.CurrentEpochParticipation))
for i := range b.CurrentEpochParticipation {
CurrentEpochParticipation[i] = fmt.Sprintf("%d", b.CurrentEpochParticipation[i])
currentEpochParticipation[i] = fmt.Sprintf("%d", b.CurrentEpochParticipation[i])
}
inactivityScores := make([]string, len(b.InactivityScores))
for i := range b.InactivityScores {
Expand All @@ -112,8 +112,8 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) {
Balances: balances,
RANDAOMixes: randaoMixes,
Slashings: slashings,
PreviousEpochParticipation: PreviousEpochParticipation,
CurrentEpochParticipation: CurrentEpochParticipation,
PreviousEpochParticipation: previousEpochParticipation,
CurrentEpochParticipation: currentEpochParticipation,
JustificationBits: fmt.Sprintf("%#x", b.JustificationBits.Bytes()),
PreviousJustifiedCheckpoint: b.PreviousJustifiedCheckpoint,
CurrentJustifiedCheckpoint: b.CurrentJustifiedCheckpoint,
Expand Down
4 changes: 3 additions & 1 deletion spec/electra/executionpayloadheader_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (e *ExecutionPayloadHeader) UnmarshalJSON(input []byte) error {

var tmpBytes []byte
switch {
case bytes.Equal(raw["extra_data"], []byte{'0', 'x'}), bytes.Equal(raw["extra_data"], []byte{'0'}), bytes.Equal(raw["extra_data"], []byte{'"', '0', '"'}):
case bytes.Equal(raw["extra_data"], []byte{'0', 'x'}),
bytes.Equal(raw["extra_data"], []byte{'0'}),
bytes.Equal(raw["extra_data"], []byte{'"', '0', '"'}):
// Empty.
default:
tmpBytes = bytes.TrimPrefix(bytes.Trim(raw["extra_data"], `"`), []byte{'0', 'x'})
Expand Down
1 change: 1 addition & 0 deletions spec/electra/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package electra

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f aggregateandproof_ssz.go attestation_ssz.go attesterslashing_ssz.go beaconblockbody_ssz.go beaconblock_ssz.go beaconstate_ssz.go consolidation_ssz.go depositreceipt_ssz.go executionlayerwithdrawalrequest_ssz.go executionpayload_ssz.go executionpayloadheader_ssz.go pendingbalancedeposit_ssz.go pendingconsolidation_ssz.go pendingpartialwithdrawal_ssz.go signedaggregateandproof_ssz.go signedbeaconblock_ssz.go signedconsolidation_ssz.go
//go:generate sszgen --suffix=ssz --path . --include ../phase0,../altair,../bellatrix,../capella,../deneb --objs AggregateAndProof,Attestation,AttesterSlashing,BeaconBlockBody,BeaconBlock,BeaconState,Consolidation,DepositReceipt,ExecutionLayerWithdrawalRequest,ExecutionPayload,ExecutionPayloadHeader,PendingBalanceDeposit,PendingConsolidation,PendingPartialWithdrawal,SignedAggregateAndProof,SignedBeaconBlock,SignedConsolidation
Expand Down
20 changes: 16 additions & 4 deletions spec/versionedsignedbeaconblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ func (v *VersionedSignedBeaconBlock) ExecutionBlockHash() (phase0.Hash32, error)

return v.Deneb.Message.Body.ExecutionPayload.BlockHash, nil
case DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
if v.Electra == nil ||
v.Electra.Message == nil ||
v.Electra.Message.Body == nil ||
v.Electra.Message.Body.ExecutionPayload == nil {
return phase0.Hash32{}, errors.New("no deneb block")
}

Expand Down Expand Up @@ -190,7 +193,10 @@ func (v *VersionedSignedBeaconBlock) ExecutionBlockNumber() (uint64, error) {

return v.Deneb.Message.Body.ExecutionPayload.BlockNumber, nil
case DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
if v.Electra == nil ||
v.Electra.Message == nil ||
v.Electra.Message.Body == nil ||
v.Electra.Message.Body.ExecutionPayload == nil {
return 0, errors.New("no electra block")
}

Expand Down Expand Up @@ -232,7 +238,10 @@ func (v *VersionedSignedBeaconBlock) ExecutionTransactions() ([]bellatrix.Transa

return v.Deneb.Message.Body.ExecutionPayload.Transactions, nil
case DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
if v.Electra == nil ||
v.Electra.Message == nil ||
v.Electra.Message.Body == nil ||
v.Electra.Message.Body.ExecutionPayload == nil {
return nil, errors.New("no electra block")
}

Expand Down Expand Up @@ -967,7 +976,10 @@ func (v *VersionedSignedBeaconBlock) Withdrawals() ([]*capella.Withdrawal, error

return v.Deneb.Message.Body.ExecutionPayload.Withdrawals, nil
case DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
if v.Electra == nil ||
v.Electra.Message == nil ||
v.Electra.Message.Body == nil ||
v.Electra.Message.Body.ExecutionPayload == nil {
return nil, errors.New("no electra block")
}

Expand Down
1 change: 1 addition & 0 deletions util/electra/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package electra

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f depositreceipts_ssz.go withdrawalrequests_ssz.go
//go:generate sszgen -suffix ssz -include ../../spec/phase0,../../spec/bellatrix,../../spec/electra -path . -objs DepositReceipts,ExecutionPayloadWithdrawalRequests
Expand Down

0 comments on commit b23aaa2

Please sign in to comment.