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 9 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()
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/attestantio/go-eth2-client v0.24.0
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874
github.com/btcsuite/btcd/btcutil v1.1.6
github.com/buger/jsonparser v1.1.1
github.com/ethereum/go-ethereum v1.15.2
github.com/flashbots/go-boost-utils v1.8.2-0.20240925223941-58709124077d
github.com/flashbots/go-utils v0.8.3
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/consensys/bavard v0.1.29 h1:fobxIYksIQ+ZSrTJUuQgu+HIJwclrAPcdXqd7H2hh1k=
Expand Down
Loading
Loading