Skip to content

Commit

Permalink
update relay to latest builder-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Nov 21, 2023
1 parent 301f5a9 commit a509806
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 166 deletions.
2 changes: 1 addition & 1 deletion beaconclient/mock_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *MockBeaconInstance) addDelay() {
}
}

func (c *MockBeaconInstance) PublishBlock(block *common.VersionedSignedBlockRequest, broadcaseMode BroadcastMode) (code int, err error) {
func (c *MockBeaconInstance) PublishBlock(block *common.VersionedSignedProposal, broadcaseMode BroadcastMode) (code int, err error) {
return 0, nil
}

Expand Down
2 changes: 1 addition & 1 deletion beaconclient/mock_multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (*MockMultiBeaconClient) GetProposerDuties(epoch uint64) (*ProposerDutiesRe
return nil, nil
}

func (*MockMultiBeaconClient) PublishBlock(block *common.VersionedSignedBlockRequest) (code int, err error) {
func (*MockMultiBeaconClient) PublishBlock(block *common.VersionedSignedProposal) (code int, err error) {
return 0, nil
}

Expand Down
6 changes: 3 additions & 3 deletions beaconclient/multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type IMultiBeaconClient interface {
// GetStateValidators returns all active and pending validators from the beacon node
GetStateValidators(stateID string) (*GetStateValidatorsResponse, error)
GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
PublishBlock(block *common.VersionedSignedBlockRequest) (code int, err error)
PublishBlock(block *common.VersionedSignedProposal) (code int, err error)
GetGenesis() (*GetGenesisResponse, error)
GetSpec() (spec *GetSpecResponse, err error)
GetForkSchedule() (spec *GetForkScheduleResponse, err error)
Expand All @@ -64,7 +64,7 @@ type IBeaconInstance interface {
GetStateValidators(stateID string) (*GetStateValidatorsResponse, error)
GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
GetURI() string
PublishBlock(block *common.VersionedSignedBlockRequest, broadcastMode BroadcastMode) (code int, err error)
PublishBlock(block *common.VersionedSignedProposal, broadcastMode BroadcastMode) (code int, err error)
GetGenesis() (*GetGenesisResponse, error)
GetSpec() (spec *GetSpecResponse, err error)
GetForkSchedule() (spec *GetForkScheduleResponse, err error)
Expand Down Expand Up @@ -259,7 +259,7 @@ type publishResp struct {
}

// PublishBlock publishes the signed beacon block via https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
func (c *MultiBeaconClient) PublishBlock(block *common.VersionedSignedBlockRequest) (code int, err error) {
func (c *MultiBeaconClient) PublishBlock(block *common.VersionedSignedProposal) (code int, err error) {
slot, err := block.Slot()
if err != nil {
c.log.WithError(err).Warn("failed to publish block as block slot is missing")
Expand Down
2 changes: 1 addition & 1 deletion beaconclient/prod_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (c *ProdBeaconInstance) GetURI() string {
return c.beaconURI
}

func (c *ProdBeaconInstance) PublishBlock(block *common.VersionedSignedBlockRequest, broadcastMode BroadcastMode) (code int, err error) {
func (c *ProdBeaconInstance) PublishBlock(block *common.VersionedSignedProposal, broadcastMode BroadcastMode) (code int, err error) {
var uri string
headers := http.Header{}
headers.Add("Eth-Consensus-Version", block.Version.String()) // optional in v1, required in v2
Expand Down
4 changes: 2 additions & 2 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version s
BaseFeePerGas: uint256.NewInt(0),
},
BlobsBundle: &builderApiDeneb.BlobsBundle{
Commitments: []deneb.KzgCommitment{},
Proofs: []deneb.KzgProof{},
Commitments: []deneb.KZGCommitment{},
Proofs: []deneb.KZGProof{},
Blobs: []deneb.Blob{},
},
},
Expand Down
8 changes: 0 additions & 8 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type EthNetworkDetails struct {
DomainBeaconProposerBellatrix phase0.Domain
DomainBeaconProposerCapella phase0.Domain
DomainBeaconProposerDeneb phase0.Domain
DomainBlobSidecarDeneb phase0.Domain
}

func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error) {
Expand All @@ -64,7 +63,6 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error
var domainBeaconProposerBellatrix phase0.Domain
var domainBeaconProposerCapella phase0.Domain
var domainBeaconProposerDeneb phase0.Domain
var domainBlobSidecarDeneb phase0.Domain

switch networkName {
case EthNetworkSepolia:
Expand Down Expand Up @@ -115,11 +113,6 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error
return nil, err
}

domainBlobSidecarDeneb, err = ComputeDomain(boostSsz.DomainTypeBlobSidecar, denebForkVersion, genesisValidatorsRoot)
if err != nil {
return nil, err
}

return &EthNetworkDetails{
Name: networkName,
GenesisForkVersionHex: genesisForkVersion,
Expand All @@ -131,7 +124,6 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error
DomainBeaconProposerBellatrix: domainBeaconProposerBellatrix,
DomainBeaconProposerCapella: domainBeaconProposerCapella,
DomainBeaconProposerDeneb: domainBeaconProposerDeneb,
DomainBlobSidecarDeneb: domainBlobSidecarDeneb,
}, nil
}

Expand Down
75 changes: 26 additions & 49 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,11 @@ func BuilderBlockRequestToSignedBuilderBid(payload *VersionedSubmitBlockRequest,
}
blobRoots = append(blobRoots, root)
}
blindedBlobsBundle := builderApiDeneb.BlindedBlobsBundle{
Commitments: payload.Deneb.BlobsBundle.Commitments,
Proofs: payload.Deneb.BlobsBundle.Proofs,
BlobRoots: blobRoots,
}

builderBid := builderApiDeneb.BuilderBid{
Value: value,
Header: header.Deneb,
BlindedBlobsBundle: &blindedBlobsBundle,
BlobKZGCommitments: payload.Deneb.BlobsBundle.Commitments,
Value: value,
Pubkey: *pubkey,
}

Expand All @@ -174,9 +169,9 @@ func BuilderBlockRequestToSignedBuilderBid(payload *VersionedSubmitBlockRequest,
}
}

func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *VersionedSignedBlindedBlockRequest, blockPayload *builderApi.VersionedSubmitBlindedBlockResponse) (*VersionedSignedBlockRequest, error) {
signedBeaconBlock := VersionedSignedBlockRequest{
eth2Api.VersionedBlockRequest{ //nolint:exhaustruct
func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *VersionedSignedBlindedBeaconBlock, blockPayload *builderApi.VersionedSubmitBlindedBlockResponse) (*VersionedSignedProposal, error) {
signedBeaconBlock := VersionedSignedProposal{
eth2Api.VersionedSignedProposal{ //nolint:exhaustruct
Version: signedBlindedBeaconBlock.Version,
},
}
Expand All @@ -185,18 +180,16 @@ func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *VersionedSi
capellaBlindedBlock := signedBlindedBeaconBlock.Capella
signedBeaconBlock.Capella = CapellaUnblindSignedBlock(capellaBlindedBlock, blockPayload.Capella)
case spec.DataVersionDeneb:
denebBlindedBlobs := signedBlindedBeaconBlock.Deneb.SignedBlindedBlobSidecars
if len(denebBlindedBlobs) != len(blockPayload.Deneb.BlobsBundle.Blobs) {
denebBlindedBlock := signedBlindedBeaconBlock.Deneb
if len(denebBlindedBlock.Message.Body.BlobKZGCommitments) != len(blockPayload.Deneb.BlobsBundle.Blobs) {
return nil, errors.New("number of blinded blobs does not match blobs bundle length")
}

denebBlindedBlock := signedBlindedBeaconBlock.Deneb.SignedBlindedBlock
blockRoot, err := denebBlindedBlock.Message.HashTreeRoot()
if err != nil {
return nil, err
}

signedBeaconBlock.Deneb = DenebUnblindSignedBlock(denebBlindedBlock, denebBlindedBlobs, blockPayload.Deneb, blockRoot)
signedBeaconBlock.Deneb = DenebUnblindSignedBlock(denebBlindedBlock, blockPayload.Deneb, blockRoot)
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", signedBlindedBeaconBlock.Version.String()))
}
Expand Down Expand Up @@ -228,24 +221,7 @@ func CapellaUnblindSignedBlock(blindedBlock *eth2ApiV1Capella.SignedBlindedBeaco
}
}

func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlock, blindedBlobs []*eth2ApiV1Deneb.SignedBlindedBlobSidecar, blockPayload *builderApiDeneb.ExecutionPayloadAndBlobsBundle, blockRoot phase0.Root) *eth2ApiV1Deneb.SignedBlockContents {
denebBlobSidecars := make([]*deneb.SignedBlobSidecar, len(blockPayload.BlobsBundle.Blobs))

for i := range denebBlobSidecars {
denebBlobSidecars[i] = &deneb.SignedBlobSidecar{
Message: &deneb.BlobSidecar{
BlockRoot: blockRoot,
Index: deneb.BlobIndex(i),
Slot: blindedBlock.Message.Slot,
BlockParentRoot: blindedBlock.Message.ParentRoot,
ProposerIndex: blindedBlock.Message.ProposerIndex,
Blob: blockPayload.BlobsBundle.Blobs[i],
KzgCommitment: blockPayload.BlobsBundle.Commitments[i],
KzgProof: blockPayload.BlobsBundle.Proofs[i],
},
Signature: blindedBlobs[i].Signature,
}
}
func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlock, blockPayload *builderApiDeneb.ExecutionPayloadAndBlobsBundle, blockRoot phase0.Root) *eth2ApiV1Deneb.SignedBlockContents {
return &eth2ApiV1Deneb.SignedBlockContents{
SignedBlock: &deneb.SignedBeaconBlock{
Message: &deneb.BeaconBlock{
Expand All @@ -254,7 +230,6 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo
ParentRoot: blindedBlock.Message.ParentRoot,
StateRoot: blindedBlock.Message.StateRoot,
Body: &deneb.BeaconBlockBody{
BLSToExecutionChanges: blindedBlock.Message.Body.BLSToExecutionChanges,
RANDAOReveal: blindedBlock.Message.Body.RANDAOReveal,
ETH1Data: blindedBlock.Message.Body.ETH1Data,
Graffiti: blindedBlock.Message.Body.Graffiti,
Expand All @@ -265,12 +240,14 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo
VoluntaryExits: blindedBlock.Message.Body.VoluntaryExits,
SyncAggregate: blindedBlock.Message.Body.SyncAggregate,
ExecutionPayload: blockPayload.ExecutionPayload,
BlobKzgCommitments: blockPayload.BlobsBundle.Commitments,
BLSToExecutionChanges: blindedBlock.Message.Body.BLSToExecutionChanges,
BlobKZGCommitments: blindedBlock.Message.Body.BlobKZGCommitments,
},
},
Signature: blindedBlock.Signature,
},
SignedBlobSidecars: denebBlobSidecars,
KZGProofs: blockPayload.BlobsBundle.Proofs,
Blobs: blockPayload.BlobsBundle.Blobs,
}
}

Expand Down Expand Up @@ -368,11 +345,11 @@ func (r *VersionedSubmitBlockRequest) UnmarshalJSON(input []byte) error {
return errors.Wrap(err, "failed to unmarshal SubmitBlockRequest")
}

type VersionedSignedBlockRequest struct {
eth2Api.VersionedBlockRequest
type VersionedSignedProposal struct {
eth2Api.VersionedSignedProposal
}

func (r *VersionedSignedBlockRequest) MarshalSSZ() ([]byte, error) {
func (r *VersionedSignedProposal) MarshalSSZ() ([]byte, error) {
switch r.Version {
case spec.DataVersionCapella:
return r.Capella.MarshalSSZ()
Expand All @@ -385,7 +362,7 @@ func (r *VersionedSignedBlockRequest) MarshalSSZ() ([]byte, error) {
}
}

func (r *VersionedSignedBlockRequest) UnmarshalSSZ(input []byte) error {
func (r *VersionedSignedProposal) UnmarshalSSZ(input []byte) error {
var err error

denebRequest := new(eth2ApiV1Deneb.SignedBlockContents)
Expand All @@ -404,7 +381,7 @@ func (r *VersionedSignedBlockRequest) UnmarshalSSZ(input []byte) error {
return errors.Wrap(err, "failed to unmarshal SubmitBlockRequest SSZ")
}

func (r *VersionedSignedBlockRequest) MarshalJSON() ([]byte, error) {
func (r *VersionedSignedProposal) MarshalJSON() ([]byte, error) {
switch r.Version {
case spec.DataVersionCapella:
return json.Marshal(r.Capella)
Expand All @@ -417,7 +394,7 @@ func (r *VersionedSignedBlockRequest) MarshalJSON() ([]byte, error) {
}
}

func (r *VersionedSignedBlockRequest) UnmarshalJSON(input []byte) error {
func (r *VersionedSignedProposal) UnmarshalJSON(input []byte) error {
var err error

denebContents := new(eth2ApiV1Deneb.SignedBlockContents)
Expand All @@ -436,11 +413,11 @@ func (r *VersionedSignedBlockRequest) UnmarshalJSON(input []byte) error {
return errors.Wrap(err, "failed to unmarshal SignedBeaconBlockRequest")
}

type VersionedSignedBlindedBlockRequest struct {
eth2Api.VersionedBlindedBlockRequest
type VersionedSignedBlindedBeaconBlock struct {
eth2Api.VersionedSignedBlindedBeaconBlock
}

func (r *VersionedSignedBlindedBlockRequest) MarshalJSON() ([]byte, error) {
func (r *VersionedSignedBlindedBeaconBlock) MarshalJSON() ([]byte, error) {
switch r.Version {
case spec.DataVersionCapella:
return json.Marshal(r.Capella)
Expand All @@ -453,13 +430,13 @@ func (r *VersionedSignedBlindedBlockRequest) MarshalJSON() ([]byte, error) {
}
}

func (r *VersionedSignedBlindedBlockRequest) UnmarshalJSON(input []byte) error {
func (r *VersionedSignedBlindedBeaconBlock) UnmarshalJSON(input []byte) error {
var err error

denebContents := new(eth2ApiV1Deneb.SignedBlindedBlockContents)
if err = json.Unmarshal(input, denebContents); err == nil {
denebBlock := new(eth2ApiV1Deneb.SignedBlindedBeaconBlock)
if err = json.Unmarshal(input, denebBlock); err == nil {
r.Version = spec.DataVersionDeneb
r.Deneb = denebContents
r.Deneb = denebBlock
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions common/types_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestSignedBeaconBlockJSON(t *testing.T) {
require.NoError(t, err)
expectedJSONBytes := buffer.Bytes()

blockRequest := new(VersionedSignedBlockRequest)
blockRequest := new(VersionedSignedProposal)
err = json.Unmarshal(jsonBytes, blockRequest)
require.NoError(t, err)

Expand All @@ -57,7 +57,7 @@ func TestSignedBlindedBlockJSON(t *testing.T) {
require.NoError(t, err)
expectedJSONBytes := buffer.Bytes()

blockRequest := new(VersionedSignedBlindedBlockRequest)
blockRequest := new(VersionedSignedBlindedBeaconBlock)
err = json.Unmarshal(jsonBytes, blockRequest)
require.NoError(t, err)

Expand Down
8 changes: 4 additions & 4 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type IDatabaseService interface {
GetExecutionPayloads(idFirst, idLast uint64) (entries []*ExecutionPayloadEntry, err error)
DeleteExecutionPayloads(idFirst, idLast uint64) error

SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBlockRequest, signedAt time.Time, publishMs uint64) error
SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error
GetNumDeliveredPayloads() (uint64, error)
GetRecentDeliveredPayloads(filters GetPayloadsFilters) ([]*DeliveredPayloadEntry, error)
GetDeliveredPayloads(idFirst, idLast uint64) (entries []*DeliveredPayloadEntry, err error)
Expand All @@ -48,7 +48,7 @@ type IDatabaseService interface {
IncBlockBuilderStatsAfterGetPayload(builderPubkey string) error

InsertBuilderDemotion(submitBlockRequest *common.VersionedSubmitBlockRequest, simError error) error
UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedBlockRequest, signedRegistration *builderApiV1.SignedValidatorRegistration) error
UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedProposal, signedRegistration *builderApiV1.SignedValidatorRegistration) error
GetBuilderDemotion(trace *common.BidTraceV2) (*BuilderDemotionEntry, error)

GetTooLateGetPayload(slot uint64) (entries []*TooLateGetPayloadEntry, err error)
Expand Down Expand Up @@ -272,7 +272,7 @@ func (s *DatabaseService) GetExecutionPayloadEntryBySlotPkHash(slot uint64, prop
return entry, err
}

func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBlockRequest, signedAt time.Time, publishMs uint64) error {
func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error {
_signedBlindedBeaconBlock, err := json.Marshal(signedBlindedBeaconBlock)
if err != nil {
return err
Expand Down Expand Up @@ -574,7 +574,7 @@ func (s *DatabaseService) InsertBuilderDemotion(submitBlockRequest *common.Versi
return err
}

func (s *DatabaseService) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedBlockRequest, signedRegistration *builderApiV1.SignedValidatorRegistration) error {
func (s *DatabaseService) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedProposal, signedRegistration *builderApiV1.SignedValidatorRegistration) error {
_signedBeaconBlock, err := json.Marshal(signedBlock)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,22 @@ func TestUpdateBuilderDemotion(t *testing.T) {
cases := []struct {
name string
req *common.VersionedSubmitBlockRequest
beaconBlock *common.VersionedSignedBlockRequest
beaconBlock *common.VersionedSignedProposal
}{
{
name: "Capella",
req: common.TestBuilderSubmitBlockRequest(sk, bt, spec.DataVersionCapella),
beaconBlock: &common.VersionedSignedBlockRequest{
VersionedBlockRequest: eth2Api.VersionedBlockRequest{
beaconBlock: &common.VersionedSignedProposal{
VersionedSignedProposal: eth2Api.VersionedSignedProposal{
Version: spec.DataVersionCapella,
Capella: &capella.SignedBeaconBlock{},
},
},
}, {
name: "Deneb",
req: common.TestBuilderSubmitBlockRequest(sk, bt, spec.DataVersionDeneb),
beaconBlock: &common.VersionedSignedBlockRequest{
VersionedBlockRequest: eth2Api.VersionedBlockRequest{
beaconBlock: &common.VersionedSignedProposal{
VersionedSignedProposal: eth2Api.VersionedSignedProposal{
Version: spec.DataVersionDeneb,
Deneb: &eth2builderApiV1Deneb.SignedBlockContents{},
},
Expand Down
4 changes: 2 additions & 2 deletions database/mockdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (db MockDB) GetBuilderSubmissionsBySlots(slotFrom, slotTo uint64) (entries
return nil, nil
}

func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBlockRequest, signedAt time.Time, publishMs uint64) error {
func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error {
return nil
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func (db MockDB) InsertBuilderDemotion(submitBlockRequest *common.VersionedSubmi
return nil
}

func (db MockDB) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedBlockRequest, signedRegistration *builderApiV1.SignedValidatorRegistration) error {
func (db MockDB) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.VersionedSignedProposal, signedRegistration *builderApiV1.SignedValidatorRegistration) error {
pubkey := trace.BuilderPubkey.String()
_, ok := db.Builders[pubkey]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions datastore/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func testBuilderSubmitBlockRequest(pubkey phase0.BLSPubKey, signature phase0.BLS
Transactions: []bellatrix.Transaction{},
},
BlobsBundle: &builderApiDeneb.BlobsBundle{
Commitments: []deneb.KzgCommitment{},
Proofs: []deneb.KzgProof{},
Commitments: []deneb.KZGCommitment{},
Proofs: []deneb.KZGProof{},
Blobs: []deneb.Blob{},
},
},
Expand Down
Loading

0 comments on commit a509806

Please sign in to comment.