From fffe0f8c39e7b1bd0b1ffa7d2abfe845a4a8f24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Tue, 18 Jun 2024 16:31:27 +0200 Subject: [PATCH 1/9] core/validatorapi: convert blinded to full proposal Shortcut `/eth/v2/beacon/blinded_blocks/submit_blinded_block_v2` to use newer proposals rather than blinded block proposals. --- core/bcast/bcast.go | 3 +- core/validatorapi/validatorapi.go | 20 ++++++- core/validatorapi/validatorapi_test.go | 11 ++-- testutil/validatormock/propose.go | 83 ++++++++++++-------------- 4 files changed, 66 insertions(+), 51 deletions(-) diff --git a/core/bcast/bcast.go b/core/bcast/bcast.go index ccf65de2b..f417d8533 100644 --- a/core/bcast/bcast.go +++ b/core/bcast/bcast.go @@ -6,6 +6,7 @@ package bcast import ( "context" + "fmt" "strings" "time" @@ -75,7 +76,7 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, set core.Sig block, ok := aggData.(core.VersionedSignedProposal) if !ok { - return errors.New("invalid proposal") + return errors.New("invalid proposal", z.Str("data", fmt.Sprintf("%+v", aggData))) } err = b.eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ diff --git a/core/validatorapi/validatorapi.go b/core/validatorapi/validatorapi.go index 80c795314..03ed58613 100644 --- a/core/validatorapi/validatorapi.go +++ b/core/validatorapi/validatorapi.go @@ -12,6 +12,7 @@ import ( eth2api "github.com/attestantio/go-eth2-client/api" eth2v1 "github.com/attestantio/go-eth2-client/api/v1" + eth2spec "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" "go.opentelemetry.io/otel/trace" @@ -448,7 +449,24 @@ func (c Component) SubmitBlindedProposal(ctx context.Context, opts *eth2api.Subm duty := core.NewProposerDuty(uint64(slot)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) - signedData, err := core.NewPartialVersionedSignedBlindedProposal(opts.Proposal, c.shareIdx) + // Translate old blinded block request to new VersionedSignedProposal universal type. + + signedBlock := new(eth2api.VersionedSignedProposal) + signedBlock.Version = opts.Proposal.Version + signedBlock.Blinded = true + + switch signedBlock.Version { + case eth2spec.DataVersionBellatrix: + signedBlock.BellatrixBlinded = opts.Proposal.Bellatrix + case eth2spec.DataVersionCapella: + signedBlock.CapellaBlinded = opts.Proposal.Capella + case eth2spec.DataVersionDeneb: + signedBlock.DenebBlinded = opts.Proposal.Deneb + default: + return errors.New("invalid blinded block") + } + + signedData, err := core.NewPartialVersionedSignedProposal(signedBlock, c.shareIdx) if err != nil { return err } diff --git a/core/validatorapi/validatorapi_test.go b/core/validatorapi/validatorapi_test.go index aac0128d4..4f8165cc9 100644 --- a/core/validatorapi/validatorapi_test.go +++ b/core/validatorapi/validatorapi_test.go @@ -692,9 +692,10 @@ func TestComponent_SubmitBlindedProposal(t *testing.T) { s, err := tbls.Sign(secret, sigData[:]) require.NoError(t, err) - signedBlindedBlock := ð2api.VersionedSignedBlindedProposal{ + signedBlindedBlock := ð2api.VersionedSignedProposal{ Version: eth2spec.DataVersionCapella, - Capella: ð2capella.SignedBlindedBeaconBlock{ + Blinded: true, + CapellaBlinded: ð2capella.SignedBlindedBeaconBlock{ Message: unsignedBlindedBlock, Signature: eth2p0.BLSSignature(s), }, @@ -702,14 +703,14 @@ func TestComponent_SubmitBlindedProposal(t *testing.T) { // Register subscriber vapi.Subscribe(func(ctx context.Context, duty core.Duty, set core.ParSignedDataSet) error { - block, ok := set[corePubKey].SignedData.(core.VersionedSignedBlindedProposal) + block, ok := set[corePubKey].SignedData.(core.VersionedSignedProposal) require.True(t, ok) - require.Equal(t, *signedBlindedBlock, block.VersionedSignedBlindedProposal) + require.Equal(t, *signedBlindedBlock, block.VersionedSignedProposal) return nil }) - err = vapi.SubmitBlindedProposal(ctx, ð2api.SubmitBlindedProposalOpts{ + err = vapi.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ Proposal: signedBlindedBlock, }) require.NoError(t, err) diff --git a/testutil/validatormock/propose.go b/testutil/validatormock/propose.go index 8755c5ee5..788c5c429 100644 --- a/testutil/validatormock/propose.go +++ b/testutil/validatormock/propose.go @@ -126,69 +126,64 @@ func ProposeBlock(ctx context.Context, eth2Cl eth2wrap.Client, signFunc SignFunc return err } + signedBlock := new(eth2api.VersionedSignedProposal) + signedBlock.Version = block.Version + if block.Blinded { - signedBlock := new(eth2api.VersionedSignedBlindedProposal) - signedBlock.Version = block.Version switch block.Version { case eth2spec.DataVersionBellatrix: - signedBlock.Bellatrix = ð2bellatrix.SignedBlindedBeaconBlock{ + signedBlock.BellatrixBlinded = ð2bellatrix.SignedBlindedBeaconBlock{ Message: block.BellatrixBlinded, Signature: sig, } case eth2spec.DataVersionCapella: - signedBlock.Capella = ð2capella.SignedBlindedBeaconBlock{ + signedBlock.CapellaBlinded = ð2capella.SignedBlindedBeaconBlock{ Message: block.CapellaBlinded, Signature: sig, } case eth2spec.DataVersionDeneb: - signedBlock.Deneb = ð2deneb.SignedBlindedBeaconBlock{ + signedBlock.DenebBlinded = ð2deneb.SignedBlindedBeaconBlock{ Message: block.DenebBlinded, Signature: sig, } default: return errors.New("invalid blinded block") } - - return eth2Cl.SubmitBlindedProposal(ctx, ð2api.SubmitBlindedProposalOpts{ - Proposal: signedBlock, - }) - } - - // Full block - signedBlock := new(eth2api.VersionedSignedProposal) - signedBlock.Version = block.Version - switch block.Version { - case eth2spec.DataVersionPhase0: - signedBlock.Phase0 = ð2p0.SignedBeaconBlock{ - Message: block.Phase0, - Signature: sig, - } - case eth2spec.DataVersionAltair: - signedBlock.Altair = &altair.SignedBeaconBlock{ - Message: block.Altair, - Signature: sig, - } - case eth2spec.DataVersionBellatrix: - signedBlock.Bellatrix = &bellatrix.SignedBeaconBlock{ - Message: block.Bellatrix, - Signature: sig, - } - case eth2spec.DataVersionCapella: - signedBlock.Capella = &capella.SignedBeaconBlock{ - Message: block.Capella, - Signature: sig, - } - case eth2spec.DataVersionDeneb: - signedBlock.Deneb = ð2deneb.SignedBlockContents{ - SignedBlock: &deneb.SignedBeaconBlock{ - Message: block.Deneb.Block, + } else { + // Full block + switch block.Version { + case eth2spec.DataVersionPhase0: + signedBlock.Phase0 = ð2p0.SignedBeaconBlock{ + Message: block.Phase0, Signature: sig, - }, - KZGProofs: block.Deneb.KZGProofs, - Blobs: block.Deneb.Blobs, + } + case eth2spec.DataVersionAltair: + signedBlock.Altair = &altair.SignedBeaconBlock{ + Message: block.Altair, + Signature: sig, + } + case eth2spec.DataVersionBellatrix: + signedBlock.Bellatrix = &bellatrix.SignedBeaconBlock{ + Message: block.Bellatrix, + Signature: sig, + } + case eth2spec.DataVersionCapella: + signedBlock.Capella = &capella.SignedBeaconBlock{ + Message: block.Capella, + Signature: sig, + } + case eth2spec.DataVersionDeneb: + signedBlock.Deneb = ð2deneb.SignedBlockContents{ + SignedBlock: &deneb.SignedBeaconBlock{ + Message: block.Deneb.Block, + Signature: sig, + }, + KZGProofs: block.Deneb.KZGProofs, + Blobs: block.Deneb.Blobs, + } + default: + return errors.New("invalid block") } - default: - return errors.New("invalid block") } return eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{Proposal: signedBlock}) From 6c006de6019301819daf19cfa38b2cdc7e43034e Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev Date: Tue, 18 Jun 2024 20:19:14 +0300 Subject: [PATCH 2/9] Add blinded blocks to IsSyntheticProposal --- app/eth2wrap/synthproposer.go | 39 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/app/eth2wrap/synthproposer.go b/app/eth2wrap/synthproposer.go index 6ffe96336..718137c8a 100644 --- a/app/eth2wrap/synthproposer.go +++ b/app/eth2wrap/synthproposer.go @@ -235,19 +235,32 @@ func IsSyntheticBlindedBlock(block *eth2api.VersionedSignedBlindedProposal) bool // IsSyntheticProposal returns true if the block is a synthetic block proposal. func IsSyntheticProposal(block *eth2api.VersionedSignedProposal) bool { var graffiti [32]byte - switch block.Version { - case eth2spec.DataVersionPhase0: - graffiti = block.Phase0.Message.Body.Graffiti - case eth2spec.DataVersionAltair: - graffiti = block.Altair.Message.Body.Graffiti - case eth2spec.DataVersionBellatrix: - graffiti = block.Bellatrix.Message.Body.Graffiti - case eth2spec.DataVersionCapella: - graffiti = block.Capella.Message.Body.Graffiti - case eth2spec.DataVersionDeneb: - graffiti = block.Deneb.SignedBlock.Message.Body.Graffiti - default: - return false + if block.Blinded { + switch block.Version { + case eth2spec.DataVersionBellatrix: + graffiti = block.BellatrixBlinded.Message.Body.Graffiti + case eth2spec.DataVersionCapella: + graffiti = block.CapellaBlinded.Message.Body.Graffiti + case eth2spec.DataVersionDeneb: + graffiti = block.DenebBlinded.Message.Body.Graffiti + default: + return false + } + } else { + switch block.Version { + case eth2spec.DataVersionPhase0: + graffiti = block.Phase0.Message.Body.Graffiti + case eth2spec.DataVersionAltair: + graffiti = block.Altair.Message.Body.Graffiti + case eth2spec.DataVersionBellatrix: + graffiti = block.Bellatrix.Message.Body.Graffiti + case eth2spec.DataVersionCapella: + graffiti = block.Capella.Message.Body.Graffiti + case eth2spec.DataVersionDeneb: + graffiti = block.Deneb.SignedBlock.Message.Body.Graffiti + default: + return false + } } return graffiti == GetSyntheticGraffiti() From 23f2f0cc000ec681f0b9ee2706d5e839887fa446 Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev Date: Tue, 18 Jun 2024 20:48:21 +0300 Subject: [PATCH 3/9] Add blinded variable for unmarshaling upon creation of struct --- core/signeddata.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/signeddata.go b/core/signeddata.go index 9cd127b3c..9187d700e 100644 --- a/core/signeddata.go +++ b/core/signeddata.go @@ -357,7 +357,10 @@ func (p *VersionedSignedProposal) UnmarshalJSON(input []byte) error { return errors.Wrap(err, "unmarshal block") } - resp := eth2api.VersionedSignedProposal{Version: raw.Version.ToETH2()} + resp := eth2api.VersionedSignedProposal{ + Version: raw.Version.ToETH2(), + Blinded: raw.Blinded, + } switch resp.Version { case eth2spec.DataVersionPhase0: block := new(eth2p0.SignedBeaconBlock) @@ -417,8 +420,6 @@ func (p *VersionedSignedProposal) UnmarshalJSON(input []byte) error { return errors.New("unknown version") } - resp.Blinded = raw.Blinded - p.VersionedSignedProposal = resp return nil From 7f1ad14dcbcf271bb042360411e233b1496cf25b Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev Date: Tue, 18 Jun 2024 20:49:42 +0300 Subject: [PATCH 4/9] Add blinded flag to signedBlock in func ProposeBlock for validatormockB --- testutil/validatormock/propose.go | 1 + 1 file changed, 1 insertion(+) diff --git a/testutil/validatormock/propose.go b/testutil/validatormock/propose.go index 788c5c429..299f4282d 100644 --- a/testutil/validatormock/propose.go +++ b/testutil/validatormock/propose.go @@ -128,6 +128,7 @@ func ProposeBlock(ctx context.Context, eth2Cl eth2wrap.Client, signFunc SignFunc signedBlock := new(eth2api.VersionedSignedProposal) signedBlock.Version = block.Version + signedBlock.Blinded = block.Blinded if block.Blinded { switch block.Version { From 5466dddbb69c20b0c2a61323edee388fddd874da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 20 Jun 2024 15:34:33 +0200 Subject: [PATCH 5/9] Revert "Add blinded flag to signedBlock in func ProposeBlock for validatormockB" This reverts commit 7f1ad14dcbcf271bb042360411e233b1496cf25b. --- testutil/validatormock/propose.go | 1 - 1 file changed, 1 deletion(-) diff --git a/testutil/validatormock/propose.go b/testutil/validatormock/propose.go index 299f4282d..788c5c429 100644 --- a/testutil/validatormock/propose.go +++ b/testutil/validatormock/propose.go @@ -128,7 +128,6 @@ func ProposeBlock(ctx context.Context, eth2Cl eth2wrap.Client, signFunc SignFunc signedBlock := new(eth2api.VersionedSignedProposal) signedBlock.Version = block.Version - signedBlock.Blinded = block.Blinded if block.Blinded { switch block.Version { From 27531f272cdaeb4de09692bd82212074e15a99d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 20 Jun 2024 15:34:45 +0200 Subject: [PATCH 6/9] Revert "Add blinded variable for unmarshaling upon creation of struct" This reverts commit 23f2f0cc000ec681f0b9ee2706d5e839887fa446. --- core/signeddata.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/signeddata.go b/core/signeddata.go index 9187d700e..9cd127b3c 100644 --- a/core/signeddata.go +++ b/core/signeddata.go @@ -357,10 +357,7 @@ func (p *VersionedSignedProposal) UnmarshalJSON(input []byte) error { return errors.Wrap(err, "unmarshal block") } - resp := eth2api.VersionedSignedProposal{ - Version: raw.Version.ToETH2(), - Blinded: raw.Blinded, - } + resp := eth2api.VersionedSignedProposal{Version: raw.Version.ToETH2()} switch resp.Version { case eth2spec.DataVersionPhase0: block := new(eth2p0.SignedBeaconBlock) @@ -420,6 +417,8 @@ func (p *VersionedSignedProposal) UnmarshalJSON(input []byte) error { return errors.New("unknown version") } + resp.Blinded = raw.Blinded + p.VersionedSignedProposal = resp return nil From 09c66c9119768299139c1777fbac7515ce183b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 20 Jun 2024 15:34:47 +0200 Subject: [PATCH 7/9] Revert "Add blinded blocks to IsSyntheticProposal" This reverts commit 6c006de6019301819daf19cfa38b2cdc7e43034e. --- app/eth2wrap/synthproposer.go | 39 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/app/eth2wrap/synthproposer.go b/app/eth2wrap/synthproposer.go index 718137c8a..6ffe96336 100644 --- a/app/eth2wrap/synthproposer.go +++ b/app/eth2wrap/synthproposer.go @@ -235,32 +235,19 @@ func IsSyntheticBlindedBlock(block *eth2api.VersionedSignedBlindedProposal) bool // IsSyntheticProposal returns true if the block is a synthetic block proposal. func IsSyntheticProposal(block *eth2api.VersionedSignedProposal) bool { var graffiti [32]byte - if block.Blinded { - switch block.Version { - case eth2spec.DataVersionBellatrix: - graffiti = block.BellatrixBlinded.Message.Body.Graffiti - case eth2spec.DataVersionCapella: - graffiti = block.CapellaBlinded.Message.Body.Graffiti - case eth2spec.DataVersionDeneb: - graffiti = block.DenebBlinded.Message.Body.Graffiti - default: - return false - } - } else { - switch block.Version { - case eth2spec.DataVersionPhase0: - graffiti = block.Phase0.Message.Body.Graffiti - case eth2spec.DataVersionAltair: - graffiti = block.Altair.Message.Body.Graffiti - case eth2spec.DataVersionBellatrix: - graffiti = block.Bellatrix.Message.Body.Graffiti - case eth2spec.DataVersionCapella: - graffiti = block.Capella.Message.Body.Graffiti - case eth2spec.DataVersionDeneb: - graffiti = block.Deneb.SignedBlock.Message.Body.Graffiti - default: - return false - } + switch block.Version { + case eth2spec.DataVersionPhase0: + graffiti = block.Phase0.Message.Body.Graffiti + case eth2spec.DataVersionAltair: + graffiti = block.Altair.Message.Body.Graffiti + case eth2spec.DataVersionBellatrix: + graffiti = block.Bellatrix.Message.Body.Graffiti + case eth2spec.DataVersionCapella: + graffiti = block.Capella.Message.Body.Graffiti + case eth2spec.DataVersionDeneb: + graffiti = block.Deneb.SignedBlock.Message.Body.Graffiti + default: + return false } return graffiti == GetSyntheticGraffiti() From 2397a2a36b8602fa6809a43ac731b551336ea86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 20 Jun 2024 15:34:48 +0200 Subject: [PATCH 8/9] Revert "core/validatorapi: convert blinded to full proposal" This reverts commit fffe0f8c39e7b1bd0b1ffa7d2abfe845a4a8f24b. --- core/bcast/bcast.go | 3 +- core/validatorapi/validatorapi.go | 20 +------ core/validatorapi/validatorapi_test.go | 11 ++-- testutil/validatormock/propose.go | 83 ++++++++++++++------------ 4 files changed, 51 insertions(+), 66 deletions(-) diff --git a/core/bcast/bcast.go b/core/bcast/bcast.go index f417d8533..ccf65de2b 100644 --- a/core/bcast/bcast.go +++ b/core/bcast/bcast.go @@ -6,7 +6,6 @@ package bcast import ( "context" - "fmt" "strings" "time" @@ -76,7 +75,7 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, set core.Sig block, ok := aggData.(core.VersionedSignedProposal) if !ok { - return errors.New("invalid proposal", z.Str("data", fmt.Sprintf("%+v", aggData))) + return errors.New("invalid proposal") } err = b.eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ diff --git a/core/validatorapi/validatorapi.go b/core/validatorapi/validatorapi.go index 03ed58613..80c795314 100644 --- a/core/validatorapi/validatorapi.go +++ b/core/validatorapi/validatorapi.go @@ -12,7 +12,6 @@ import ( eth2api "github.com/attestantio/go-eth2-client/api" eth2v1 "github.com/attestantio/go-eth2-client/api/v1" - eth2spec "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" "go.opentelemetry.io/otel/trace" @@ -449,24 +448,7 @@ func (c Component) SubmitBlindedProposal(ctx context.Context, opts *eth2api.Subm duty := core.NewProposerDuty(uint64(slot)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) - // Translate old blinded block request to new VersionedSignedProposal universal type. - - signedBlock := new(eth2api.VersionedSignedProposal) - signedBlock.Version = opts.Proposal.Version - signedBlock.Blinded = true - - switch signedBlock.Version { - case eth2spec.DataVersionBellatrix: - signedBlock.BellatrixBlinded = opts.Proposal.Bellatrix - case eth2spec.DataVersionCapella: - signedBlock.CapellaBlinded = opts.Proposal.Capella - case eth2spec.DataVersionDeneb: - signedBlock.DenebBlinded = opts.Proposal.Deneb - default: - return errors.New("invalid blinded block") - } - - signedData, err := core.NewPartialVersionedSignedProposal(signedBlock, c.shareIdx) + signedData, err := core.NewPartialVersionedSignedBlindedProposal(opts.Proposal, c.shareIdx) if err != nil { return err } diff --git a/core/validatorapi/validatorapi_test.go b/core/validatorapi/validatorapi_test.go index 4f8165cc9..aac0128d4 100644 --- a/core/validatorapi/validatorapi_test.go +++ b/core/validatorapi/validatorapi_test.go @@ -692,10 +692,9 @@ func TestComponent_SubmitBlindedProposal(t *testing.T) { s, err := tbls.Sign(secret, sigData[:]) require.NoError(t, err) - signedBlindedBlock := ð2api.VersionedSignedProposal{ + signedBlindedBlock := ð2api.VersionedSignedBlindedProposal{ Version: eth2spec.DataVersionCapella, - Blinded: true, - CapellaBlinded: ð2capella.SignedBlindedBeaconBlock{ + Capella: ð2capella.SignedBlindedBeaconBlock{ Message: unsignedBlindedBlock, Signature: eth2p0.BLSSignature(s), }, @@ -703,14 +702,14 @@ func TestComponent_SubmitBlindedProposal(t *testing.T) { // Register subscriber vapi.Subscribe(func(ctx context.Context, duty core.Duty, set core.ParSignedDataSet) error { - block, ok := set[corePubKey].SignedData.(core.VersionedSignedProposal) + block, ok := set[corePubKey].SignedData.(core.VersionedSignedBlindedProposal) require.True(t, ok) - require.Equal(t, *signedBlindedBlock, block.VersionedSignedProposal) + require.Equal(t, *signedBlindedBlock, block.VersionedSignedBlindedProposal) return nil }) - err = vapi.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ + err = vapi.SubmitBlindedProposal(ctx, ð2api.SubmitBlindedProposalOpts{ Proposal: signedBlindedBlock, }) require.NoError(t, err) diff --git a/testutil/validatormock/propose.go b/testutil/validatormock/propose.go index 788c5c429..8755c5ee5 100644 --- a/testutil/validatormock/propose.go +++ b/testutil/validatormock/propose.go @@ -126,64 +126,69 @@ func ProposeBlock(ctx context.Context, eth2Cl eth2wrap.Client, signFunc SignFunc return err } - signedBlock := new(eth2api.VersionedSignedProposal) - signedBlock.Version = block.Version - if block.Blinded { + signedBlock := new(eth2api.VersionedSignedBlindedProposal) + signedBlock.Version = block.Version switch block.Version { case eth2spec.DataVersionBellatrix: - signedBlock.BellatrixBlinded = ð2bellatrix.SignedBlindedBeaconBlock{ + signedBlock.Bellatrix = ð2bellatrix.SignedBlindedBeaconBlock{ Message: block.BellatrixBlinded, Signature: sig, } case eth2spec.DataVersionCapella: - signedBlock.CapellaBlinded = ð2capella.SignedBlindedBeaconBlock{ + signedBlock.Capella = ð2capella.SignedBlindedBeaconBlock{ Message: block.CapellaBlinded, Signature: sig, } case eth2spec.DataVersionDeneb: - signedBlock.DenebBlinded = ð2deneb.SignedBlindedBeaconBlock{ + signedBlock.Deneb = ð2deneb.SignedBlindedBeaconBlock{ Message: block.DenebBlinded, Signature: sig, } default: return errors.New("invalid blinded block") } - } else { - // Full block - switch block.Version { - case eth2spec.DataVersionPhase0: - signedBlock.Phase0 = ð2p0.SignedBeaconBlock{ - Message: block.Phase0, - Signature: sig, - } - case eth2spec.DataVersionAltair: - signedBlock.Altair = &altair.SignedBeaconBlock{ - Message: block.Altair, - Signature: sig, - } - case eth2spec.DataVersionBellatrix: - signedBlock.Bellatrix = &bellatrix.SignedBeaconBlock{ - Message: block.Bellatrix, - Signature: sig, - } - case eth2spec.DataVersionCapella: - signedBlock.Capella = &capella.SignedBeaconBlock{ - Message: block.Capella, + + return eth2Cl.SubmitBlindedProposal(ctx, ð2api.SubmitBlindedProposalOpts{ + Proposal: signedBlock, + }) + } + + // Full block + signedBlock := new(eth2api.VersionedSignedProposal) + signedBlock.Version = block.Version + switch block.Version { + case eth2spec.DataVersionPhase0: + signedBlock.Phase0 = ð2p0.SignedBeaconBlock{ + Message: block.Phase0, + Signature: sig, + } + case eth2spec.DataVersionAltair: + signedBlock.Altair = &altair.SignedBeaconBlock{ + Message: block.Altair, + Signature: sig, + } + case eth2spec.DataVersionBellatrix: + signedBlock.Bellatrix = &bellatrix.SignedBeaconBlock{ + Message: block.Bellatrix, + Signature: sig, + } + case eth2spec.DataVersionCapella: + signedBlock.Capella = &capella.SignedBeaconBlock{ + Message: block.Capella, + Signature: sig, + } + case eth2spec.DataVersionDeneb: + signedBlock.Deneb = ð2deneb.SignedBlockContents{ + SignedBlock: &deneb.SignedBeaconBlock{ + Message: block.Deneb.Block, Signature: sig, - } - case eth2spec.DataVersionDeneb: - signedBlock.Deneb = ð2deneb.SignedBlockContents{ - SignedBlock: &deneb.SignedBeaconBlock{ - Message: block.Deneb.Block, - Signature: sig, - }, - KZGProofs: block.Deneb.KZGProofs, - Blobs: block.Deneb.Blobs, - } - default: - return errors.New("invalid block") + }, + KZGProofs: block.Deneb.KZGProofs, + Blobs: block.Deneb.Blobs, } + default: + return errors.New("invalid block") } return eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{Proposal: signedBlock}) From 17c38eefb4d2b27bd2dbdcfdb4b59acccb7d0d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 20 Jun 2024 15:36:26 +0200 Subject: [PATCH 9/9] core/bcast: switch on proposal type Allow both blinded and full block proposals since v2 proposal APIs still differentiate between the two --- core/bcast/bcast.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/core/bcast/bcast.go b/core/bcast/bcast.go index ccf65de2b..379031243 100644 --- a/core/bcast/bcast.go +++ b/core/bcast/bcast.go @@ -73,18 +73,39 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, set core.Sig return err } - block, ok := aggData.(core.VersionedSignedProposal) + var ( + block core.VersionedSignedProposal + blindedBlock core.VersionedSignedBlindedProposal + + blinded bool + ok bool + ) + + block, ok = aggData.(core.VersionedSignedProposal) if !ok { - return errors.New("invalid proposal") + // check if it's a blinded proposal + blindedBlock, blinded = aggData.(core.VersionedSignedBlindedProposal) + if !blinded { + return errors.New("invalid proposal") + } + } + + switch blinded { + case true: + err = b.eth2Cl.SubmitBlindedProposal(ctx, ð2api.SubmitBlindedProposalOpts{ + Proposal: &blindedBlock.VersionedSignedBlindedProposal, + }) + default: + err = b.eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ + Proposal: &block.VersionedSignedProposal, + }) } - err = b.eth2Cl.SubmitProposal(ctx, ð2api.SubmitProposalOpts{ - Proposal: &block.VersionedSignedProposal, - }) if err == nil { log.Info(ctx, "Successfully submitted block proposal to beacon node", z.Any("delay", b.delayFunc(duty.Slot)), z.Any("pubkey", pubkey), + z.Bool("blinded", blinded), ) }