From b23aaa22aa01e4e4fed15bcb202d17025ba0aa5b Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Fri, 10 May 2024 09:15:11 +0100 Subject: [PATCH] Rebase and linting. --- api/v1/electra/generate.go | 1 + api/versionedproposal.go | 5 ++++- http/proposal.go | 10 ++++++++-- spec/electra/beaconstate_json.go | 12 ++++++------ spec/electra/executionpayloadheader_json.go | 4 +++- spec/electra/generate.go | 1 + spec/versionedsignedbeaconblock.go | 20 ++++++++++++++++---- util/electra/generate.go | 1 + 8 files changed, 40 insertions(+), 14 deletions(-) diff --git a/api/v1/electra/generate.go b/api/v1/electra/generate.go index 6274fdf8..a4d288cf 100644 --- a/api/v1/electra/generate.go +++ b/api/v1/electra/generate.go @@ -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 diff --git a/api/versionedproposal.go b/api/versionedproposal.go index 6f0cb9b3..bd1f713e 100644 --- a/api/versionedproposal.go +++ b/api/versionedproposal.go @@ -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 diff --git a/http/proposal.go b/http/proposal.go index d265f22f..80f08d56 100644 --- a/http/proposal.go +++ b/http/proposal.go @@ -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) diff --git a/spec/electra/beaconstate_json.go b/spec/electra/beaconstate_json.go index dfb59d02..f57c68bf 100644 --- a/spec/electra/beaconstate_json.go +++ b/spec/electra/beaconstate_json.go @@ -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 { @@ -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, diff --git a/spec/electra/executionpayloadheader_json.go b/spec/electra/executionpayloadheader_json.go index c63d1594..5d5ad8c9 100644 --- a/spec/electra/executionpayloadheader_json.go +++ b/spec/electra/executionpayloadheader_json.go @@ -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'}) diff --git a/spec/electra/generate.go b/spec/electra/generate.go index 113d8256..5e654957 100644 --- a/spec/electra/generate.go +++ b/spec/electra/generate.go @@ -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 diff --git a/spec/versionedsignedbeaconblock.go b/spec/versionedsignedbeaconblock.go index 55d98d12..62366aef 100644 --- a/spec/versionedsignedbeaconblock.go +++ b/spec/versionedsignedbeaconblock.go @@ -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") } @@ -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") } @@ -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") } @@ -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") } diff --git a/util/electra/generate.go b/util/electra/generate.go index cbd61a7d..08e6e537 100644 --- a/util/electra/generate.go +++ b/util/electra/generate.go @@ -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