Skip to content

Commit 47cc71d

Browse files
jtragliametachris
andauthored
Add SSZ support to the Proposer API (#685)
* Add SSZ support to registerValidator * Fix merge mistake * Run go mod tidy * Add SSZ support for getHeader * Add a couple getHeader SSZ tests * Add SSZ support for getPayload * Do some clean up * Add some debug prints * Add back fast registration parsing --------- Co-authored-by: Chris Hager <[email protected]>
1 parent 17ed054 commit 47cc71d

File tree

7 files changed

+485
-220
lines changed

7 files changed

+485
-220
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ linters:
3030
- exhaustruct
3131
- tenv
3232
- gocognit
33+
- dupl
3334

3435
#
3536
# Disabled because of generics:

common/constants.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package common
2+
3+
const (
4+
EthConsensusVersionBellatrix = "bellatrix"
5+
EthConsensusVersionCapella = "capella"
6+
EthConsensusVersionDeneb = "deneb"
7+
EthConsensusVersionElectra = "electra"
8+
)

common/types_spec.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package common
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67

@@ -11,6 +12,7 @@ import (
1112
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
1213
builderSpec "github.com/attestantio/go-builder-client/spec"
1314
eth2Api "github.com/attestantio/go-eth2-client/api"
15+
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
1416
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
1517
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
1618
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
@@ -589,3 +591,36 @@ func (r *VersionedSignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error {
589591
}
590592
return errors.Wrap(err, "failed to unmarshal SignedBlindedBeaconBlock")
591593
}
594+
595+
func (r *VersionedSignedBlindedBeaconBlock) Unmarshal(input []byte, contentType, ethConsensusVersion string) error {
596+
switch contentType {
597+
case "application/octet-stream":
598+
if ethConsensusVersion != "" {
599+
switch ethConsensusVersion {
600+
case EthConsensusVersionBellatrix:
601+
r.Version = spec.DataVersionBellatrix
602+
r.Bellatrix = new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock)
603+
return r.Bellatrix.UnmarshalSSZ(input)
604+
case EthConsensusVersionCapella:
605+
r.Version = spec.DataVersionCapella
606+
r.Capella = new(eth2ApiV1Capella.SignedBlindedBeaconBlock)
607+
return r.Capella.UnmarshalSSZ(input)
608+
case EthConsensusVersionDeneb:
609+
r.Version = spec.DataVersionDeneb
610+
r.Deneb = new(eth2ApiV1Deneb.SignedBlindedBeaconBlock)
611+
return r.Deneb.UnmarshalSSZ(input)
612+
case EthConsensusVersionElectra:
613+
r.Version = spec.DataVersionElectra
614+
r.Electra = new(eth2ApiV1Electra.SignedBlindedBeaconBlock)
615+
return r.Electra.UnmarshalSSZ(input)
616+
default:
617+
return ErrInvalidForkVersion
618+
}
619+
} else {
620+
return ErrMissingEthConsensusVersion
621+
}
622+
case "application/json":
623+
return json.NewDecoder(bytes.NewReader(input)).Decode(r)
624+
}
625+
return ErrInvalidContentType
626+
}

common/utils.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import (
2626
)
2727

2828
var (
29-
ErrInvalidForkVersion = errors.New("invalid fork version")
30-
ErrHTTPErrorResponse = errors.New("got an HTTP error response")
31-
ErrIncorrectLength = errors.New("incorrect length")
29+
ErrInvalidForkVersion = errors.New("invalid fork version")
30+
ErrHTTPErrorResponse = errors.New("got an HTTP error response")
31+
ErrIncorrectLength = errors.New("incorrect length")
32+
ErrMissingEthConsensusVersion = errors.New("missing eth-consensus-version")
33+
ErrInvalidContentType = errors.New("invalid content type")
3234
)
3335

3436
// SlotPos returns the slot's position in the epoch (1-based, i.e. 1..32)

datastore/redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,6 @@ func (r *RedisCache) NewPipeline() redis.Pipeliner { //nolint:ireturn,nolintlint
847847
return r.client.Pipeline()
848848
}
849849

850-
func (r *RedisCache) NewTxPipeline() redis.Pipeliner { //nolint:ireturn
850+
func (r *RedisCache) NewTxPipeline() redis.Pipeliner { //nolint:ireturn,nolintlint
851851
return r.client.TxPipeline()
852852
}

0 commit comments

Comments
 (0)