diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 927ae79a..768ceb4e 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -4,18 +4,21 @@ on: branches: - master pull_request: + permissions: contents: read + jobs: golangci: name: lint - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '^1.20' - - uses: actions/checkout@v3 + cache: false + go-version: '1.20' + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: - version: latest + args: --timeout=60m diff --git a/.github/workflows/revive.yml b/.github/workflows/revive.yml new file mode 100644 index 00000000..60ef0b3a --- /dev/null +++ b/.github/workflows/revive.yml @@ -0,0 +1,20 @@ +name: revive +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + +jobs: + revive: + runs-on: ubuntu-22.04 + steps: + - uses: actions/setup-go@v5 + with: + cache: false + go-version: '1.20' + - uses: actions/checkout@v4 + - uses: morphy2k/revive-action@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d6983cc..4eafaa96 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,12 +6,14 @@ on: pull_request: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: '^1.20' - - uses: actions/checkout@v3 - - uses: n8maninger/action-golang-test@v1 + cache: false + go-version: '1.20' + - uses: actions/checkout@v4 + - uses: n8maninger/action-golang-test@v2 with: args: "-race;-timeout=30m" + diff --git a/.golangci.yml b/.golangci.yml index b896e60e..30a8a1c8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -109,6 +109,56 @@ linters-settings: lll: line-length: 132 + revive: + ignore-generated-header: true + severity: error + confidence: 0.1 + errorCode: 0 + warningCode: 0 + rules: + - name: atomic + - name: blank-imports + - name: comment-spacings + - name: confusing-results + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + - name: datarace + - name: defer + - name: dot-imports + - name: duplicated-imports + - name: early-return + - name: error-strings + - name: errorf + - name: exported + - name: file-header + - name: identical-branches + - name: import-alias-naming + - name: import-shadowing + - name: increment-decrement + - name: indent-error-flow + - name: modifies-value-receiver + - name: range-val-address + - name: range-val-in-closure + - name: range + - name: receiver-naming + - name: string-of-int + - name: superfluous-else + - name: time-equal + - name: time-naming + - name: unchecked-type-assertion + - name: unhandled-error + arguments: + - "fmt.Fprint" + - "fmt.Fprintf" + - name: unnecessary-stmt + - name: unused-parameter + - name: unused-receiver + - name: use-any + - name: useless-break + - name: var-naming + - name: waitgroup-by-value + stylecheck: checks: [ "all", "-ST1000" ] diff --git a/api/submitblindedproposalopts.go b/api/submitblindedproposalopts.go index 8355f47d..4edb2f3c 100644 --- a/api/submitblindedproposalopts.go +++ b/api/submitblindedproposalopts.go @@ -13,7 +13,7 @@ package api -import v2 "github.com/attestantio/go-eth2-client/api/v2" +import apiv2 "github.com/attestantio/go-eth2-client/api/v2" // SubmitBlindedProposalOpts are the options for submitting proposals. type SubmitBlindedProposalOpts struct { @@ -23,5 +23,5 @@ type SubmitBlindedProposalOpts struct { Proposal *VersionedSignedBlindedProposal // BroadcastValidation is the validation required of the consensus node before broadcasting the proposal. - BroadcastValidation *v2.BroadcastValidation + BroadcastValidation *apiv2.BroadcastValidation } diff --git a/api/submitproposalopts.go b/api/submitproposalopts.go index 48884913..fafe1984 100644 --- a/api/submitproposalopts.go +++ b/api/submitproposalopts.go @@ -13,7 +13,7 @@ package api -import v2 "github.com/attestantio/go-eth2-client/api/v2" +import apiv2 "github.com/attestantio/go-eth2-client/api/v2" // SubmitProposalOpts are the options for submitting proposals. type SubmitProposalOpts struct { @@ -23,5 +23,5 @@ type SubmitProposalOpts struct { Proposal *VersionedSignedProposal // BroadcastValidation is the validation required of the consensus node before broadcasting the proposal. - BroadcastValidation *v2.BroadcastValidation + BroadcastValidation *apiv2.BroadcastValidation } diff --git a/api/v1/capella/generate.go b/api/v1/capella/generate.go index 99ada52b..8262a319 100644 --- a/api/v1/capella/generate.go +++ b/api/v1/capella/generate.go @@ -16,5 +16,4 @@ package capella // Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work. //go:generate rm -f blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go //go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock -//nogo:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella --exclude-objs=blindedBeaconBlockBodyJSON,blindedBeaconBlockBodyYAML,blindedBeaconBlockJSON,blindedBeaconBlockYAML,signedBlindedBeaconBlockJSON,signedBlindedBeaconBlockYAML -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock //go:generate goimports -w blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go diff --git a/api/v1/deneb/blockcontents_yaml.go b/api/v1/deneb/blockcontents_yaml.go index 578fae5e..356e6e90 100644 --- a/api/v1/deneb/blockcontents_yaml.go +++ b/api/v1/deneb/blockcontents_yaml.go @@ -46,15 +46,15 @@ func (b *BlockContents) MarshalYAML() ([]byte, error) { // UnmarshalYAML implements yaml.Unmarshaler. func (b *BlockContents) UnmarshalYAML(input []byte) error { // We unmarshal to the JSON struct to save on duplicate code. - var data blockContentsJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled blockContentsJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/api/v1/deneb/signedblockcontents_yaml.go b/api/v1/deneb/signedblockcontents_yaml.go index 9daab627..f5a4ac0a 100644 --- a/api/v1/deneb/signedblockcontents_yaml.go +++ b/api/v1/deneb/signedblockcontents_yaml.go @@ -46,15 +46,15 @@ func (s *SignedBlockContents) MarshalYAML() ([]byte, error) { // UnmarshalYAML implements yaml.Unmarshaler. func (s *SignedBlockContents) UnmarshalYAML(input []byte) error { // We unmarshal to the JSON struct to save on duplicate code. - var data signedBlockContentsJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled signedBlockContentsJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return s.UnmarshalJSON(bytes) + return s.UnmarshalJSON(marshaled) } diff --git a/api/v1/event.go b/api/v1/event.go index 5de4ddb8..8a991d39 100644 --- a/api/v1/event.go +++ b/api/v1/event.go @@ -27,7 +27,7 @@ type Event struct { // Topic is the topic of the event. Topic string // Data is the data of the event. - Data interface{} + Data any } // SupportedEventTopics is a map of supported event topics. @@ -45,8 +45,8 @@ var SupportedEventTopics = map[string]bool{ // eventJSON is the spec representation of the struct. type eventJSON struct { - Topic string `json:"topic"` - Data map[string]interface{} `json:"data"` + Topic string `json:"topic"` + Data map[string]any `json:"data"` } // MarshalJSON implements json.Marshaler. @@ -56,7 +56,7 @@ func (e *Event) MarshalJSON() ([]byte, error) { if err != nil { return nil, errors.Wrap(err, "failed to marshal data") } - var unmarshalled map[string]interface{} + var unmarshalled map[string]any if err := json.Unmarshal(data, &unmarshalled); err != nil { return nil, errors.Wrap(err, "failed to unmarshal data") } diff --git a/api/v1/forkchoice.go b/api/v1/forkchoice.go index 1693810c..d890b4a9 100644 --- a/api/v1/forkchoice.go +++ b/api/v1/forkchoice.go @@ -173,20 +173,20 @@ type ForkChoiceNode struct { // ExecutiionBlockHash is the execution block hash of the node. ExecutionBlockHash phase0.Root // ExtraData is the extra data of the node. - ExtraData map[string]interface{} + ExtraData map[string]any } // forkChoiceNodeJSON is the json representation of the struct. type forkChoiceNodeJSON struct { - Slot string `json:"slot"` - BlockRoot string `json:"block_root"` - ParentRoot string `json:"parent_root"` - JustifiedEpoch string `json:"justified_epoch"` - FinalizedEpoch string `json:"finalized_epoch"` - Weight string `json:"weight"` - Validity string `json:"validity"` - ExecutionBlockHash string `json:"execution_block_hash"` - ExtraData map[string]interface{} `json:"extra_data,omitempty"` + Slot string `json:"slot"` + BlockRoot string `json:"block_root"` + ParentRoot string `json:"parent_root"` + JustifiedEpoch string `json:"justified_epoch"` + FinalizedEpoch string `json:"finalized_epoch"` + Weight string `json:"weight"` + Validity string `json:"validity"` + ExecutionBlockHash string `json:"execution_block_hash"` + ExtraData map[string]any `json:"extra_data,omitempty"` } // MarshalJSON implements json.Marshaler. diff --git a/api/versionedsignedproposal.go b/api/versionedsignedproposal.go index 41de741a..0993661e 100644 --- a/api/versionedsignedproposal.go +++ b/api/versionedsignedproposal.go @@ -43,7 +43,7 @@ type VersionedSignedProposal struct { DenebBlinded *apiv1deneb.SignedBlindedBeaconBlock } -// AssertPresnet throws an error if the expected proposal +// AssertPresent throws an error if the expected proposal // given the version and blinded fields is not present. func (v *VersionedSignedProposal) AssertPresent() error { switch v.Version { diff --git a/auto/service.go b/auto/service.go index 06920648..7bf31570 100644 --- a/auto/service.go +++ b/auto/service.go @@ -16,7 +16,7 @@ package auto import ( "context" - client "github.com/attestantio/go-eth2-client" + consensusclient "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/http" "github.com/pkg/errors" "github.com/rs/zerolog" @@ -28,7 +28,7 @@ var log zerolog.Logger // New creates a new Ethereum 2 client service, trying different implementations at the given address. // Deprecated. Use the `http` module instead. -func New(ctx context.Context, params ...Parameter) (client.Service, error) { +func New(ctx context.Context, params ...Parameter) (consensusclient.Service, error) { parameters, err := parseAndCheckParameters(params...) if err != nil { return nil, errors.Wrap(err, "problem with parameters") @@ -51,7 +51,7 @@ func New(ctx context.Context, params ...Parameter) (client.Service, error) { return nil, errors.New("failed to connect to Ethereum 2 client with any known method") } -func tryHTTP(ctx context.Context, parameters *parameters) (client.Service, error) { +func tryHTTP(ctx context.Context, parameters *parameters) (consensusclient.Service, error) { httpParameters := make([]http.Parameter, 0) httpParameters = append(httpParameters, http.WithLogLevel(parameters.logLevel)) httpParameters = append(httpParameters, http.WithAddress(parameters.address)) diff --git a/go.mod b/go.mod index fb3e3e48..8ba9d963 100644 --- a/go.mod +++ b/go.mod @@ -4,19 +4,20 @@ go 1.20 require ( github.com/ferranbt/fastssz v0.1.3 - github.com/goccy/go-yaml v1.9.2 + github.com/goccy/go-yaml v1.11.3 github.com/golang/snappy v0.0.4 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/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.16.0 - github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 + github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e github.com/r3labs/sse/v2 v2.10.0 github.com/rs/zerolog v1.32.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/otel v1.16.0 - golang.org/x/crypto v0.20.0 + go.opentelemetry.io/otel/trace v1.16.0 + golang.org/x/crypto v0.22.0 golang.org/x/sync v0.2.0 ) @@ -41,9 +42,8 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect - go.opentelemetry.io/otel/trace v1.16.0 // indirect golang.org/x/net v0.21.0 // indirect - golang.org/x/sys v0.17.0 // indirect + golang.org/x/sys v0.19.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect diff --git a/go.sum b/go.sum index 9ae03b72..1488e36e 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo= @@ -17,15 +16,11 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/goccy/go-yaml v1.9.2 h1:2Njwzw+0+pjU2gb805ZC1B/uBuAs2VcZ3K+ZgHwDs7w= -github.com/goccy/go-yaml v1.9.2/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= +github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I= +github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= @@ -50,11 +45,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -77,8 +69,8 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= -github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 h1:0tVE4tdWQK9ZpYygoV7+vS6QkDvQVySboMVEIxBJmXw= -github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7/go.mod h1:wmuf/mdK4VMD+jA9ThwcUKjg3a2XWM9cVfFYjDyY4j4= +github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e h1:ATgOe+abbzfx9kCPeXIW4fiWyDdxlwHw07j8UGhdTd4= +github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e/go.mod h1:wmuf/mdK4VMD+jA9ThwcUKjg3a2XWM9cVfFYjDyY4j4= github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= @@ -99,10 +91,8 @@ go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxx go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg= -golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= @@ -110,20 +100,14 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/http/attestationdata.go b/http/attestationdata.go index 3f490b20..8e73efa8 100644 --- a/http/attestationdata.go +++ b/http/attestationdata.go @@ -53,7 +53,7 @@ func (s *Service) AttestationData(ctx context.Context, } } -func (s *Service) attestationDataFromJSON(_ context.Context, +func (*Service) attestationDataFromJSON(_ context.Context, opts *api.AttestationDataOpts, httpResponse *httpResponse, ) ( diff --git a/http/attestationpool.go b/http/attestationpool.go index e6038c85..ab2b10b0 100644 --- a/http/attestationpool.go +++ b/http/attestationpool.go @@ -53,7 +53,7 @@ func (s *Service) AttestationPool(ctx context.Context, } } -func (s *Service) attestationPoolFromJSON(_ context.Context, +func (*Service) attestationPoolFromJSON(_ context.Context, opts *api.AttestationPoolOpts, httpResponse *httpResponse, ) ( diff --git a/http/beaconcommittees.go b/http/beaconcommittees.go index fef059bd..fe1e289d 100644 --- a/http/beaconcommittees.go +++ b/http/beaconcommittees.go @@ -20,7 +20,7 @@ import ( "fmt" client "github.com/attestantio/go-eth2-client" - api "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/api" apiv1 "github.com/attestantio/go-eth2-client/api/v1" ) diff --git a/http/beaconstate.go b/http/beaconstate.go index 0d62dfdd..6e61597b 100644 --- a/http/beaconstate.go +++ b/http/beaconstate.go @@ -62,7 +62,7 @@ func (s *Service) BeaconState(ctx context.Context, } } -func (s *Service) beaconStateFromSSZ(res *httpResponse) (*api.Response[*spec.VersionedBeaconState], error) { +func (*Service) beaconStateFromSSZ(res *httpResponse) (*api.Response[*spec.VersionedBeaconState], error) { response := &api.Response[*spec.VersionedBeaconState]{ Data: &spec.VersionedBeaconState{ Version: res.consensusVersion, @@ -103,7 +103,7 @@ func (s *Service) beaconStateFromSSZ(res *httpResponse) (*api.Response[*spec.Ver return response, nil } -func (s *Service) beaconStateFromJSON(res *httpResponse) (*api.Response[*spec.VersionedBeaconState], error) { +func (*Service) beaconStateFromJSON(res *httpResponse) (*api.Response[*spec.VersionedBeaconState], error) { response := &api.Response[*spec.VersionedBeaconState]{ Data: &spec.VersionedBeaconState{ Version: res.consensusVersion, diff --git a/http/blindedproposal.go b/http/blindedproposal.go index 11724fba..f1f8d143 100644 --- a/http/blindedproposal.go +++ b/http/blindedproposal.go @@ -108,7 +108,7 @@ func (s *Service) BlindedProposal(ctx context.Context, return response, nil } -func (s *Service) blindedProposalFromSSZ(res *httpResponse) (*api.Response[*api.VersionedBlindedProposal], error) { +func (*Service) blindedProposalFromSSZ(res *httpResponse) (*api.Response[*api.VersionedBlindedProposal], error) { response := &api.Response[*api.VersionedBlindedProposal]{ Data: &api.VersionedBlindedProposal{ Version: res.consensusVersion, @@ -139,7 +139,7 @@ func (s *Service) blindedProposalFromSSZ(res *httpResponse) (*api.Response[*api. return response, nil } -func (s *Service) blindedProposalFromJSON(res *httpResponse) (*api.Response[*api.VersionedBlindedProposal], error) { +func (*Service) blindedProposalFromJSON(res *httpResponse) (*api.Response[*api.VersionedBlindedProposal], error) { response := &api.Response[*api.VersionedBlindedProposal]{ Data: &api.VersionedBlindedProposal{ Version: res.consensusVersion, diff --git a/http/blobsidecars.go b/http/blobsidecars.go index 7743305c..d6f3cfe6 100644 --- a/http/blobsidecars.go +++ b/http/blobsidecars.go @@ -63,7 +63,7 @@ func (s *Service) BlobSidecars(ctx context.Context, return response, nil } -func (s *Service) blobSidecarsFromSSZ(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { +func (*Service) blobSidecarsFromSSZ(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { response := &api.Response[[]*deneb.BlobSidecar]{} data := &api.BlobSidecars{} @@ -76,7 +76,7 @@ func (s *Service) blobSidecarsFromSSZ(res *httpResponse) (*api.Response[[]*deneb return response, nil } -func (s *Service) blobSidecarsFromJSON(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { +func (*Service) blobSidecarsFromJSON(res *httpResponse) (*api.Response[[]*deneb.BlobSidecar], error) { response := &api.Response[[]*deneb.BlobSidecar]{} var err error diff --git a/http/errors.go b/http/errors.go new file mode 100644 index 00000000..53488092 --- /dev/null +++ b/http/errors.go @@ -0,0 +1,19 @@ +// Copyright © 2024 Attestant Limited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package http + +import "errors" + +// ErrIncorrectType is returned when the multi client obtain a response type it is not expecting. +var ErrIncorrectType = errors.New("incorrect response type") diff --git a/http/events.go b/http/events.go index 8d8ada7e..fbaaace8 100644 --- a/http/events.go +++ b/http/events.go @@ -25,7 +25,7 @@ import ( "strings" "time" - client "github.com/attestantio/go-eth2-client" + consensusclient "github.com/attestantio/go-eth2-client" api "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec/altair" "github.com/attestantio/go-eth2-client/spec/capella" @@ -35,12 +35,12 @@ import ( ) // Events feeds requested events with the given topics to the supplied handler. -func (s *Service) Events(ctx context.Context, topics []string, handler client.EventHandlerFunc) error { +func (s *Service) Events(ctx context.Context, topics []string, handler consensusclient.EventHandlerFunc) error { if err := s.assertIsActive(ctx); err != nil { return err } if len(topics) == 0 { - return errors.Join(errors.New("no topics supplied"), client.ErrInvalidOptions) + return errors.Join(errors.New("no topics supplied"), consensusclient.ErrInvalidOptions) } // #nosec G404 @@ -58,10 +58,10 @@ func (s *Service) Events(ctx context.Context, topics []string, handler client.Ev if err != nil { return errors.Join(errors.New("invalid endpoint"), err) } - url := s.base.ResolveReference(reference).String() - log.Trace().Str("url", url).Msg("GET request to events stream") + callURL := s.base.ResolveReference(reference).String() + log.Trace().Str("url", callURL).Msg("GET request to events stream") - client := sse.NewClient(url) + client := sse.NewClient(callURL) client.Connection.Transport = &http.Transport{ Dial: (&net.Dialer{ Timeout: 2 * time.Second, @@ -92,7 +92,7 @@ func (s *Service) Events(ctx context.Context, topics []string, handler client.Ev } // handleEvent parses an event and passes it on to the handler. -func (s *Service) handleEvent(ctx context.Context, msg *sse.Event, handler client.EventHandlerFunc) { +func (*Service) handleEvent(ctx context.Context, msg *sse.Event, handler consensusclient.EventHandlerFunc) { log := zerolog.Ctx(ctx) if handler == nil { diff --git a/http/farfutureepoch.go b/http/farfutureepoch.go index 19dc2b53..d15b10a7 100644 --- a/http/farfutureepoch.go +++ b/http/farfutureepoch.go @@ -20,6 +20,6 @@ import ( ) // FarFutureEpoch provides the values for FAR_FUTURE_EOPCH of the chain. -func (s *Service) FarFutureEpoch(_ context.Context) (phase0.Epoch, error) { +func (*Service) FarFutureEpoch(_ context.Context) (phase0.Epoch, error) { return phase0.Epoch(0xffffffffffffffff), nil } diff --git a/http/http.go b/http/http.go index cbe62c73..8e5c161f 100644 --- a/http/http.go +++ b/http/http.go @@ -47,11 +47,11 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io e.Str("body", string(bodyBytes)).Msg("POST request") } - url := urlForCall(s.base, endpoint, "") + callURL := urlForCall(s.base, endpoint, "") opCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() - req, err := http.NewRequestWithContext(opCtx, http.MethodPost, url.String(), body) + req, err := http.NewRequestWithContext(opCtx, http.MethodPost, callURL.String(), body) if err != nil { return nil, errors.Join(errors.New("failed to create POST request"), err) } @@ -65,7 +65,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io resp, err := s.client.Do(req) if err != nil { go s.CheckConnectionState(ctx) - s.monitorPostComplete(ctx, url.Path, "failed") + s.monitorPostComplete(ctx, callURL.Path, "failed") return nil, errors.Join(errors.New("failed to call POST endpoint"), err) } @@ -80,7 +80,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io if statusFamily != 2 { log.Debug().Int("status_code", resp.StatusCode).Str("data", string(data)).Msg("POST failed") - s.monitorPostComplete(ctx, url.Path, "failed") + s.monitorPostComplete(ctx, callURL.Path, "failed") return nil, &api.Error{ Method: http.MethodPost, @@ -91,7 +91,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io } log.Trace().Str("response", string(data)).Msg("POST response") - s.monitorPostComplete(ctx, url.Path, "succeeded") + s.monitorPostComplete(ctx, callURL.Path, "succeeded") return bytes.NewReader(data), nil } @@ -130,13 +130,13 @@ func (s *Service) post2(ctx context.Context, } } - url := urlForCall(s.base, endpoint, query) - log.Trace().Str("url", url.String()).Msg("URL to POST") - span.SetAttributes(attribute.String("url", url.String())) + callURL := urlForCall(s.base, endpoint, query) + log.Trace().Str("url", callURL.String()).Msg("URL to POST") + span.SetAttributes(attribute.String("url", callURL.String())) opCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() - req, err := http.NewRequestWithContext(opCtx, http.MethodPost, url.String(), body) + req, err := http.NewRequestWithContext(opCtx, http.MethodPost, callURL.String(), body) if err != nil { return nil, errors.Join(errors.New("failed to create POST request"), err) } @@ -165,7 +165,7 @@ func (s *Service) post2(ctx context.Context, } span.SetStatus(codes.Error, err.Error()) - s.monitorPostComplete(ctx, url.Path, "failed") + s.monitorPostComplete(ctx, callURL.Path, "failed") return nil, errors.Join(errors.New("failed to call POST endpoint"), err) } @@ -189,7 +189,7 @@ func (s *Service) post2(ctx context.Context, } span.SetStatus(codes.Error, err.Error()) - s.monitorPostComplete(ctx, url.Path, "failed") + s.monitorPostComplete(ctx, callURL.Path, "failed") return nil, errors.Join(errors.New("failed to read POST response"), err) } @@ -198,7 +198,7 @@ func (s *Service) post2(ctx context.Context, // Nothing returned. This is not considered an error. span.AddEvent("Received empty response") log.Trace().Msg("Endpoint returned no content") - s.monitorPostComplete(ctx, url.Path, "succeeded") + s.monitorPostComplete(ctx, callURL.Path, "succeeded") return res, nil } @@ -226,7 +226,7 @@ func (s *Service) post2(ctx context.Context, log.Debug().Int("status_code", resp.StatusCode).RawJSON("response", trimmedResponse).Msg("POST failed") span.SetStatus(codes.Error, fmt.Sprintf("Status code %d", resp.StatusCode)) - s.monitorPostComplete(ctx, url.Path, "failed") + s.monitorPostComplete(ctx, callURL.Path, "failed") return nil, &api.Error{ Method: http.MethodPost, @@ -236,7 +236,7 @@ func (s *Service) post2(ctx context.Context, } } - s.monitorPostComplete(ctx, url.Path, "succeeded") + s.monitorPostComplete(ctx, callURL.Path, "succeeded") return res, nil } @@ -276,9 +276,9 @@ func (s *Service) get(ctx context.Context, log := s.log.With().Str("id", fmt.Sprintf("%02x", rand.Int31())).Str("address", s.address).Str("endpoint", endpoint).Logger() log.Trace().Msg("GET request") - url := urlForCall(s.base, endpoint, query) - log.Trace().Str("url", url.String()).Msg("URL to GET") - span.SetAttributes(attribute.String("url", url.String())) + callURL := urlForCall(s.base, endpoint, query) + log.Trace().Str("url", callURL.String()).Msg("URL to GET") + span.SetAttributes(attribute.String("url", callURL.String())) timeout := s.timeout if opts.Timeout != 0 { @@ -287,7 +287,7 @@ func (s *Service) get(ctx context.Context, opCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - req, err := http.NewRequestWithContext(opCtx, http.MethodGet, url.String(), nil) + req, err := http.NewRequestWithContext(opCtx, http.MethodGet, callURL.String(), nil) if err != nil { span.SetStatus(codes.Error, "Failed to create request") @@ -310,7 +310,7 @@ func (s *Service) get(ctx context.Context, // We don't consider context canceled to be a potential connection issue, as the user canceled the context. case errors.Is(err, context.DeadlineExceeded): // We don't consider context deadline exceeded to be a potential connection issue, as the user selected the deadline. - case strings.HasSuffix(url.String(), "/node/syncing"): + case strings.HasSuffix(callURL.String(), "/node/syncing"): // Special case; if we have called the syncing endpoint and it failed then we don't check the connectino status, as // that calls the syncing endpoint itself and so we find ourselves in an endless loop. default: @@ -319,7 +319,7 @@ func (s *Service) get(ctx context.Context, } span.SetStatus(codes.Error, err.Error()) - s.monitorGetComplete(ctx, url.Path, "failed") + s.monitorGetComplete(ctx, callURL.Path, "failed") return nil, errors.Join(errors.New("failed to call GET endpoint"), err) } @@ -347,7 +347,7 @@ func (s *Service) get(ctx context.Context, } span.SetStatus(codes.Error, err.Error()) - s.monitorGetComplete(ctx, url.Path, "failed") + s.monitorGetComplete(ctx, callURL.Path, "failed") return nil, errors.Join(errors.New("failed to read GET response"), err) } @@ -356,7 +356,7 @@ func (s *Service) get(ctx context.Context, // Nothing returned. This is not considered an error. span.AddEvent("Received empty response") log.Trace().Msg("Endpoint returned no content") - s.monitorGetComplete(ctx, url.Path, "succeeded") + s.monitorGetComplete(ctx, callURL.Path, "succeeded") return res, nil } @@ -372,8 +372,8 @@ func (s *Service) get(ctx context.Context, )) if res.contentType == ContentTypeJSON { - trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(res.body, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{}) if e := log.Trace(); e.Enabled() { + trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(res.body, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{}) e.RawJSON("body", trimmedResponse).Msg("GET response") } } @@ -384,7 +384,7 @@ func (s *Service) get(ctx context.Context, log.Debug().Int("status_code", resp.StatusCode).RawJSON("response", trimmedResponse).Msg("GET failed") span.SetStatus(codes.Error, fmt.Sprintf("Status code %d", resp.StatusCode)) - s.monitorGetComplete(ctx, url.Path, "failed") + s.monitorGetComplete(ctx, callURL.Path, "failed") return nil, &api.Error{ Method: http.MethodGet, @@ -398,7 +398,7 @@ func (s *Service) get(ctx context.Context, return nil, errors.Join(errors.New("failed to parse consensus version"), err) } - s.monitorGetComplete(ctx, url.Path, "succeeded") + s.monitorGetComplete(ctx, callURL.Path, "succeeded") return res, nil } @@ -466,7 +466,10 @@ func metadataFromHeaders(headers map[string]string) map[string]any { } // urlForCall patches together a URL for a call. -func urlForCall(base *url.URL, endpoint string, query string) *url.URL { +func urlForCall(base *url.URL, + endpoint string, + query string, +) *url.URL { callURL := *base callURL.Path = endpoint if callURL.RawQuery == "" { diff --git a/http/json.go b/http/json.go index 43eb0c34..08997fab 100644 --- a/http/json.go +++ b/http/json.go @@ -21,7 +21,10 @@ func decodeJSONResponse[T any](body io.Reader, res T) (T, map[string]any, error) return res, nil, errors.Join(errors.New("failed to parse JSON"), err) } - data := clone.Clone(res).(T) + data, isCorrectType := clone.Clone(res).(T) + if !isCorrectType { + return res, nil, ErrIncorrectType + } metadata := make(map[string]any) for k, v := range decoded { switch k { diff --git a/http/proposal.go b/http/proposal.go index ca33eb80..f99dd816 100644 --- a/http/proposal.go +++ b/http/proposal.go @@ -224,7 +224,7 @@ func (s *Service) beaconBlockProposalFromJSON(res *httpResponse) (*api.Response[ return response, nil } -func (s *Service) populateProposalDataFromHeaders(response *api.Response[*api.VersionedProposal], +func (*Service) populateProposalDataFromHeaders(response *api.Response[*api.VersionedProposal], headers map[string]string, ) error { for k, v := range headers { diff --git a/http/service.go b/http/service.go index 7895230b..a0666ec6 100644 --- a/http/service.go +++ b/http/service.go @@ -48,7 +48,7 @@ type Service struct { // lifetime of a beacon node. genesis *apiv1.Genesis genesisMutex sync.RWMutex - spec map[string]interface{} + spec map[string]any specMutex sync.RWMutex depositContract *apiv1.DepositContract depositContractMutex sync.RWMutex @@ -230,7 +230,7 @@ func (s *Service) checkDVT(ctx context.Context) error { } // Name provides the name of the service. -func (s *Service) Name() string { +func (*Service) Name() string { return "Standard (HTTP)" } @@ -240,7 +240,7 @@ func (s *Service) Address() string { } // close closes the service, freeing up resources. -func (s *Service) close() { +func (*Service) close() { } // CheckConnectionState checks the connection state for the client, potentially updating diff --git a/http/signedbeaconblock.go b/http/signedbeaconblock.go index f4bc3c00..2070fa92 100644 --- a/http/signedbeaconblock.go +++ b/http/signedbeaconblock.go @@ -65,7 +65,7 @@ func (s *Service) SignedBeaconBlock(ctx context.Context, return response, nil } -func (s *Service) signedBeaconBlockFromSSZ(res *httpResponse) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { +func (*Service) signedBeaconBlockFromSSZ(res *httpResponse) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { response := &api.Response[*spec.VersionedSignedBeaconBlock]{ Data: &spec.VersionedSignedBeaconBlock{ Version: res.consensusVersion, @@ -106,7 +106,7 @@ func (s *Service) signedBeaconBlockFromSSZ(res *httpResponse) (*api.Response[*sp return response, nil } -func (s *Service) signedBeaconBlockFromJSON(res *httpResponse) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { +func (*Service) signedBeaconBlockFromJSON(res *httpResponse) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { response := &api.Response[*spec.VersionedSignedBeaconBlock]{ Data: &spec.VersionedSignedBeaconBlock{ Version: res.consensusVersion, diff --git a/http/signedbeaconblock_test.go b/http/signedbeaconblock_test.go index 14b83249..6086c826 100644 --- a/http/signedbeaconblock_test.go +++ b/http/signedbeaconblock_test.go @@ -15,6 +15,7 @@ package http_test import ( "context" + "errors" "os" "testing" @@ -51,8 +52,15 @@ func TestSignedBeaconBlock(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { response, err := service.(client.SignedBeaconBlockProvider).SignedBeaconBlock(ctx, test.opts) - require.NoError(t, err) - require.NotNil(t, response) + if err != nil { + // The beacon node we are talking to may not have the block. + var apiError *api.Error + require.True(t, errors.As(err, &apiError)) + require.Equal(t, 404, apiError.StatusCode) + } else { + require.NoError(t, err) + require.NotNil(t, response) + } }) } } diff --git a/http/slotduration.go b/http/slotduration.go index aaa8b608..7dac2959 100644 --- a/http/slotduration.go +++ b/http/slotduration.go @@ -31,5 +31,10 @@ func (s *Service) SlotDuration(ctx context.Context) (time.Duration, error) { return 0, err } - return response.Data["SECONDS_PER_SLOT"].(time.Duration), nil + res, isCorrectType := response.Data["SECONDS_PER_SLOT"].(time.Duration) + if !isCorrectType { + return 0, ErrIncorrectType + } + + return res, nil } diff --git a/http/slotsperepoch.go b/http/slotsperepoch.go index 95efc500..1bd0a797 100644 --- a/http/slotsperepoch.go +++ b/http/slotsperepoch.go @@ -30,5 +30,10 @@ func (s *Service) SlotsPerEpoch(ctx context.Context) (uint64, error) { return 0, err } - return response.Data["SLOTS_PER_EPOCH"].(uint64), nil + res, isCorrectType := response.Data["SLOTS_PER_EPOCH"].(uint64) + if !isCorrectType { + return 0, ErrIncorrectType + } + + return res, nil } diff --git a/http/stateid.go b/http/stateid.go index 390b3871..9421b1ae 100644 --- a/http/stateid.go +++ b/http/stateid.go @@ -25,7 +25,7 @@ import ( ) // SlotFromStateID parses the state ID and returns the relevant slot. -func (s *Service) SlotFromStateID(_ context.Context, stateID string) (phase0.Slot, error) { +func (*Service) SlotFromStateID(_ context.Context, stateID string) (phase0.Slot, error) { var slot phase0.Slot switch { case stateID == "genesis": diff --git a/http/submitbeaconblock_test.go b/http/submitbeaconblock_test.go index 58dab7c6..4cb260d8 100644 --- a/http/submitbeaconblock_test.go +++ b/http/submitbeaconblock_test.go @@ -1,4 +1,4 @@ -// Copyright © 2020, 2021 Attestant Limited. +// Copyright © 2020 - 2024 Attestant Limited. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -83,6 +83,13 @@ func TestSubmitBeaconBlock(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) + if res.Data.Version != spec.DataVersionPhase0 && + res.Data.Version != spec.DataVersionAltair && + res.Data.Version != spec.DataVersionBellatrix && + res.Data.Version != spec.DataVersionCapella { + t.Skip("proposal version not supported by endpoint, skipping test") + } + signedBeaconBlock := &spec.VersionedSignedBeaconBlock{} switch { case res.Data.Phase0 != nil: diff --git a/http/submitproposal.go b/http/submitproposal.go index 6580cd4d..0343093c 100644 --- a/http/submitproposal.go +++ b/http/submitproposal.go @@ -92,7 +92,7 @@ func (s *Service) submitProposalData(ctx context.Context, return body, contentType, nil } -func (s *Service) submitProposalJSON(_ context.Context, +func (*Service) submitProposalJSON(_ context.Context, proposal *api.VersionedSignedProposal, ) ( []byte, @@ -126,7 +126,7 @@ func (s *Service) submitProposalJSON(_ context.Context, return specJSON, nil } -func (s *Service) submitProposalSSZ(_ context.Context, +func (*Service) submitProposalSSZ(_ context.Context, proposal *api.VersionedSignedProposal, ) ( []byte, diff --git a/http/submitproposal_test.go b/http/submitproposal_test.go index 50be39bb..a80ecdb0 100644 --- a/http/submitproposal_test.go +++ b/http/submitproposal_test.go @@ -21,11 +21,13 @@ import ( client "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/api" + apiv1deneb "github.com/attestantio/go-eth2-client/api/v1/deneb" "github.com/attestantio/go-eth2-client/http" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/capella" + "github.com/attestantio/go-eth2-client/spec/deneb" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/stretchr/testify/require" ) @@ -109,6 +111,14 @@ func TestSubmitProposal(t *testing.T) { Message: res.Data.Capella, Signature: phase0.BLSSignature([96]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), } + case res.Data.Deneb != nil: + signedBeaconBlock.Version = spec.DataVersionDeneb + signedBeaconBlock.Deneb = &apiv1deneb.SignedBlockContents{ + SignedBlock: &deneb.SignedBeaconBlock{ + Message: res.Data.Deneb.Block, + Signature: phase0.BLSSignature([96]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), + }, + } default: t.Fatalf("unknown block version %s", res.Data.Version.String()) } diff --git a/http/submitvalidatorregistrations.go b/http/submitvalidatorregistrations.go index a36aa526..6ca41a37 100644 --- a/http/submitvalidatorregistrations.go +++ b/http/submitvalidatorregistrations.go @@ -35,7 +35,7 @@ func (s *Service) SubmitValidatorRegistrations(ctx context.Context, registration // Unwrap versioned registrations. var version *spec.BuilderVersion - var unversionedRegistrations []interface{} + var unversionedRegistrations []any for i := range registrations { if registrations[i] == nil { diff --git a/http/targetaggregatorspercommittee.go b/http/targetaggregatorspercommittee.go index dab1e5da..7b5b720c 100644 --- a/http/targetaggregatorspercommittee.go +++ b/http/targetaggregatorspercommittee.go @@ -30,5 +30,10 @@ func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, er return 0, err } - return response.Data["TARGET_AGGREGATORS_PER_COMMITTEE"].(uint64), nil + res, isCorrectType := response.Data["TARGET_AGGREGATORS_PER_COMMITTEE"].(uint64) + if !isCorrectType { + return 0, ErrIncorrectType + } + + return res, nil } diff --git a/http/validatorbalances.go b/http/validatorbalances.go index 24b45824..2a40fd0e 100644 --- a/http/validatorbalances.go +++ b/http/validatorbalances.go @@ -108,7 +108,7 @@ func (s *Service) chunkedValidatorBalances(ctx context.Context, }, nil } -func (s *Service) validatorBalancesFromJSON(_ context.Context, +func (*Service) validatorBalancesFromJSON(_ context.Context, httpResponse *httpResponse, ) ( *api.Response[map[phase0.ValidatorIndex]phase0.Gwei], diff --git a/mock/aggregateandproofdomain.go b/mock/aggregateandproofdomain.go index 06cd0639..ddfd1c10 100644 --- a/mock/aggregateandproofdomain.go +++ b/mock/aggregateandproofdomain.go @@ -20,6 +20,6 @@ import ( ) // AggregateAndProofDomain provides the aggregate and proof domain. -func (s *Service) AggregateAndProofDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) AggregateAndProofDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x06, 0x00, 0x00, 0x00}, nil } diff --git a/mock/aggregateattestation.go b/mock/aggregateattestation.go index 2d0bdc11..8f5765d1 100644 --- a/mock/aggregateattestation.go +++ b/mock/aggregateattestation.go @@ -21,7 +21,7 @@ import ( ) // AggregateAttestation fetches the aggregate attestation given an attestation. -func (s *Service) AggregateAttestation(_ context.Context, +func (*Service) AggregateAttestation(_ context.Context, _ *api.AggregateAttestationOpts, ) ( *api.Response[*phase0.Attestation], diff --git a/mock/attestationdata.go b/mock/attestationdata.go index c93d08f0..60af2756 100644 --- a/mock/attestationdata.go +++ b/mock/attestationdata.go @@ -21,7 +21,7 @@ import ( ) // AttestationData fetches the attestation data for the given slot and committee index. -func (s *Service) AttestationData(_ context.Context, +func (*Service) AttestationData(_ context.Context, _ *api.AttestationDataOpts, ) ( *api.Response[*phase0.AttestationData], diff --git a/mock/attestationpool.go b/mock/attestationpool.go index 9eb70c51..5f35c7df 100644 --- a/mock/attestationpool.go +++ b/mock/attestationpool.go @@ -21,7 +21,7 @@ import ( ) // AttestationPool fetches the attestation pool for the given slot. -func (s *Service) AttestationPool(_ context.Context, +func (*Service) AttestationPool(_ context.Context, _ *api.AttestationPoolOpts, ) ( *api.Response[[]*phase0.Attestation], diff --git a/mock/attesterduties.go b/mock/attesterduties.go index a0affcdb..e2150057 100644 --- a/mock/attesterduties.go +++ b/mock/attesterduties.go @@ -22,7 +22,7 @@ import ( // AttesterDuties obtains attester duties. // If validatorIndicess is nil it will return all duties for the given epoch. -func (s *Service) AttesterDuties(_ context.Context, opts *api.AttesterDutiesOpts) (*api.Response[[]*apiv1.AttesterDuty], error) { +func (*Service) AttesterDuties(_ context.Context, opts *api.AttesterDutiesOpts) (*api.Response[[]*apiv1.AttesterDuty], error) { data := make([]*apiv1.AttesterDuty, len(opts.Indices)) for i := range opts.Indices { data[i] = &apiv1.AttesterDuty{ diff --git a/mock/beaconattesterdomain.go b/mock/beaconattesterdomain.go index 0a0b42b6..e9133d5f 100644 --- a/mock/beaconattesterdomain.go +++ b/mock/beaconattesterdomain.go @@ -20,6 +20,6 @@ import ( ) // BeaconAttesterDomain provides the beacon attester domain. -func (s *Service) BeaconAttesterDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) BeaconAttesterDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x01, 0x00, 0x00, 0x00}, nil } diff --git a/mock/beaconblockheader.go b/mock/beaconblockheader.go index 9d9ff498..fab8cbbc 100644 --- a/mock/beaconblockheader.go +++ b/mock/beaconblockheader.go @@ -22,7 +22,7 @@ import ( ) // BeaconBlockHeader provides the block header of a given block ID. -func (s *Service) BeaconBlockHeader(_ context.Context, +func (*Service) BeaconBlockHeader(_ context.Context, _ *api.BeaconBlockHeaderOpts, ) ( *api.Response[*apiv1.BeaconBlockHeader], diff --git a/mock/beaconblockroot.go b/mock/beaconblockroot.go index 142e45ff..50b7c388 100644 --- a/mock/beaconblockroot.go +++ b/mock/beaconblockroot.go @@ -21,7 +21,7 @@ import ( ) // BeaconBlockRoot fetches a block's root given a block ID. -func (s *Service) BeaconBlockRoot(_ context.Context, +func (*Service) BeaconBlockRoot(_ context.Context, _ *api.BeaconBlockRootOpts, ) ( *api.Response[*phase0.Root], diff --git a/mock/beaconcommittees.go b/mock/beaconcommittees.go index 14ae33d3..f9592ad9 100644 --- a/mock/beaconcommittees.go +++ b/mock/beaconcommittees.go @@ -21,7 +21,7 @@ import ( ) // BeaconCommittees fetches all beacon committees for the epoch at the given state. -func (s *Service) BeaconCommittees(_ context.Context, +func (*Service) BeaconCommittees(_ context.Context, _ *api.BeaconCommitteesOpts, ) ( *api.Response[[]*apiv1.BeaconCommittee], diff --git a/mock/beaconproposerdomain.go b/mock/beaconproposerdomain.go index 93cd4a94..33447cbb 100644 --- a/mock/beaconproposerdomain.go +++ b/mock/beaconproposerdomain.go @@ -20,6 +20,6 @@ import ( ) // BeaconProposerDomain provides the beacon proposer domain. -func (s *Service) BeaconProposerDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) BeaconProposerDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x00, 0x00, 0x00, 0x00}, nil } diff --git a/mock/beaconstate.go b/mock/beaconstate.go index f65db42c..54b9994a 100644 --- a/mock/beaconstate.go +++ b/mock/beaconstate.go @@ -22,7 +22,7 @@ import ( ) // BeaconState fetches a beacon state given a state ID. -func (s *Service) BeaconState(_ context.Context, _ *api.BeaconStateOpts) (*api.Response[*spec.VersionedBeaconState], error) { +func (*Service) BeaconState(_ context.Context, _ *api.BeaconStateOpts) (*api.Response[*spec.VersionedBeaconState], error) { data := &spec.VersionedBeaconState{ Version: spec.DataVersionPhase0, Phase0: &phase0.BeaconState{ diff --git a/mock/beaconstateroot.go b/mock/beaconstateroot.go index 0a0c1f3d..85fda59d 100644 --- a/mock/beaconstateroot.go +++ b/mock/beaconstateroot.go @@ -21,7 +21,7 @@ import ( ) // BeaconStateRoot fetches a beacon state's root given a state ID. -func (s *Service) BeaconStateRoot(_ context.Context, _ *api.BeaconStateRootOpts) (*api.Response[*phase0.Root], error) { +func (*Service) BeaconStateRoot(_ context.Context, _ *api.BeaconStateRootOpts) (*api.Response[*phase0.Root], error) { data := phase0.Root{} return &api.Response[*phase0.Root]{ diff --git a/mock/blindedproposal.go b/mock/blindedproposal.go index bd66eeec..d62c28cc 100644 --- a/mock/blindedproposal.go +++ b/mock/blindedproposal.go @@ -24,7 +24,7 @@ import ( ) // BlindedProposal fetches a blinded proposal for signing. -func (s *Service) BlindedProposal(_ context.Context, +func (*Service) BlindedProposal(_ context.Context, opts *api.BlindedProposalOpts, ) ( *api.Response[*api.VersionedBlindedProposal], @@ -97,11 +97,11 @@ func (s *Service) BlindedProposal(_ context.Context, }, }, Graffiti: opts.Graffiti, - ProposerSlashings: []*phase0.ProposerSlashing{}, - AttesterSlashings: []*phase0.AttesterSlashing{}, + ProposerSlashings: make([]*phase0.ProposerSlashing, 0), + AttesterSlashings: make([]*phase0.AttesterSlashing, 0), Attestations: attestations, - Deposits: []*phase0.Deposit{}, - VoluntaryExits: []*phase0.SignedVoluntaryExit{}, + Deposits: make([]*phase0.Deposit, 0), + VoluntaryExits: make([]*phase0.SignedVoluntaryExit, 0), }, } diff --git a/mock/depositcontract.go b/mock/depositcontract.go index dcb4746a..9c73e2e0 100644 --- a/mock/depositcontract.go +++ b/mock/depositcontract.go @@ -21,7 +21,7 @@ import ( ) // DepositContract provides details of the execution layer deposit contract for the chain. -func (s *Service) DepositContract(_ context.Context, _ *api.DepositContractOpts) (*api.Response[*apiv1.DepositContract], error) { +func (*Service) DepositContract(_ context.Context, _ *api.DepositContractOpts) (*api.Response[*apiv1.DepositContract], error) { return &api.Response[*apiv1.DepositContract]{ Data: &apiv1.DepositContract{}, Metadata: make(map[string]any), diff --git a/mock/depositdomain.go b/mock/depositdomain.go index 369d607a..94edbb66 100644 --- a/mock/depositdomain.go +++ b/mock/depositdomain.go @@ -20,6 +20,6 @@ import ( ) // DepositDomain provides the deposit domain. -func (s *Service) DepositDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) DepositDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x03, 0x00, 0x00, 0x00}, nil } diff --git a/mock/events.go b/mock/events.go index a16750b1..37d13f18 100644 --- a/mock/events.go +++ b/mock/events.go @@ -20,6 +20,6 @@ import ( ) // Events feeds requested events with the given topics to the supplied handler. -func (s *Service) Events(_ context.Context, _ []string, _ client.EventHandlerFunc) error { +func (*Service) Events(_ context.Context, _ []string, _ client.EventHandlerFunc) error { return nil } diff --git a/mock/farfutureepoch.go b/mock/farfutureepoch.go index 3a43a9a3..da1057f8 100644 --- a/mock/farfutureepoch.go +++ b/mock/farfutureepoch.go @@ -20,6 +20,6 @@ import ( ) // FarFutureEpoch provides the values for FAR_FUTURE_EOPCH of the chain. -func (s *Service) FarFutureEpoch(_ context.Context) (spec.Epoch, error) { +func (*Service) FarFutureEpoch(_ context.Context) (spec.Epoch, error) { return spec.Epoch(0xffffffffffffffff), nil } diff --git a/mock/finality.go b/mock/finality.go index 812f054f..edd0255e 100644 --- a/mock/finality.go +++ b/mock/finality.go @@ -22,7 +22,7 @@ import ( ) // Finality provides the finality given a state ID. -func (s *Service) Finality(_ context.Context, _ *api.FinalityOpts) (*api.Response[*apiv1.Finality], error) { +func (*Service) Finality(_ context.Context, _ *api.FinalityOpts) (*api.Response[*apiv1.Finality], error) { return &api.Response[*apiv1.Finality]{ Data: &apiv1.Finality{ Finalized: &phase0.Checkpoint{ diff --git a/mock/forkschedule.go b/mock/forkschedule.go index 32bef4bf..acbf3d40 100644 --- a/mock/forkschedule.go +++ b/mock/forkschedule.go @@ -21,7 +21,7 @@ import ( ) // ForkSchedule provides details of past and future changes in the chain's fork version. -func (s *Service) ForkSchedule(_ context.Context, _ *api.ForkScheduleOpts) (*api.Response[[]*spec.Fork], error) { +func (*Service) ForkSchedule(_ context.Context, _ *api.ForkScheduleOpts) (*api.Response[[]*spec.Fork], error) { data := []*spec.Fork{ { PreviousVersion: spec.Version{0x01, 0x02, 0x03, 0x04}, diff --git a/mock/nodepeers.go b/mock/nodepeers.go index 42cf85b4..5f7c1172 100644 --- a/mock/nodepeers.go +++ b/mock/nodepeers.go @@ -21,7 +21,7 @@ import ( ) // NodePeers provides the peers of the node. -func (s *Service) NodePeers(_ context.Context, _ *api.NodePeersOpts) (*api.Response[[]*apiv1.Peer], error) { +func (*Service) NodePeers(_ context.Context, _ *api.NodePeersOpts) (*api.Response[[]*apiv1.Peer], error) { return &api.Response[[]*apiv1.Peer]{ Data: []*apiv1.Peer{{ PeerID: "MOCK16Uiu2HAm7ukVy4XugqVShYbLih4H2jBJjYevevznBZaHsmd1FM96", diff --git a/mock/proposal.go b/mock/proposal.go index fb679a0a..b70e17fb 100644 --- a/mock/proposal.go +++ b/mock/proposal.go @@ -23,7 +23,7 @@ import ( ) // Proposal fetches a proposal for signing. -func (s *Service) Proposal(_ context.Context, +func (*Service) Proposal(_ context.Context, opts *api.ProposalOpts, ) ( *api.Response[*api.VersionedProposal], error, @@ -95,11 +95,11 @@ func (s *Service) Proposal(_ context.Context, }, }, Graffiti: opts.Graffiti, - ProposerSlashings: []*phase0.ProposerSlashing{}, - AttesterSlashings: []*phase0.AttesterSlashing{}, + ProposerSlashings: make([]*phase0.ProposerSlashing, 0), + AttesterSlashings: make([]*phase0.AttesterSlashing, 0), Attestations: attestations, - Deposits: []*phase0.Deposit{}, - VoluntaryExits: []*phase0.SignedVoluntaryExit{}, + Deposits: make([]*phase0.Deposit, 0), + VoluntaryExits: make([]*phase0.SignedVoluntaryExit, 0), }, } diff --git a/mock/proposerduties.go b/mock/proposerduties.go index 7a3f6db6..cdea0cc1 100644 --- a/mock/proposerduties.go +++ b/mock/proposerduties.go @@ -22,7 +22,7 @@ import ( // ProposerDuties obtains proposer duties for the given epoch. // If validatorIndices is empty all duties are returned, otherwise only matching duties are returned. -func (s *Service) ProposerDuties(_ context.Context, opts *api.ProposerDutiesOpts) (*api.Response[[]*apiv1.ProposerDuty], error) { +func (*Service) ProposerDuties(_ context.Context, opts *api.ProposerDutiesOpts) (*api.Response[[]*apiv1.ProposerDuty], error) { data := make([]*apiv1.ProposerDuty, len(opts.Indices)) for i := range opts.Indices { data[i] = &apiv1.ProposerDuty{ diff --git a/mock/randaodomain.go b/mock/randaodomain.go index 86a9937a..315a3093 100644 --- a/mock/randaodomain.go +++ b/mock/randaodomain.go @@ -20,6 +20,6 @@ import ( ) // RANDAODomain provides the RANDAO domain. -func (s *Service) RANDAODomain(_ context.Context) (spec.DomainType, error) { +func (*Service) RANDAODomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x02, 0x00, 0x00, 0x00}, nil } diff --git a/mock/selectionproofdomain.go b/mock/selectionproofdomain.go index 3d62a3eb..6d9d561f 100644 --- a/mock/selectionproofdomain.go +++ b/mock/selectionproofdomain.go @@ -20,6 +20,6 @@ import ( ) // SelectionProofDomain provides the selection proof domain. -func (s *Service) SelectionProofDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) SelectionProofDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x05, 0x00, 0x00, 0x00}, nil } diff --git a/mock/service.go b/mock/service.go index a94efa09..6662a1f9 100644 --- a/mock/service.go +++ b/mock/service.go @@ -76,7 +76,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { } // Close the service on context done. - go func(s *Service) { + go func(*Service) { <-ctx.Done() log.Trace().Msg("Context done; closing connection") s.close() @@ -105,7 +105,7 @@ func (s *Service) fetchStaticValues(ctx context.Context) error { } // Name provides the name of the service. -func (s *Service) Name() string { +func (*Service) Name() string { return "Mock" } @@ -115,7 +115,7 @@ func (s *Service) Address() string { } // IsActive returns true if the client is active. -func (s *Service) IsActive() bool { +func (*Service) IsActive() bool { return true } @@ -125,5 +125,5 @@ func (s *Service) IsSynced() bool { } // close closes the service, freeing up resources. -func (s *Service) close() { +func (*Service) close() { } diff --git a/mock/signedbeaconblock.go b/mock/signedbeaconblock.go index b653a189..5dc997c1 100644 --- a/mock/signedbeaconblock.go +++ b/mock/signedbeaconblock.go @@ -22,7 +22,7 @@ import ( ) // SignedBeaconBlock fetches a signed beacon block given a block ID. -func (s *Service) SignedBeaconBlock(_ context.Context, _ *api.SignedBeaconBlockOpts) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { +func (*Service) SignedBeaconBlock(_ context.Context, _ *api.SignedBeaconBlockOpts) (*api.Response[*spec.VersionedSignedBeaconBlock], error) { return &api.Response[*spec.VersionedSignedBeaconBlock]{ Data: &spec.VersionedSignedBeaconBlock{ Version: spec.DataVersionPhase0, diff --git a/mock/slotduration.go b/mock/slotduration.go index 7ac46a29..8a4350a6 100644 --- a/mock/slotduration.go +++ b/mock/slotduration.go @@ -19,6 +19,6 @@ import ( ) // SlotDuration provides the duration of a slot of the chain. -func (s *Service) SlotDuration(_ context.Context) (time.Duration, error) { +func (*Service) SlotDuration(_ context.Context) (time.Duration, error) { return 12 * time.Second, nil } diff --git a/mock/slotsperepoch.go b/mock/slotsperepoch.go index 736729fc..f9f8730d 100644 --- a/mock/slotsperepoch.go +++ b/mock/slotsperepoch.go @@ -18,6 +18,6 @@ import ( ) // SlotsPerEpoch provides the slots per epoch of the chain. -func (s *Service) SlotsPerEpoch(_ context.Context) (uint64, error) { +func (*Service) SlotsPerEpoch(_ context.Context) (uint64, error) { return 32, nil } diff --git a/mock/spec.go b/mock/spec.go index e776565a..f83e3d0c 100644 --- a/mock/spec.go +++ b/mock/spec.go @@ -22,7 +22,7 @@ import ( // Spec provides the spec information of the chain. // This returns various useful values. -func (s *Service) Spec(_ context.Context, _ *api.SpecOpts) (*api.Response[map[string]any], error) { +func (*Service) Spec(_ context.Context, _ *api.SpecOpts) (*api.Response[map[string]any], error) { data := map[string]any{ "SECONDS_PER_SLOT": 12 * time.Second, "SLOTS_PER_EPOCH": uint64(32), diff --git a/mock/submitaggregateattestations.go b/mock/submitaggregateattestations.go index 0b62c959..8e20adba 100644 --- a/mock/submitaggregateattestations.go +++ b/mock/submitaggregateattestations.go @@ -20,6 +20,6 @@ import ( ) // SubmitAggregateAttestations submits aggregate attestations. -func (s *Service) SubmitAggregateAttestations(_ context.Context, _ []*spec.SignedAggregateAndProof) error { +func (*Service) SubmitAggregateAttestations(_ context.Context, _ []*spec.SignedAggregateAndProof) error { return nil } diff --git a/mock/submitattestations.go b/mock/submitattestations.go index 255fd5f9..699def7b 100644 --- a/mock/submitattestations.go +++ b/mock/submitattestations.go @@ -20,6 +20,6 @@ import ( ) // SubmitAttestations submits attestations. -func (s *Service) SubmitAttestations(_ context.Context, _ []*spec.Attestation) error { +func (*Service) SubmitAttestations(_ context.Context, _ []*spec.Attestation) error { return nil } diff --git a/mock/submitattesterslashing.go b/mock/submitattesterslashing.go index 849b999a..fe418bff 100644 --- a/mock/submitattesterslashing.go +++ b/mock/submitattesterslashing.go @@ -20,6 +20,6 @@ import ( ) // SubmitAttesterSlashing submits a proposal slashing. -func (s *Service) SubmitAttesterSlashing(_ context.Context, _ *phase0.AttesterSlashing) error { +func (*Service) SubmitAttesterSlashing(_ context.Context, _ *phase0.AttesterSlashing) error { return nil } diff --git a/mock/submitbeaconblock.go b/mock/submitbeaconblock.go index ab8d11e6..7882fb72 100644 --- a/mock/submitbeaconblock.go +++ b/mock/submitbeaconblock.go @@ -16,10 +16,10 @@ package mock import ( "context" - spec "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec" ) // SubmitBeaconBlock submits a beacon block. -func (s *Service) SubmitBeaconBlock(_ context.Context, _ *spec.VersionedSignedBeaconBlock) error { +func (*Service) SubmitBeaconBlock(_ context.Context, _ *spec.VersionedSignedBeaconBlock) error { return nil } diff --git a/mock/submitbeaconcommitteesubscriptions.go b/mock/submitbeaconcommitteesubscriptions.go index 81d21304..63d3aba0 100644 --- a/mock/submitbeaconcommitteesubscriptions.go +++ b/mock/submitbeaconcommitteesubscriptions.go @@ -20,6 +20,6 @@ import ( ) // SubmitBeaconCommitteeSubscriptions subscribes to beacon committees. -func (s *Service) SubmitBeaconCommitteeSubscriptions(_ context.Context, _ []*api.BeaconCommitteeSubscription) error { +func (*Service) SubmitBeaconCommitteeSubscriptions(_ context.Context, _ []*api.BeaconCommitteeSubscription) error { return nil } diff --git a/mock/submitblindedbeaconblock.go b/mock/submitblindedbeaconblock.go index c26486cb..97e40676 100644 --- a/mock/submitblindedbeaconblock.go +++ b/mock/submitblindedbeaconblock.go @@ -20,6 +20,6 @@ import ( ) // SubmitBlindedBeaconBlock submits a blinded beacon block. -func (s *Service) SubmitBlindedBeaconBlock(_ context.Context, _ *api.VersionedSignedBlindedBeaconBlock) error { +func (*Service) SubmitBlindedBeaconBlock(_ context.Context, _ *api.VersionedSignedBlindedBeaconBlock) error { return nil } diff --git a/mock/submitblstoexecutionchange.go b/mock/submitblstoexecutionchange.go index 73f9289d..8cd2b8ef 100644 --- a/mock/submitblstoexecutionchange.go +++ b/mock/submitblstoexecutionchange.go @@ -20,6 +20,6 @@ import ( ) // SubmitBLSToExecutionChange submits a BLS to execution address change operation. -func (s *Service) SubmitBLSToExecutionChange(_ context.Context, _ *capella.SignedBLSToExecutionChange) error { +func (*Service) SubmitBLSToExecutionChange(_ context.Context, _ *capella.SignedBLSToExecutionChange) error { return nil } diff --git a/mock/submitproposal.go b/mock/submitproposal.go index 700e532d..d1b0f067 100644 --- a/mock/submitproposal.go +++ b/mock/submitproposal.go @@ -20,6 +20,6 @@ import ( ) // SubmitProposal submits a proposal. -func (s *Service) SubmitProposal(_ context.Context, _ *api.VersionedSignedProposal) error { +func (*Service) SubmitProposal(_ context.Context, _ *api.VersionedSignedProposal) error { return nil } diff --git a/mock/submitproposalpreparations.go b/mock/submitproposalpreparations.go index b6db8859..28648afa 100644 --- a/mock/submitproposalpreparations.go +++ b/mock/submitproposalpreparations.go @@ -21,6 +21,6 @@ import ( // SubmitProposalPreparations provides the beacon node with information required if a proposal for the given validators // shows up in the next epoch. -func (s *Service) SubmitProposalPreparations(_ context.Context, _ []*apiv1.ProposalPreparation) error { +func (*Service) SubmitProposalPreparations(_ context.Context, _ []*apiv1.ProposalPreparation) error { return nil } diff --git a/mock/submitproposalslashing.go b/mock/submitproposalslashing.go index bf821caf..5a1cd501 100644 --- a/mock/submitproposalslashing.go +++ b/mock/submitproposalslashing.go @@ -20,6 +20,6 @@ import ( ) // SubmitProposalSlashing submits a proposal slashing. -func (s *Service) SubmitProposalSlashing(_ context.Context, _ *phase0.ProposerSlashing) error { +func (*Service) SubmitProposalSlashing(_ context.Context, _ *phase0.ProposerSlashing) error { return nil } diff --git a/mock/submitsynccommitteecontributions.go b/mock/submitsynccommitteecontributions.go index e4cc9cc2..d17b1962 100644 --- a/mock/submitsynccommitteecontributions.go +++ b/mock/submitsynccommitteecontributions.go @@ -20,6 +20,6 @@ import ( ) // SubmitSyncCommitteeContributions submits sync committee contributions. -func (s *Service) SubmitSyncCommitteeContributions(_ context.Context, _ []*altair.SignedContributionAndProof) error { +func (*Service) SubmitSyncCommitteeContributions(_ context.Context, _ []*altair.SignedContributionAndProof) error { return nil } diff --git a/mock/submitsynccommitteemessages.go b/mock/submitsynccommitteemessages.go index 8915d845..d3174758 100644 --- a/mock/submitsynccommitteemessages.go +++ b/mock/submitsynccommitteemessages.go @@ -20,6 +20,6 @@ import ( ) // SubmitSyncCommitteeMessages submits sync committee messages. -func (s *Service) SubmitSyncCommitteeMessages(_ context.Context, _ []*altair.SyncCommitteeMessage) error { +func (*Service) SubmitSyncCommitteeMessages(_ context.Context, _ []*altair.SyncCommitteeMessage) error { return nil } diff --git a/mock/submitsynccommitteesubscriptions.go b/mock/submitsynccommitteesubscriptions.go index 47ce291d..381a829e 100644 --- a/mock/submitsynccommitteesubscriptions.go +++ b/mock/submitsynccommitteesubscriptions.go @@ -20,6 +20,6 @@ import ( ) // SubmitSyncCommitteeSubscriptions subscribes to sync committees. -func (s *Service) SubmitSyncCommitteeSubscriptions(_ context.Context, _ []*api.SyncCommitteeSubscription) error { +func (*Service) SubmitSyncCommitteeSubscriptions(_ context.Context, _ []*api.SyncCommitteeSubscription) error { return nil } diff --git a/mock/submitvalidatorregistration.go b/mock/submitvalidatorregistration.go index c7def11f..7eadf8aa 100644 --- a/mock/submitvalidatorregistration.go +++ b/mock/submitvalidatorregistration.go @@ -20,6 +20,6 @@ import ( ) // SubmitValidatorRegistrations submits a validator registration. -func (s *Service) SubmitValidatorRegistrations(_ context.Context, _ []*api.VersionedSignedValidatorRegistration) error { +func (*Service) SubmitValidatorRegistrations(_ context.Context, _ []*api.VersionedSignedValidatorRegistration) error { return nil } diff --git a/mock/submitvoluntaryexit.go b/mock/submitvoluntaryexit.go index 56d71c8a..d195a90a 100644 --- a/mock/submitvoluntaryexit.go +++ b/mock/submitvoluntaryexit.go @@ -20,6 +20,6 @@ import ( ) // SubmitVoluntaryExit submits a voluntary exit. -func (s *Service) SubmitVoluntaryExit(_ context.Context, _ *spec.SignedVoluntaryExit) error { +func (*Service) SubmitVoluntaryExit(_ context.Context, _ *spec.SignedVoluntaryExit) error { return nil } diff --git a/mock/synccommittee.go b/mock/synccommittee.go index 2e9d8d6f..da68438d 100644 --- a/mock/synccommittee.go +++ b/mock/synccommittee.go @@ -21,7 +21,7 @@ import ( ) // SyncCommittee fetches the sync committee for the given state. -func (s *Service) SyncCommittee(_ context.Context, _ *api.SyncCommitteeOpts) (*api.Response[*apiv1.SyncCommittee], error) { +func (*Service) SyncCommittee(_ context.Context, _ *api.SyncCommitteeOpts) (*api.Response[*apiv1.SyncCommittee], error) { return &api.Response[*apiv1.SyncCommittee]{ Data: &apiv1.SyncCommittee{}, Metadata: make(map[string]any), diff --git a/mock/synccommitteecontributionprovider.go b/mock/synccommitteecontributionprovider.go index ae9814e1..e6dbbc41 100644 --- a/mock/synccommitteecontributionprovider.go +++ b/mock/synccommitteecontributionprovider.go @@ -23,7 +23,7 @@ import ( ) // SyncCommitteeContribution provides a sync committee contribution. -func (s *Service) SyncCommitteeContribution(_ context.Context, _ *api.SyncCommitteeContributionOpts) (*api.Response[*altair.SyncCommitteeContribution], error) { +func (*Service) SyncCommitteeContribution(_ context.Context, _ *api.SyncCommitteeContributionOpts) (*api.Response[*altair.SyncCommitteeContribution], error) { return &api.Response[*altair.SyncCommitteeContribution]{ Data: &altair.SyncCommitteeContribution{ Slot: 5, diff --git a/mock/synccommitteeduties.go b/mock/synccommitteeduties.go index 53d31efa..7988f390 100644 --- a/mock/synccommitteeduties.go +++ b/mock/synccommitteeduties.go @@ -21,7 +21,7 @@ import ( ) // SyncCommitteeDuties obtains sync committee duties. -func (s *Service) SyncCommitteeDuties(_ context.Context, opts *api.SyncCommitteeDutiesOpts) (*api.Response[[]*apiv1.SyncCommitteeDuty], error) { +func (*Service) SyncCommitteeDuties(_ context.Context, opts *api.SyncCommitteeDutiesOpts) (*api.Response[[]*apiv1.SyncCommitteeDuty], error) { data := make([]*apiv1.SyncCommitteeDuty, len(opts.Indices)) for i := range opts.Indices { data[i] = &apiv1.SyncCommitteeDuty{ diff --git a/mock/targetaggregatorspercommittee.go b/mock/targetaggregatorspercommittee.go index 4cc0f9aa..4f4113a5 100644 --- a/mock/targetaggregatorspercommittee.go +++ b/mock/targetaggregatorspercommittee.go @@ -18,6 +18,6 @@ import ( ) // TargetAggregatorsPerCommittee provides the target number of aggregators for each attestation committee. -func (s *Service) TargetAggregatorsPerCommittee(_ context.Context) (uint64, error) { +func (*Service) TargetAggregatorsPerCommittee(_ context.Context) (uint64, error) { return 4, nil } diff --git a/mock/validatorbalances.go b/mock/validatorbalances.go index 719efb8a..d2658613 100644 --- a/mock/validatorbalances.go +++ b/mock/validatorbalances.go @@ -24,7 +24,7 @@ import ( // stateID can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized". // validatorIndices is a list of validator indices to restrict the returned values. If no validators are supplied no filter // will be applied. -func (s *Service) ValidatorBalances(_ context.Context, _ *api.ValidatorBalancesOpts) (*api.Response[map[phase0.ValidatorIndex]phase0.Gwei], error) { +func (*Service) ValidatorBalances(_ context.Context, _ *api.ValidatorBalancesOpts) (*api.Response[map[phase0.ValidatorIndex]phase0.Gwei], error) { return &api.Response[map[phase0.ValidatorIndex]phase0.Gwei]{ Data: map[phase0.ValidatorIndex]phase0.Gwei{}, Metadata: make(map[string]any), diff --git a/mock/validators.go b/mock/validators.go index 9c75f701..e8bb30c9 100644 --- a/mock/validators.go +++ b/mock/validators.go @@ -22,7 +22,7 @@ import ( ) // Validators provides the validators, with their balance and status, for a given state. -func (s *Service) Validators(_ context.Context, _ *api.ValidatorsOpts) (*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator], error) { +func (*Service) Validators(_ context.Context, _ *api.ValidatorsOpts) (*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator], error) { return &api.Response[map[phase0.ValidatorIndex]*apiv1.Validator]{ Data: map[phase0.ValidatorIndex]*apiv1.Validator{}, Metadata: make(map[string]any), diff --git a/mock/voluntaryexitdomain.go b/mock/voluntaryexitdomain.go index 90c94b41..cbbc508b 100644 --- a/mock/voluntaryexitdomain.go +++ b/mock/voluntaryexitdomain.go @@ -20,6 +20,6 @@ import ( ) // VoluntaryExitDomain provides the voluntary exit domain. -func (s *Service) VoluntaryExitDomain(_ context.Context) (spec.DomainType, error) { +func (*Service) VoluntaryExitDomain(_ context.Context) (spec.DomainType, error) { return spec.DomainType{0x04, 0x00, 0x00, 0x00}, nil } diff --git a/mock/voluntaryexitpool.go b/mock/voluntaryexitpool.go index 22c1a313..dff81050 100644 --- a/mock/voluntaryexitpool.go +++ b/mock/voluntaryexitpool.go @@ -21,7 +21,7 @@ import ( ) // VoluntaryExitPool fetches the voluntary exit pool. -func (s *Service) VoluntaryExitPool(_ context.Context, _ *api.VoluntaryExitPoolOpts) (*api.Response[[]*spec.SignedVoluntaryExit], error) { +func (*Service) VoluntaryExitPool(_ context.Context, _ *api.VoluntaryExitPoolOpts) (*api.Response[[]*spec.SignedVoluntaryExit], error) { res := make([]*spec.SignedVoluntaryExit, 5) for i := 0; i < 5; i++ { res[i] = &spec.SignedVoluntaryExit{ diff --git a/multi/aggregateattestation.go b/multi/aggregateattestation.go index 0f6d3c20..ff0f7f8d 100644 --- a/multi/aggregateattestation.go +++ b/multi/aggregateattestation.go @@ -28,7 +28,7 @@ func (s *Service) AggregateAttestation(ctx context.Context, *api.Response[*phase0.Attestation], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { aggregate, err := client.(consensusclient.AggregateAttestationProvider).AggregateAttestation(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) AggregateAttestation(ctx context.Context, return nil, err } - return res.(*api.Response[*phase0.Attestation]), nil + response, isResponse := res.(*api.Response[*phase0.Attestation]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/attestationdata.go b/multi/attestationdata.go index ce9f627e..0c825396 100644 --- a/multi/attestationdata.go +++ b/multi/attestationdata.go @@ -28,7 +28,7 @@ func (s *Service) AttestationData(ctx context.Context, *api.Response[*phase0.AttestationData], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { attestationData, err := client.(consensusclient.AttestationDataProvider).AttestationData(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) AttestationData(ctx context.Context, return nil, err } - return res.(*api.Response[*phase0.AttestationData]), nil + response, isResponse := res.(*api.Response[*phase0.AttestationData]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/attestationpool.go b/multi/attestationpool.go index 46bc2f3f..0228fbba 100644 --- a/multi/attestationpool.go +++ b/multi/attestationpool.go @@ -28,7 +28,7 @@ func (s *Service) AttestationPool(ctx context.Context, *api.Response[[]*phase0.Attestation], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { attestationPool, err := client.(consensusclient.AttestationPoolProvider).AttestationPool(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) AttestationPool(ctx context.Context, return nil, err } - return res.(*api.Response[[]*phase0.Attestation]), nil + response, isResponse := res.(*api.Response[[]*phase0.Attestation]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/attesterduties.go b/multi/attesterduties.go index 3483af80..de0d0ce1 100644 --- a/multi/attesterduties.go +++ b/multi/attesterduties.go @@ -29,7 +29,7 @@ func (s *Service) AttesterDuties(ctx context.Context, *api.Response[[]*apiv1.AttesterDuty], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.AttesterDutiesProvider).AttesterDuties(ctx, opts) if err != nil { return nil, err @@ -41,5 +41,10 @@ func (s *Service) AttesterDuties(ctx context.Context, return nil, err } - return res.(*api.Response[[]*apiv1.AttesterDuty]), nil + response, isResponse := res.(*api.Response[[]*apiv1.AttesterDuty]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/beaconblockheader.go b/multi/beaconblockheader.go index ceb255bf..1ebb8844 100644 --- a/multi/beaconblockheader.go +++ b/multi/beaconblockheader.go @@ -28,7 +28,7 @@ func (s *Service) BeaconBlockHeader(ctx context.Context, *api.Response[*apiv1.BeaconBlockHeader], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { beaconBlockHeader, err := client.(consensusclient.BeaconBlockHeadersProvider).BeaconBlockHeader(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) BeaconBlockHeader(ctx context.Context, return nil, err } - return res.(*api.Response[*apiv1.BeaconBlockHeader]), nil + response, isResponse := res.(*api.Response[*apiv1.BeaconBlockHeader]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/beaconblockroot.go b/multi/beaconblockroot.go index 98bdbb1c..f3a2e32f 100644 --- a/multi/beaconblockroot.go +++ b/multi/beaconblockroot.go @@ -28,7 +28,7 @@ func (s *Service) BeaconBlockRoot(ctx context.Context, *api.Response[*phase0.Root], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { root, err := client.(consensusclient.BeaconBlockRootProvider).BeaconBlockRoot(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) BeaconBlockRoot(ctx context.Context, return nil, err } - return res.(*api.Response[*phase0.Root]), nil + response, isResponse := res.(*api.Response[*phase0.Root]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/beaconcommittees.go b/multi/beaconcommittees.go index d6b1eae0..ad7145b2 100644 --- a/multi/beaconcommittees.go +++ b/multi/beaconcommittees.go @@ -28,7 +28,7 @@ func (s *Service) BeaconCommittees(ctx context.Context, *api.Response[[]*apiv1.BeaconCommittee], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { beaconCommittees, err := client.(consensusclient.BeaconCommitteesProvider).BeaconCommittees(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) BeaconCommittees(ctx context.Context, return nil, err } - return res.(*api.Response[[]*apiv1.BeaconCommittee]), nil + response, isResponse := res.(*api.Response[[]*apiv1.BeaconCommittee]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/beaconstate.go b/multi/beaconstate.go index 91c718bb..b2bd8150 100644 --- a/multi/beaconstate.go +++ b/multi/beaconstate.go @@ -23,7 +23,7 @@ import ( // BeaconState fetches a beacon state. func (s *Service) BeaconState(ctx context.Context, opts *api.BeaconStateOpts) (*api.Response[*spec.VersionedBeaconState], error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { beaconState, err := client.(consensusclient.BeaconStateProvider).BeaconState(ctx, opts) if err != nil { return nil, err @@ -35,5 +35,10 @@ func (s *Service) BeaconState(ctx context.Context, opts *api.BeaconStateOpts) (* return nil, err } - return res.(*api.Response[*spec.VersionedBeaconState]), nil + response, isResponse := res.(*api.Response[*spec.VersionedBeaconState]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/blobsidecars.go b/multi/blobsidecars.go index 941fe4fb..ddcdcb60 100644 --- a/multi/blobsidecars.go +++ b/multi/blobsidecars.go @@ -22,8 +22,12 @@ import ( ) // BlobSidecars fetches the blob sidecars given options. -func (s *Service) BlobSidecars(ctx context.Context, opts *api.BlobSidecarsOpts) ([]*deneb.BlobSidecar, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { +func (s *Service) BlobSidecars(ctx context.Context, + opts *api.BlobSidecarsOpts, +) (*api.Response[[]*deneb.BlobSidecar], + error, +) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { blobSidecars, err := client.(consensusclient.BlobSidecarsProvider).BlobSidecars(ctx, opts) if err != nil { return nil, err @@ -34,9 +38,11 @@ func (s *Service) BlobSidecars(ctx context.Context, opts *api.BlobSidecarsOpts) if err != nil { return nil, err } - if res == nil { - return nil, nil + + response, isResponse := res.(*api.Response[[]*deneb.BlobSidecar]) + if !isResponse { + return nil, ErrIncorrectType } - return res.([]*deneb.BlobSidecar), nil + return response, nil } diff --git a/multi/client.go b/multi/client.go index 86c3a135..ecc748a6 100644 --- a/multi/client.go +++ b/multi/client.go @@ -129,7 +129,7 @@ func (s *Service) activateClient(ctx context.Context, client consensusclient.Ser // callFunc is the definition for a call function. It provides a generic return interface // to allow the caller to unpick the results as it sees fit. -type callFunc func(ctx context.Context, client consensusclient.Service) (interface{}, error) +type callFunc func(ctx context.Context, client consensusclient.Service) (any, error) // errHandlerFunc is the definition for an error handler function. It looks at the error // returned from the client, potentially rewrites it, and also states if the error should @@ -137,7 +137,7 @@ type callFunc func(ctx context.Context, client consensusclient.Service) (interfa type errHandlerFunc func(ctx context.Context, client consensusclient.Service, err error) (bool, error) // doCall carries out a call on the active clients in turn until one succeeds. -func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandlerFunc) (interface{}, error) { +func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandlerFunc) (any, error) { log := s.log.With().Logger() ctx = log.WithContext(ctx) @@ -159,7 +159,7 @@ func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandl } var err error - var res interface{} + var res any for _, client := range activeClients { res, err = call(ctx, client) if err != nil { @@ -209,7 +209,7 @@ func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandl // providerInfo returns information on the provider. // Currently this just returns the name of the service (lighthouse/teku/etc.). -func (s *Service) providerInfo(ctx context.Context, provider consensusclient.Service) string { +func (*Service) providerInfo(ctx context.Context, provider consensusclient.Service) string { providerName := "" nodeVersionProvider, isNodeVersionProvider := provider.(consensusclient.NodeVersionProvider) if isNodeVersionProvider { diff --git a/multi/client_internal_test.go b/multi/client_internal_test.go index dbef8e1c..7c2095bc 100644 --- a/multi/client_internal_test.go +++ b/multi/client_internal_test.go @@ -53,7 +53,7 @@ func TestDeactivateMulti(t *testing.T) { multi := s.(*Service) var wg sync.WaitGroup - starter := make(chan interface{}) + starter := make(chan any) for i := 0; i < 256; i++ { wg.Add(1) go func() { @@ -100,7 +100,7 @@ func TestActivateMulti(t *testing.T) { multi.deactivateClient(ctx, erroringClient2) var wg sync.WaitGroup - starter := make(chan interface{}) + starter := make(chan any) for i := 0; i < 256; i++ { wg.Add(1) go func() { diff --git a/multi/depositcontract.go b/multi/depositcontract.go index 98999a0e..06210e3d 100644 --- a/multi/depositcontract.go +++ b/multi/depositcontract.go @@ -28,7 +28,7 @@ func (s *Service) DepositContract(ctx context.Context, *api.Response[*apiv1.DepositContract], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { aggregate, err := client.(consensusclient.DepositContractProvider).DepositContract(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) DepositContract(ctx context.Context, return nil, err } - return res.(*api.Response[*apiv1.DepositContract]), nil + response, isResponse := res.(*api.Response[*apiv1.DepositContract]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/domain.go b/multi/domain.go index 7aab8d85..69ec7c7c 100644 --- a/multi/domain.go +++ b/multi/domain.go @@ -33,7 +33,7 @@ func (s *Service) Domain(ctx context.Context, phase0.Domain, error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { domain, err := client.(consensusclient.DomainProvider).Domain(ctx, domainType, epoch) if err != nil { return nil, err @@ -48,7 +48,12 @@ func (s *Service) Domain(ctx context.Context, return phase0.Domain{}, err } - return res.(phase0.Domain), nil + response, isResponse := res.(phase0.Domain) + if !isResponse { + return phase0.Domain{}, ErrIncorrectType + } + + return response, nil } // GenesisDomain provides a domain for a given domain type. @@ -58,7 +63,7 @@ func (s *Service) GenesisDomain(ctx context.Context, phase0.Domain, error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { domain, err := client.(consensusclient.DomainProvider).GenesisDomain(ctx, domainType) if err != nil { return nil, err @@ -73,5 +78,10 @@ func (s *Service) GenesisDomain(ctx context.Context, return phase0.Domain{}, err } - return res.(phase0.Domain), nil + response, isResponse := res.(phase0.Domain) + if !isResponse { + return phase0.Domain{}, ErrIncorrectType + } + + return response, nil } diff --git a/multi/errors.go b/multi/errors.go new file mode 100644 index 00000000..0324cafc --- /dev/null +++ b/multi/errors.go @@ -0,0 +1,19 @@ +// Copyright © 2024 Attestant Limited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package multi + +import "errors" + +// ErrIncorrectType is returned when the multi client obtain a response type it is not expecting. +var ErrIncorrectType = errors.New("incorrect response type") diff --git a/multi/farfutureepoch.go b/multi/farfutureepoch.go index 6ed1efc5..63d6cfe3 100644 --- a/multi/farfutureepoch.go +++ b/multi/farfutureepoch.go @@ -23,7 +23,7 @@ import ( // FarFutureEpoch provides the far future epoch of the chain. func (s *Service) FarFutureEpoch(ctx context.Context) (phase0.Epoch, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { epoch, err := client.(consensusclient.FarFutureEpochProvider).FarFutureEpoch(ctx) if err != nil { return nil, err @@ -38,5 +38,10 @@ func (s *Service) FarFutureEpoch(ctx context.Context) (phase0.Epoch, error) { return 0, err } - return res.(phase0.Epoch), nil + response, isResponse := res.(phase0.Epoch) + if !isResponse { + return 0, ErrIncorrectType + } + + return response, nil } diff --git a/multi/finality.go b/multi/finality.go index 54bb0eb8..94ad4dc1 100644 --- a/multi/finality.go +++ b/multi/finality.go @@ -23,7 +23,7 @@ import ( // Finality provides the finality given a state ID. func (s *Service) Finality(ctx context.Context, opts *api.FinalityOpts) (*api.Response[*apiv1.Finality], error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { finality, err := client.(consensusclient.FinalityProvider).Finality(ctx, opts) if err != nil { return nil, err @@ -35,5 +35,10 @@ func (s *Service) Finality(ctx context.Context, opts *api.FinalityOpts) (*api.Re return nil, err } - return res.(*api.Response[*apiv1.Finality]), nil + response, isResponse := res.(*api.Response[*apiv1.Finality]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/fork.go b/multi/fork.go index 060377a3..8500b111 100644 --- a/multi/fork.go +++ b/multi/fork.go @@ -28,7 +28,7 @@ func (s *Service) Fork(ctx context.Context, *api.Response[*phase0.Fork], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { fork, err := client.(consensusclient.ForkProvider).Fork(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) Fork(ctx context.Context, return nil, err } - return res.(*api.Response[*phase0.Fork]), nil + response, isResponse := res.(*api.Response[*phase0.Fork]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/forkchoice.go b/multi/forkchoice.go new file mode 100644 index 00000000..c34c8036 --- /dev/null +++ b/multi/forkchoice.go @@ -0,0 +1,49 @@ +// Copyright © 2024 Attestant Limited. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package multi + +import ( + "context" + + consensusclient "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" + apiv1 "github.com/attestantio/go-eth2-client/api/v1" +) + +// ForkChoice fetches all current fork choice context. +func (s *Service) ForkChoice(ctx context.Context, + opts *api.ForkChoiceOpts, +) ( + *api.Response[*apiv1.ForkChoice], + error, +) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { + aggregate, err := client.(consensusclient.ForkChoiceProvider).ForkChoice(ctx, opts) + if err != nil { + return nil, err + } + + return aggregate, nil + }, nil) + if err != nil { + return nil, err + } + + response, isResponse := res.(*api.Response[*apiv1.ForkChoice]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil +} diff --git a/multi/forkschedule.go b/multi/forkschedule.go index 08b910bc..1b645f61 100644 --- a/multi/forkschedule.go +++ b/multi/forkschedule.go @@ -28,7 +28,7 @@ func (s *Service) ForkSchedule(ctx context.Context, *api.Response[[]*phase0.Fork], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { forkSchedule, err := client.(consensusclient.ForkScheduleProvider).ForkSchedule(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) ForkSchedule(ctx context.Context, return nil, err } - return res.(*api.Response[[]*phase0.Fork]), nil + response, isResponse := res.(*api.Response[[]*phase0.Fork]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/genesis.go b/multi/genesis.go index d6cf002e..cb067469 100644 --- a/multi/genesis.go +++ b/multi/genesis.go @@ -28,7 +28,7 @@ func (s *Service) Genesis(ctx context.Context, *api.Response[*apiv1.Genesis], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { genesis, err := client.(consensusclient.GenesisProvider).Genesis(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) Genesis(ctx context.Context, return nil, err } - return res.(*api.Response[*apiv1.Genesis]), nil + response, isResponse := res.(*api.Response[*apiv1.Genesis]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/genesistime.go b/multi/genesistime.go index 6a8c7a30..0e7b8ac5 100644 --- a/multi/genesistime.go +++ b/multi/genesistime.go @@ -25,7 +25,7 @@ import ( // // Deprecated: use Genesis(). func (s *Service) GenesisTime(ctx context.Context) (time.Time, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { genesisTime, err := client.(consensusclient.GenesisTimeProvider).GenesisTime(ctx) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) GenesisTime(ctx context.Context) (time.Time, error) { return time.Time{}, err } - return res.(time.Time), nil + response, isResponse := res.(time.Time) + if !isResponse { + return time.Time{}, ErrIncorrectType + } + + return response, nil } diff --git a/multi/nodepeers.go b/multi/nodepeers.go index 085f22d0..5dd7316d 100644 --- a/multi/nodepeers.go +++ b/multi/nodepeers.go @@ -23,7 +23,7 @@ import ( // NodePeers provides the peers of the node. func (s *Service) NodePeers(ctx context.Context, opts *api.NodePeersOpts) (*api.Response[[]*apiv1.Peer], error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { nodePeers, err := client.(consensusclient.NodePeersProvider).NodePeers(ctx, opts) if err != nil { return nil, err @@ -35,5 +35,10 @@ func (s *Service) NodePeers(ctx context.Context, opts *api.NodePeersOpts) (*api. return nil, err } - return res.(*api.Response[[]*apiv1.Peer]), nil + response, isResponse := res.(*api.Response[[]*apiv1.Peer]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/nodesyncing.go b/multi/nodesyncing.go index 760827b2..118d21b3 100644 --- a/multi/nodesyncing.go +++ b/multi/nodesyncing.go @@ -28,7 +28,7 @@ func (s *Service) NodeSyncing(ctx context.Context, *api.Response[*apiv1.SyncState], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { nodeSyncing, err := client.(consensusclient.NodeSyncingProvider).NodeSyncing(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) NodeSyncing(ctx context.Context, return nil, err } - return res.(*api.Response[*apiv1.SyncState]), nil + response, isResponse := res.(*api.Response[*apiv1.SyncState]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/nodeversion.go b/multi/nodeversion.go index a5d21ef0..eb4008e0 100644 --- a/multi/nodeversion.go +++ b/multi/nodeversion.go @@ -22,7 +22,7 @@ import ( // NodeVersion provides the version information of the node. func (s *Service) NodeVersion(ctx context.Context, opts *api.NodeVersionOpts) (*api.Response[string], error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { aggregate, err := client.(consensusclient.NodeVersionProvider).NodeVersion(ctx, opts) if err != nil { return nil, err @@ -34,5 +34,10 @@ func (s *Service) NodeVersion(ctx context.Context, opts *api.NodeVersionOpts) (* return nil, err } - return res.(*api.Response[string]), nil + response, isResponse := res.(*api.Response[string]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/proposal.go b/multi/proposal.go index 5290e234..59d4ec34 100644 --- a/multi/proposal.go +++ b/multi/proposal.go @@ -27,7 +27,7 @@ func (s *Service) Proposal(ctx context.Context, *api.Response[*api.VersionedProposal], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.ProposalProvider).Proposal(ctx, opts) if err != nil { return nil, err @@ -39,5 +39,10 @@ func (s *Service) Proposal(ctx context.Context, return nil, err } - return res.(*api.Response[*api.VersionedProposal]), nil + response, isResponse := res.(*api.Response[*api.VersionedProposal]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/proposerduties.go b/multi/proposerduties.go index afcafc43..c5e592ca 100644 --- a/multi/proposerduties.go +++ b/multi/proposerduties.go @@ -29,7 +29,7 @@ func (s *Service) ProposerDuties(ctx context.Context, *api.Response[[]*apiv1.ProposerDuty], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.ProposerDutiesProvider).ProposerDuties(ctx, opts) if err != nil { return nil, err @@ -41,5 +41,10 @@ func (s *Service) ProposerDuties(ctx context.Context, return nil, err } - return res.(*api.Response[[]*apiv1.ProposerDuty]), nil + response, isResponse := res.(*api.Response[[]*apiv1.ProposerDuty]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/service.go b/multi/service.go index 5e9460ef..e28d0ac6 100644 --- a/multi/service.go +++ b/multi/service.go @@ -118,7 +118,7 @@ func New(ctx context.Context, params ...Parameter) (consensusclient.Service, err } // Name returns the name of the client implementation. -func (s *Service) Name() string { +func (*Service) Name() string { return "multi" } diff --git a/multi/service_test.go b/multi/service_test.go index 8f6ee560..e5cfd1d3 100644 --- a/multi/service_test.go +++ b/multi/service_test.go @@ -113,10 +113,12 @@ func TestInterfaces(t *testing.T) { assert.Implements(t, (*client.BeaconCommitteeSubscriptionsSubmitter)(nil), s) assert.Implements(t, (*client.BeaconStateProvider)(nil), s) assert.Implements(t, (*client.BlindedBeaconBlockSubmitter)(nil), s) + assert.Implements(t, (*client.BlobSidecarsProvider)(nil), s) assert.Implements(t, (*client.ValidatorRegistrationsSubmitter)(nil), s) assert.Implements(t, (*client.DepositContractProvider)(nil), s) assert.Implements(t, (*client.EventsProvider)(nil), s) assert.Implements(t, (*client.FinalityProvider)(nil), s) + assert.Implements(t, (*client.ForkChoiceProvider)(nil), s) assert.Implements(t, (*client.ForkProvider)(nil), s) assert.Implements(t, (*client.ForkScheduleProvider)(nil), s) assert.Implements(t, (*client.GenesisProvider)(nil), s) diff --git a/multi/signedbeaconblock.go b/multi/signedbeaconblock.go index fd1a0b9e..171df398 100644 --- a/multi/signedbeaconblock.go +++ b/multi/signedbeaconblock.go @@ -28,7 +28,7 @@ func (s *Service) SignedBeaconBlock(ctx context.Context, *api.Response[*spec.VersionedSignedBeaconBlock], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.SignedBeaconBlockProvider).SignedBeaconBlock(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) SignedBeaconBlock(ctx context.Context, return nil, err } - return res.(*api.Response[*spec.VersionedSignedBeaconBlock]), nil + response, isResponse := res.(*api.Response[*spec.VersionedSignedBeaconBlock]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/slotduration.go b/multi/slotduration.go index a559849c..ae5754da 100644 --- a/multi/slotduration.go +++ b/multi/slotduration.go @@ -25,7 +25,7 @@ import ( // // Deprecated: use Spec(). func (s *Service) SlotDuration(ctx context.Context) (time.Duration, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { duration, err := client.(consensusclient.SlotDurationProvider).SlotDuration(ctx) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) SlotDuration(ctx context.Context) (time.Duration, error) { return 0, err } - return res.(time.Duration), nil + response, isResponse := res.(time.Duration) + if !isResponse { + return 0, ErrIncorrectType + } + + return response, nil } diff --git a/multi/slotsperepoch.go b/multi/slotsperepoch.go index b56f3cc1..b16f831c 100644 --- a/multi/slotsperepoch.go +++ b/multi/slotsperepoch.go @@ -24,7 +24,7 @@ import ( // // Deprecated: use Spec(). func (s *Service) SlotsPerEpoch(ctx context.Context) (uint64, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { slotsPerEpoch, err := client.(consensusclient.SlotsPerEpochProvider).SlotsPerEpoch(ctx) if err != nil { return nil, err @@ -39,5 +39,10 @@ func (s *Service) SlotsPerEpoch(ctx context.Context) (uint64, error) { return 0, err } - return res.(uint64), nil + response, isResponse := res.(uint64) + if !isResponse { + return 0, ErrIncorrectType + } + + return response, nil } diff --git a/multi/spec.go b/multi/spec.go index 2557d248..e7404dc7 100644 --- a/multi/spec.go +++ b/multi/spec.go @@ -27,7 +27,7 @@ func (s *Service) Spec(ctx context.Context, *api.Response[map[string]any], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { aggregate, err := client.(consensusclient.SpecProvider).Spec(ctx, opts) if err != nil { return nil, err @@ -39,5 +39,10 @@ func (s *Service) Spec(ctx context.Context, return nil, err } - return res.(*api.Response[map[string]any]), nil + response, isResponse := res.(*api.Response[map[string]any]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/stateroot.go b/multi/stateroot.go index 2fa62f52..dd1c59ed 100644 --- a/multi/stateroot.go +++ b/multi/stateroot.go @@ -28,7 +28,7 @@ func (s *Service) BeaconStateRoot(ctx context.Context, *api.Response[*phase0.Root], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { stateRoot, err := client.(consensusclient.BeaconStateRootProvider).BeaconStateRoot(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) BeaconStateRoot(ctx context.Context, return nil, err } - return res.(*api.Response[*phase0.Root]), nil + response, isResponse := res.(*api.Response[*phase0.Root]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/submitaggregateattestations.go b/multi/submitaggregateattestations.go index 1010a5f8..0329d201 100644 --- a/multi/submitaggregateattestations.go +++ b/multi/submitaggregateattestations.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitAggregateAttestations(ctx context.Context, aggregateAndProofs []*phase0.SignedAggregateAndProof, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.AggregateAttestationsSubmitter).SubmitAggregateAttestations(ctx, aggregateAndProofs) if err != nil { return nil, err diff --git a/multi/submitattestations.go b/multi/submitattestations.go index c0a3ec68..faa0baa5 100644 --- a/multi/submitattestations.go +++ b/multi/submitattestations.go @@ -25,7 +25,7 @@ import ( func (s *Service) SubmitAttestations(ctx context.Context, attestations []*phase0.Attestation, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.AttestationsSubmitter).SubmitAttestations(ctx, attestations) if err != nil { return nil, err diff --git a/multi/submitbeaconblock.go b/multi/submitbeaconblock.go index b7c3455c..81283ac8 100644 --- a/multi/submitbeaconblock.go +++ b/multi/submitbeaconblock.go @@ -24,7 +24,7 @@ import ( // // Deprecated: this will not work from the deneb hard-fork onwards. Use SubmitProposal() instead. func (s *Service) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.BeaconBlockSubmitter).SubmitBeaconBlock(ctx, block) if err != nil { return nil, err diff --git a/multi/submitbeaconcommitteesubscriptions.go b/multi/submitbeaconcommitteesubscriptions.go index 324b182d..96fe1d59 100644 --- a/multi/submitbeaconcommitteesubscriptions.go +++ b/multi/submitbeaconcommitteesubscriptions.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitBeaconCommitteeSubscriptions(ctx context.Context, subscriptions []*api.BeaconCommitteeSubscription, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.BeaconCommitteeSubscriptionsSubmitter).SubmitBeaconCommitteeSubscriptions(ctx, subscriptions) if err != nil { return nil, err diff --git a/multi/submitblindedbeaconblock.go b/multi/submitblindedbeaconblock.go index 9b1a71c0..a4c10672 100644 --- a/multi/submitblindedbeaconblock.go +++ b/multi/submitblindedbeaconblock.go @@ -24,7 +24,7 @@ import ( // // Deprecated: this will not work from the deneb hard-fork onwards. Use SubmitBlindedProposal() instead. func (s *Service) SubmitBlindedBeaconBlock(ctx context.Context, block *api.VersionedSignedBlindedBeaconBlock) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.BlindedBeaconBlockSubmitter).SubmitBlindedBeaconBlock(ctx, block) if err != nil { return nil, err diff --git a/multi/submitproposal.go b/multi/submitproposal.go index df058c66..6d6d9831 100644 --- a/multi/submitproposal.go +++ b/multi/submitproposal.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitProposal(ctx context.Context, opts *api.SubmitProposalOpts, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.ProposalSubmitter).SubmitProposal(ctx, opts) if err != nil { return nil, err diff --git a/multi/submitproposalpreparations.go b/multi/submitproposalpreparations.go index 9f9cd55b..87d25e46 100644 --- a/multi/submitproposalpreparations.go +++ b/multi/submitproposalpreparations.go @@ -25,7 +25,7 @@ import ( func (s *Service) SubmitProposalPreparations(ctx context.Context, preparations []*apiv1.ProposalPreparation, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.ProposalPreparationsSubmitter).SubmitProposalPreparations(ctx, preparations) if err != nil { return nil, err diff --git a/multi/submitsynccommitteecontributions.go b/multi/submitsynccommitteecontributions.go index f2af9117..bc59d2dc 100644 --- a/multi/submitsynccommitteecontributions.go +++ b/multi/submitsynccommitteecontributions.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitSyncCommitteeContributions(ctx context.Context, contributionAndProofs []*altair.SignedContributionAndProof, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.SyncCommitteeContributionsSubmitter).SubmitSyncCommitteeContributions(ctx, contributionAndProofs) if err != nil { return nil, err diff --git a/multi/submitsynccommitteemessages.go b/multi/submitsynccommitteemessages.go index 2948ab63..4153ee48 100644 --- a/multi/submitsynccommitteemessages.go +++ b/multi/submitsynccommitteemessages.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitSyncCommitteeMessages(ctx context.Context, messages []*altair.SyncCommitteeMessage, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.SyncCommitteeMessagesSubmitter).SubmitSyncCommitteeMessages(ctx, messages) if err != nil { return nil, err diff --git a/multi/submitsynccommitteesubscriptions.go b/multi/submitsynccommitteesubscriptions.go index c23c119b..e33e4be1 100644 --- a/multi/submitsynccommitteesubscriptions.go +++ b/multi/submitsynccommitteesubscriptions.go @@ -24,7 +24,7 @@ import ( func (s *Service) SubmitSyncCommitteeSubscriptions(ctx context.Context, subscriptions []*api.SyncCommitteeSubscription, ) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.SyncCommitteeSubscriptionsSubmitter).SubmitSyncCommitteeSubscriptions(ctx, subscriptions) if err != nil { return nil, err diff --git a/multi/submitvalidatorregistrations.go b/multi/submitvalidatorregistrations.go index bed43ad2..26d64390 100644 --- a/multi/submitvalidatorregistrations.go +++ b/multi/submitvalidatorregistrations.go @@ -22,7 +22,7 @@ import ( // SubmitValidatorRegistrations submits a validator registration. func (s *Service) SubmitValidatorRegistrations(ctx context.Context, registrations []*api.VersionedSignedValidatorRegistration) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.ValidatorRegistrationsSubmitter).SubmitValidatorRegistrations(ctx, registrations) if err != nil { return nil, err diff --git a/multi/submitvoluntaryexit.go b/multi/submitvoluntaryexit.go index 0f1c72b5..d6ebc24f 100644 --- a/multi/submitvoluntaryexit.go +++ b/multi/submitvoluntaryexit.go @@ -22,7 +22,7 @@ import ( // SubmitVoluntaryExit submits a voluntary exit. func (s *Service) SubmitVoluntaryExit(ctx context.Context, voluntaryExit *phase0.SignedVoluntaryExit) error { - _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + _, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { err := client.(consensusclient.VoluntaryExitSubmitter).SubmitVoluntaryExit(ctx, voluntaryExit) if err != nil { return nil, err diff --git a/multi/synccommitteecontribution.go b/multi/synccommitteecontribution.go index 4486bfb8..8e57cdd6 100644 --- a/multi/synccommitteecontribution.go +++ b/multi/synccommitteecontribution.go @@ -28,7 +28,7 @@ func (s *Service) SyncCommitteeContribution(ctx context.Context, *api.Response[*altair.SyncCommitteeContribution], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.SyncCommitteeContributionProvider).SyncCommitteeContribution(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) SyncCommitteeContribution(ctx context.Context, return nil, err } - return res.(*api.Response[*altair.SyncCommitteeContribution]), nil + response, isResponse := res.(*api.Response[*altair.SyncCommitteeContribution]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/synccommitteeduties.go b/multi/synccommitteeduties.go index 3324fdfc..5723323a 100644 --- a/multi/synccommitteeduties.go +++ b/multi/synccommitteeduties.go @@ -29,7 +29,7 @@ func (s *Service) SyncCommitteeDuties(ctx context.Context, *api.Response[[]*apiv1.SyncCommitteeDuty], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { response, err := client.(consensusclient.SyncCommitteeDutiesProvider).SyncCommitteeDuties(ctx, opts) if err != nil { return nil, err @@ -41,5 +41,10 @@ func (s *Service) SyncCommitteeDuties(ctx context.Context, return nil, err } - return res.(*api.Response[[]*apiv1.SyncCommitteeDuty]), nil + response, isResponse := res.(*api.Response[[]*apiv1.SyncCommitteeDuty]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/synccommittees.go b/multi/synccommittees.go index 36b4ca5a..94626dd4 100644 --- a/multi/synccommittees.go +++ b/multi/synccommittees.go @@ -23,7 +23,7 @@ import ( // SyncCommittee fetches the sync committee for the given state. func (s *Service) SyncCommittee(ctx context.Context, opts *api.SyncCommitteeOpts) (*api.Response[*apiv1.SyncCommittee], error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.SyncCommitteesProvider).SyncCommittee(ctx, opts) if err != nil { return nil, err @@ -35,5 +35,10 @@ func (s *Service) SyncCommittee(ctx context.Context, opts *api.SyncCommitteeOpts return nil, err } - return res.(*api.Response[*apiv1.SyncCommittee]), nil + response, isResponse := res.(*api.Response[*apiv1.SyncCommittee]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/targetaggregatorspercommittee.go b/multi/targetaggregatorspercommittee.go index 8e234f55..ca91ae75 100644 --- a/multi/targetaggregatorspercommittee.go +++ b/multi/targetaggregatorspercommittee.go @@ -24,7 +24,7 @@ import ( // // Deprecated: Use Spec(). func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, error) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { aggregators, err := client.(consensusclient.TargetAggregatorsPerCommitteeProvider).TargetAggregatorsPerCommittee(ctx) if err != nil { return nil, err @@ -39,5 +39,10 @@ func (s *Service) TargetAggregatorsPerCommittee(ctx context.Context) (uint64, er return 0, err } - return res.(uint64), nil + response, isResponse := res.(uint64) + if !isResponse { + return 0, ErrIncorrectType + } + + return response, nil } diff --git a/multi/validatorbalances.go b/multi/validatorbalances.go index 90f6503b..949177b2 100644 --- a/multi/validatorbalances.go +++ b/multi/validatorbalances.go @@ -28,7 +28,7 @@ func (s *Service) ValidatorBalances(ctx context.Context, *api.Response[map[phase0.ValidatorIndex]phase0.Gwei], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.ValidatorBalancesProvider).ValidatorBalances(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) ValidatorBalances(ctx context.Context, return nil, err } - return res.(*api.Response[map[phase0.ValidatorIndex]phase0.Gwei]), nil + response, isResponse := res.(*api.Response[map[phase0.ValidatorIndex]phase0.Gwei]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/validators.go b/multi/validators.go index 33cfeddd..121864eb 100644 --- a/multi/validators.go +++ b/multi/validators.go @@ -29,7 +29,7 @@ func (s *Service) Validators(ctx context.Context, *api.Response[map[phase0.ValidatorIndex]*apiv1.Validator], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { block, err := client.(consensusclient.ValidatorsProvider).Validators(ctx, opts) if err != nil { return nil, err @@ -41,5 +41,10 @@ func (s *Service) Validators(ctx context.Context, return nil, err } - return res.(*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator]), nil + response, isResponse := res.(*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/multi/voluntaryexitpool.go b/multi/voluntaryexitpool.go index 24b6b151..ced2675c 100644 --- a/multi/voluntaryexitpool.go +++ b/multi/voluntaryexitpool.go @@ -28,7 +28,7 @@ func (s *Service) VoluntaryExitPool(ctx context.Context, *api.Response[[]*phase0.SignedVoluntaryExit], error, ) { - res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { + res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (any, error) { voluntaryExitPool, err := client.(consensusclient.VoluntaryExitPoolProvider).VoluntaryExitPool(ctx, opts) if err != nil { return nil, err @@ -40,5 +40,10 @@ func (s *Service) VoluntaryExitPool(ctx context.Context, return nil, err } - return res.(*api.Response[[]*phase0.SignedVoluntaryExit]), nil + response, isResponse := res.(*api.Response[[]*phase0.SignedVoluntaryExit]) + if !isResponse { + return nil, ErrIncorrectType + } + + return response, nil } diff --git a/service.go b/service.go index 90544a71..adbeb1fa 100644 --- a/service.go +++ b/service.go @@ -17,7 +17,7 @@ import ( "context" "time" - api "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/api" apiv1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" diff --git a/spec/bellatrix/executionaddress.go b/spec/bellatrix/executionaddress.go index cc012a62..feaa356d 100644 --- a/spec/bellatrix/executionaddress.go +++ b/spec/bellatrix/executionaddress.go @@ -34,25 +34,25 @@ func (a ExecutionAddress) IsZero() bool { // String returns an EIP-55 string version of the address. func (a ExecutionAddress) String() string { - bytes := []byte(hex.EncodeToString(a[:])) + data := []byte(hex.EncodeToString(a[:])) keccak := sha3.NewLegacyKeccak256() - keccak.Write(bytes) + keccak.Write(data) hash := keccak.Sum(nil) - for i := 0; i < len(bytes); i++ { + for i := 0; i < len(data); i++ { hashByte := hash[i/2] if i%2 == 0 { hashByte >>= 4 } else { hashByte &= 0xf } - if bytes[i] > '9' && hashByte > 7 { - bytes[i] -= 32 + if data[i] > '9' && hashByte > 7 { + data[i] -= 32 } } - return fmt.Sprintf("0x%s", string(bytes)) + return fmt.Sprintf("0x%s", string(data)) } // Format formats the execution address. diff --git a/spec/bellatrix/executionpayload.go b/spec/bellatrix/executionpayload.go index 284a012c..07f25c73 100644 --- a/spec/bellatrix/executionpayload.go +++ b/spec/bellatrix/executionpayload.go @@ -243,7 +243,7 @@ func (e *ExecutionPayload) unpack(data *executionPayloadJSON) error { } switch { case data.ExtraData == "0x", data.ExtraData == "0": - e.ExtraData = []byte{} + e.ExtraData = make([]byte, 0) default: data.ExtraData = strings.TrimPrefix(data.ExtraData, "0x") if len(data.ExtraData)%2 == 1 { diff --git a/spec/capella/executionpayload.go b/spec/capella/executionpayload.go index 92faaed8..561d40c9 100644 --- a/spec/capella/executionpayload.go +++ b/spec/capella/executionpayload.go @@ -248,7 +248,7 @@ func (e *ExecutionPayload) unpack(data *executionPayloadJSON) error { } switch { case data.ExtraData == "0x", data.ExtraData == "0": - e.ExtraData = []byte{} + e.ExtraData = make([]byte, 0) default: data.ExtraData = strings.TrimPrefix(data.ExtraData, "0x") if len(data.ExtraData)%2 == 1 { diff --git a/spec/deneb/beaconblock_yaml.go b/spec/deneb/beaconblock_yaml.go index 5e9736f4..9ebe4168 100644 --- a/spec/deneb/beaconblock_yaml.go +++ b/spec/deneb/beaconblock_yaml.go @@ -50,14 +50,14 @@ func (b *BeaconBlock) MarshalYAML() ([]byte, error) { func (b *BeaconBlock) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data beaconBlockJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled beaconBlockJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/beaconblockbody_yaml.go b/spec/deneb/beaconblockbody_yaml.go index b040e59a..8b79a4b6 100644 --- a/spec/deneb/beaconblockbody_yaml.go +++ b/spec/deneb/beaconblockbody_yaml.go @@ -73,14 +73,14 @@ func (b *BeaconBlockBody) MarshalYAML() ([]byte, error) { func (b *BeaconBlockBody) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data beaconBlockBodyJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled beaconBlockBodyJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/beaconstate_yaml.go b/spec/deneb/beaconstate_yaml.go index d33b6a76..b520707b 100644 --- a/spec/deneb/beaconstate_yaml.go +++ b/spec/deneb/beaconstate_yaml.go @@ -100,14 +100,14 @@ func (b *BeaconState) MarshalYAML() ([]byte, error) { func (b *BeaconState) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data beaconStateJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled beaconStateJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/blob.go b/spec/deneb/blob.go index 02353429..e4587630 100644 --- a/spec/deneb/blob.go +++ b/spec/deneb/blob.go @@ -58,7 +58,7 @@ func (b *Blob) UnmarshalJSON(input []byte) error { return errors.New("invalid prefix") } if !bytes.HasSuffix(input, []byte{'"'}) { - return errors.New("Invalid suffix") + return errors.New("invalid suffix") } if len(input) != 1+2+BlobLength*2+1 { return errors.New("incorrect length") @@ -91,7 +91,7 @@ func (b *Blob) UnmarshalYAML(input []byte) error { return errors.New("invalid prefix") } if !bytes.HasSuffix(input, []byte{'\''}) { - return errors.New("Invalid suffix") + return errors.New("invalid suffix") } if len(input) != 1+2+BlobLength*2+1 { return errors.New("incorrect length") diff --git a/spec/deneb/blobidentifier_yaml.go b/spec/deneb/blobidentifier_yaml.go index b48f0e68..0e628175 100644 --- a/spec/deneb/blobidentifier_yaml.go +++ b/spec/deneb/blobidentifier_yaml.go @@ -44,14 +44,14 @@ func (b *BlobIdentifier) MarshalYAML() ([]byte, error) { func (b *BlobIdentifier) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data blobIdentifierJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled blobIdentifierJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/blobsidecar_yaml.go b/spec/deneb/blobsidecar_yaml.go index 1610217d..b6df70a5 100644 --- a/spec/deneb/blobsidecar_yaml.go +++ b/spec/deneb/blobsidecar_yaml.go @@ -53,14 +53,14 @@ func (b *BlobSidecar) MarshalYAML() ([]byte, error) { func (b *BlobSidecar) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data blobSidecarJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled blobSidecarJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(&data) + marshaled, err := json.Marshal(&unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return b.UnmarshalJSON(bytes) + return b.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/executionpayload_yaml.go b/spec/deneb/executionpayload_yaml.go index a397202a..186fce8a 100644 --- a/spec/deneb/executionpayload_yaml.go +++ b/spec/deneb/executionpayload_yaml.go @@ -86,14 +86,14 @@ func (e *ExecutionPayload) MarshalYAML() ([]byte, error) { func (e *ExecutionPayload) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data executionPayloadJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled executionPayloadJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return e.UnmarshalJSON(bytes) + return e.UnmarshalJSON(marshaled) } diff --git a/spec/deneb/executionpayloadheader_yaml.go b/spec/deneb/executionpayloadheader_yaml.go index 1d49a2f4..cd0b6265 100644 --- a/spec/deneb/executionpayloadheader_yaml.go +++ b/spec/deneb/executionpayloadheader_yaml.go @@ -82,14 +82,14 @@ func (e *ExecutionPayloadHeader) MarshalYAML() ([]byte, error) { func (e *ExecutionPayloadHeader) UnmarshalYAML(input []byte) error { // This is very inefficient, but YAML is only used for spec tests so we do this // rather than maintain a custom YAML unmarshaller. - var data executionPayloadHeaderJSON - if err := yaml.Unmarshal(input, &data); err != nil { + var unmarshaled executionPayloadHeaderJSON + if err := yaml.Unmarshal(input, &unmarshaled); err != nil { return errors.Wrap(err, "failed to unmarshal YAML") } - bytes, err := json.Marshal(data) + marshaled, err := json.Marshal(unmarshaled) if err != nil { return errors.Wrap(err, "failed to marshal JSON") } - return e.UnmarshalJSON(bytes) + return e.UnmarshalJSON(marshaled) } diff --git a/testclients/erroring.go b/testclients/erroring.go index f1b355b6..a2c86cfd 100644 --- a/testclients/erroring.go +++ b/testclients/erroring.go @@ -71,12 +71,12 @@ func (s *Erroring) Address() string { } // IsActive returns true if the client is active. -func (s *Erroring) IsActive() bool { +func (*Erroring) IsActive() bool { return true } // IsSynced returns true if the client is synced. -func (s *Erroring) IsSynced() bool { +func (*Erroring) IsSynced() bool { return true } @@ -639,7 +639,7 @@ func (s *Erroring) SyncCommitteeDuties(ctx context.Context, opts *api.SyncCommit } // Spec provides the spec information of the chain. -func (s *Erroring) Spec(ctx context.Context, opts *api.SpecOpts) (*api.Response[map[string]interface{}], error) { +func (s *Erroring) Spec(ctx context.Context, opts *api.SpecOpts) (*api.Response[map[string]any], error) { if err := s.maybeError(ctx); err != nil { return nil, err } diff --git a/testclients/sleepy.go b/testclients/sleepy.go index 277f445a..88acec9c 100644 --- a/testclients/sleepy.go +++ b/testclients/sleepy.go @@ -72,12 +72,12 @@ func (s *Sleepy) Address() string { } // IsActive returns true if the client is active. -func (s *Sleepy) IsActive() bool { +func (*Sleepy) IsActive() bool { return true } // IsSynced returns true if the client is synced. -func (s *Sleepy) IsSynced() bool { +func (*Sleepy) IsSynced() bool { return true } @@ -463,7 +463,7 @@ func (s *Sleepy) ProposerDuties(ctx context.Context, } // Spec provides the spec information of the chain. -func (s *Sleepy) Spec(ctx context.Context, opts *api.SpecOpts) (*api.Response[map[string]interface{}], error) { +func (s *Sleepy) Spec(ctx context.Context, opts *api.SpecOpts) (*api.Response[map[string]any], error) { s.sleep(ctx) next, isNext := s.next.(consensusclient.SpecProvider) if !isNext {