Skip to content

Commit

Permalink
Spec Align: Version block support (ssvlabs#913)
Browse files Browse the repository at this point in the history
* update & align to spec

* deploy to all nodes

* deploy onlt v3-1..4

* Revert "deploy onlt v3-1..4"

This reverts commit b283f22.

* run `go generate`

* fix gitlab
  • Loading branch information
moshe-blox authored Mar 22, 2023
1 parent 4749590 commit f4e07e6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 129 deletions.
2 changes: 2 additions & 0 deletions beacon/goclient/goclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type Client interface {
eth2client.NodeSyncingProvider
eth2client.BeaconBlockProposalProvider
eth2client.BeaconBlockSubmitter
eth2client.BlindedBeaconBlockProposalProvider
eth2client.BlindedBeaconBlockSubmitter
eth2client.DomainProvider
eth2client.BeaconBlockRootProvider
eth2client.SyncCommitteeMessagesSubmitter
Expand Down
77 changes: 73 additions & 4 deletions beacon/goclient/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import (
"github.com/attestantio/go-eth2-client/api"
eth2apiv1 "github.com/attestantio/go-eth2-client/api/v1"
"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/phase0"
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"

apiv1bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
apiv1capella "github.com/attestantio/go-eth2-client/api/v1/capella"
)

// GetBeaconBlock returns beacon block by the given slot and committee index
Expand Down Expand Up @@ -45,13 +50,77 @@ func (gc *goClient) GetBlindedBeaconBlock(slot phase0.Slot, committeeIndex phase
return nil, DataVersionNil, nil
}

func (gc *goClient) SubmitBlindedBeaconBlock(block *api.VersionedSignedBlindedBeaconBlock) error {
return nil
func (gc *goClient) SubmitBlindedBeaconBlock(block *api.VersionedBlindedBeaconBlock, sig phase0.BLSSignature) error {
signedBlock := &api.VersionedSignedBlindedBeaconBlock{
Version: block.Version,
}
switch block.Version {
case spec.DataVersionBellatrix:
if block.Bellatrix == nil {
return errors.New("bellatrix blinded block is nil")
}
signedBlock.Bellatrix = &apiv1bellatrix.SignedBlindedBeaconBlock{
Message: block.Bellatrix,
}
copy(signedBlock.Bellatrix.Signature[:], sig[:])
case spec.DataVersionCapella:
if block.Capella == nil {
return errors.New("capella blinded block is nil")
}
signedBlock.Capella = &apiv1capella.SignedBlindedBeaconBlock{
Message: block.Capella,
}
copy(signedBlock.Capella.Signature[:], sig[:])
default:
return errors.New("unknown block version")
}

return gc.client.SubmitBlindedBeaconBlock(gc.ctx, signedBlock)
}

// SubmitBeaconBlock submit the block to the node
func (gc *goClient) SubmitBeaconBlock(block *spec.VersionedSignedBeaconBlock) error {
return gc.client.SubmitBeaconBlock(gc.ctx, block)
func (gc *goClient) SubmitBeaconBlock(block *spec.VersionedBeaconBlock, sig phase0.BLSSignature) error {
signedBlock := &spec.VersionedSignedBeaconBlock{
Version: block.Version,
}
switch block.Version {
case spec.DataVersionPhase0:
if block.Phase0 == nil {
return errors.New("phase0 block is nil")
}
signedBlock.Phase0 = &phase0.SignedBeaconBlock{
Message: block.Phase0,
}
copy(signedBlock.Phase0.Signature[:], sig[:])
case spec.DataVersionAltair:
if block.Altair == nil {
return errors.New("altair block is nil")
}
signedBlock.Altair = &altair.SignedBeaconBlock{
Message: block.Altair,
}
copy(signedBlock.Altair.Signature[:], sig[:])
case spec.DataVersionBellatrix:
if block.Bellatrix == nil {
return errors.New("bellatrix block is nil")
}
signedBlock.Bellatrix = &bellatrix.SignedBeaconBlock{
Message: block.Bellatrix,
}
copy(signedBlock.Bellatrix.Signature[:], sig[:])
case spec.DataVersionCapella:
if block.Capella == nil {
return errors.New("capella block is nil")
}
signedBlock.Capella = &capella.SignedBeaconBlock{
Message: block.Capella,
}
copy(signedBlock.Capella.Signature[:], sig[:])
default:
return errors.New("unknown block version")
}

return gc.client.SubmitBeaconBlock(gc.ctx, signedBlock)
}

func (gc *goClient) SubmitProposalPreparation(feeRecipients map[phase0.ValidatorIndex]bellatrix.ExecutionAddress) error {
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.19

require (
github.com/aquasecurity/table v1.8.0
github.com/attestantio/go-eth2-client v0.15.7
github.com/attestantio/go-eth2-client v0.15.8-0.20230322092059-6b2aee891155
github.com/bloxapp/eth2-key-manager v1.3.0-rc.0
github.com/bloxapp/ssv-spec v0.2.8-0.20230302114248-61a10845523b
github.com/bloxapp/ssv-spec v0.3.1-0.20230322125847-21e97ea2ad3d
github.com/btcsuite/btcd/btcec/v2 v2.2.1
github.com/cespare/xxhash/v2 v2.2.0
github.com/cornelk/hashmap v1.0.8
Expand Down Expand Up @@ -182,5 +182,3 @@ replace github.com/prysmaticlabs/prysm => github.com/prysmaticlabs/prysm v1.4.2-
replace github.com/google/flatbuffers => github.com/google/flatbuffers v1.11.0

replace github.com/dgraph-io/ristretto => github.com/dgraph-io/ristretto v0.1.1-0.20211108053508-297c39e6640f

replace github.com/bloxapp/ssv-spec => github.com/olegshmuelov/ssv-spec v0.0.0-20230316101051-2509fee73647
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/attestantio/go-eth2-client v0.15.7 h1:0v7+Z2RZ8bNtU/0mfppXzLiYv+6a8pe2wKyA6CU9jwQ=
github.com/attestantio/go-eth2-client v0.15.7/go.mod h1:/Oh6YTuHmHhgLN/ZnQRKHGc7HdIzGlDkI2vjNZvOsvA=
github.com/attestantio/go-eth2-client v0.15.8-0.20230322092059-6b2aee891155 h1:MGoOMumyZiwVVnMgc4FmQyaOMgA7TzP4zM5RlRSO++o=
github.com/attestantio/go-eth2-client v0.15.8-0.20230322092059-6b2aee891155/go.mod h1:PLRKnILnr63V3yl2VagBqnhVRFBWc0V+JhQSsXQaSwQ=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
Expand All @@ -139,6 +139,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bloxapp/eth2-key-manager v1.3.0-rc.0 h1:Hfq7/mdjUHmqI5Tv0Pc1TdGgXfHrgrY1tOTIz290pAg=
github.com/bloxapp/eth2-key-manager v1.3.0-rc.0/go.mod h1:cT+qAJfnAzNz9StFoHQ8xAkyU2eyEukd6xfxvcBWuZA=
github.com/bloxapp/ssv-spec v0.3.1-0.20230322125847-21e97ea2ad3d h1:53fq26+ulTdIB35ea5ji64pmb9hE2sAuK5FRYXP2liA=
github.com/bloxapp/ssv-spec v0.3.1-0.20230322125847-21e97ea2ad3d/go.mod h1:VDG27SnHcC2coL/eCXFvROuzvlOrdlSTzgCWcoUvh7s=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
Expand Down
19 changes: 9 additions & 10 deletions operator/validator/mocks/controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions protocol/v2/blockchain/beacon/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 4 additions & 95 deletions protocol/v2/ssv/runner/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import (
"crypto/sha256"
"encoding/json"

"github.com/attestantio/go-eth2-client/api"
apiv1bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
apiv1capella "github.com/attestantio/go-eth2-client/api/v1/capella"
"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/phase0"
specqbft "github.com/bloxapp/ssv-spec/qbft"
specssv "github.com/bloxapp/ssv-spec/ssv"
Expand Down Expand Up @@ -134,7 +128,6 @@ func (r *ProposerRunner) ProcessConsensus(logger *zap.Logger, signedMsg *specqbf
if err != nil {
return errors.Wrap(err, "failed processing consensus message")
}

// Decided returns true only once so if it is true it must be for the current running instance
if !decided {
return nil
Expand All @@ -156,9 +149,6 @@ func (r *ProposerRunner) ProcessConsensus(logger *zap.Logger, signedMsg *specqbf
return errors.Wrap(err, "could not get block data")
}
}
if err != nil {
return errors.Wrap(err, "could not get block")
}

msg, err := r.BaseRunner.signBeaconObject(
r,
Expand All @@ -179,18 +169,15 @@ func (r *ProposerRunner) ProcessConsensus(logger *zap.Logger, signedMsg *specqbf
if err != nil {
return errors.Wrap(err, "could not sign post consensus msg")
}

data, err := postSignedMsg.Encode()
if err != nil {
return errors.Wrap(err, "failed to encode post consensus signature msg")
}

msgToBroadcast := &spectypes.SSVMessage{
MsgType: spectypes.SSVPartialSignatureMsgType,
MsgID: spectypes.NewMsgID(r.GetShare().DomainType, r.GetShare().ValidatorPubKey, r.BaseRunner.BeaconRoleType),
Data: data,
}

if err := r.GetNetwork().Broadcast(msgToBroadcast); err != nil {
return errors.Wrap(err, "can't broadcast partial post consensus sig")
}
Expand All @@ -202,7 +189,6 @@ func (r *ProposerRunner) ProcessPostConsensus(logger *zap.Logger, signedMsg *spe
if err != nil {
return errors.Wrap(err, "failed processing post consensus message")
}

if !quorum {
return nil
}
Expand All @@ -225,35 +211,9 @@ func (r *ProposerRunner) ProcessPostConsensus(logger *zap.Logger, signedMsg *spe
return errors.Wrap(err, "could not get blinded block")
}

var blkToSubmit *api.VersionedSignedBlindedBeaconBlock
switch vBlindedBlk.Version {
case spec.DataVersionBellatrix:
if vBlindedBlk.Bellatrix == nil {
return errors.New("bellatrix blinded block is nil")
}
blkToSubmit = &api.VersionedSignedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Bellatrix: &apiv1bellatrix.SignedBlindedBeaconBlock{
Message: vBlindedBlk.Bellatrix,
},
}
copy(blkToSubmit.Bellatrix.Signature[:], specSig[:])
case spec.DataVersionCapella:
if vBlindedBlk.Capella == nil {
return errors.New("capella blinded block is nil")
}
blkToSubmit = &api.VersionedSignedBlindedBeaconBlock{
Version: spec.DataVersionCapella,
Capella: &apiv1capella.SignedBlindedBeaconBlock{
Message: vBlindedBlk.Capella,
},
}
copy(blkToSubmit.Capella.Signature[:], specSig[:])
default:
return errors.New("unknown blinded block version")
}
if err := r.GetBeaconNode().SubmitBlindedBeaconBlock(vBlindedBlk, specSig); err != nil {
r.metrics.RoleSubmissionFailed()

if err := r.GetBeaconNode().SubmitBlindedBeaconBlock(blkToSubmit); err != nil {
return errors.Wrap(err, "could not submit to Beacon chain reconstructed signed blinded Beacon block")
}
} else {
Expand All @@ -262,58 +222,9 @@ func (r *ProposerRunner) ProcessPostConsensus(logger *zap.Logger, signedMsg *spe
return errors.Wrap(err, "could not get block")
}

var blkToSubmit *spec.VersionedSignedBeaconBlock
switch vBlk.Version {
case spec.DataVersionPhase0:
if vBlk.Phase0 == nil {
return errors.New("phase0 block is nil")
}
blkToSubmit = &spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionPhase0,
Phase0: &phase0.SignedBeaconBlock{
Message: vBlk.Phase0,
},
}
copy(blkToSubmit.Phase0.Signature[:], specSig[:])
case spec.DataVersionAltair:
if vBlk.Altair == nil {
return errors.New("altair block is nil")
}
blkToSubmit = &spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionAltair,
Altair: &altair.SignedBeaconBlock{
Message: vBlk.Altair,
},
}
copy(blkToSubmit.Altair.Signature[:], specSig[:])
case spec.DataVersionBellatrix:
if vBlk.Bellatrix == nil {
return errors.New("bellatrix block is nil")
}
blkToSubmit = &spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionBellatrix,
Bellatrix: &bellatrix.SignedBeaconBlock{
Message: vBlk.Bellatrix,
},
}
copy(blkToSubmit.Bellatrix.Signature[:], specSig[:])
case spec.DataVersionCapella:
if vBlk.Capella == nil {
return errors.New("capella block is nil")
}
blkToSubmit = &spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionCapella,
Capella: &capella.SignedBeaconBlock{
Message: vBlk.Capella,
},
}
copy(blkToSubmit.Capella.Signature[:], specSig[:])
default:
return errors.New("unknown block version")
}

if err := r.GetBeaconNode().SubmitBeaconBlock(blkToSubmit); err != nil {
if err := r.GetBeaconNode().SubmitBeaconBlock(vBlk, specSig); err != nil {
r.metrics.RoleSubmissionFailed()

return errors.Wrap(err, "could not submit to Beacon chain reconstructed signed Beacon block")
}
}
Expand All @@ -324,9 +235,7 @@ func (r *ProposerRunner) ProcessPostConsensus(logger *zap.Logger, signedMsg *spe

logger.Info("✅ successfully proposed block!")
}

r.GetState().Finished = true

return nil
}

Expand Down
Loading

0 comments on commit f4e07e6

Please sign in to comment.