Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSZ support to the Proposer API #685

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
- exhaustruct
- tenv
- gocognit
- dupl

#
# Disabled because of generics:
Expand Down
8 changes: 8 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package common

const (
EthConsensusVersionBellatrix = "bellatrix"
EthConsensusVersionCapella = "capella"
EthConsensusVersionDeneb = "deneb"
EthConsensusVersionElectra = "electra"
)
35 changes: 35 additions & 0 deletions common/types_spec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"bytes"
"encoding/json"
"fmt"

Expand All @@ -11,6 +12,7 @@ import (
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
builderSpec "github.com/attestantio/go-builder-client/spec"
eth2Api "github.com/attestantio/go-eth2-client/api"
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
Expand Down Expand Up @@ -589,3 +591,36 @@ func (r *VersionedSignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error {
}
return errors.Wrap(err, "failed to unmarshal SignedBlindedBeaconBlock")
}

func (r *VersionedSignedBlindedBeaconBlock) Unmarshal(input []byte, contentType, ethConsensusVersion string) error {
switch contentType {
case "application/octet-stream":
if ethConsensusVersion != "" {
switch ethConsensusVersion {
case EthConsensusVersionBellatrix:
r.Version = spec.DataVersionBellatrix
r.Bellatrix = new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock)
return r.Bellatrix.UnmarshalSSZ(input)
case EthConsensusVersionCapella:
r.Version = spec.DataVersionCapella
r.Capella = new(eth2ApiV1Capella.SignedBlindedBeaconBlock)
return r.Capella.UnmarshalSSZ(input)
case EthConsensusVersionDeneb:
r.Version = spec.DataVersionDeneb
r.Deneb = new(eth2ApiV1Deneb.SignedBlindedBeaconBlock)
return r.Deneb.UnmarshalSSZ(input)
case EthConsensusVersionElectra:
r.Version = spec.DataVersionElectra
r.Electra = new(eth2ApiV1Electra.SignedBlindedBeaconBlock)
return r.Electra.UnmarshalSSZ(input)
default:
return ErrInvalidForkVersion
}
} else {
return ErrMissingEthConsensusVersion
}
case "application/json":
return json.NewDecoder(bytes.NewReader(input)).Decode(r)
}
return ErrInvalidContentType
}
8 changes: 5 additions & 3 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
)

var (
ErrInvalidForkVersion = errors.New("invalid fork version")
ErrHTTPErrorResponse = errors.New("got an HTTP error response")
ErrIncorrectLength = errors.New("incorrect length")
ErrInvalidForkVersion = errors.New("invalid fork version")
ErrHTTPErrorResponse = errors.New("got an HTTP error response")
ErrIncorrectLength = errors.New("incorrect length")
ErrMissingEthConsensusVersion = errors.New("missing eth-consensus-version")
ErrInvalidContentType = errors.New("invalid content type")
)

// SlotPos returns the slot's position in the epoch (1-based, i.e. 1..32)
Expand Down
2 changes: 1 addition & 1 deletion datastore/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,6 @@ func (r *RedisCache) NewPipeline() redis.Pipeliner { //nolint:ireturn,nolintlint
return r.client.Pipeline()
}

func (r *RedisCache) NewTxPipeline() redis.Pipeliner { //nolint:ireturn
func (r *RedisCache) NewTxPipeline() redis.Pipeliner { //nolint:ireturn,nolintlint
return r.client.TxPipeline()
}
Loading