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

*: cherry-pick for v1.0.0-rc7 #3154

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 26 additions & 5 deletions core/bcast/bcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,39 @@
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")
}

Check warning on line 90 in core/bcast/bcast.go

View check run for this annotation

Codecov / codecov/patch

core/bcast/bcast.go#L86-L90

Added lines #L86 - L90 were not covered by tests
}

switch blinded {
case true:
err = b.eth2Cl.SubmitBlindedProposal(ctx, &eth2api.SubmitBlindedProposalOpts{
Proposal: &blindedBlock.VersionedSignedBlindedProposal,
})

Check warning on line 97 in core/bcast/bcast.go

View check run for this annotation

Codecov / codecov/patch

core/bcast/bcast.go#L94-L97

Added lines #L94 - L97 were not covered by tests
default:
err = b.eth2Cl.SubmitProposal(ctx, &eth2api.SubmitProposalOpts{
Proposal: &block.VersionedSignedProposal,
})
}

err = b.eth2Cl.SubmitProposal(ctx, &eth2api.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),
)
}

Expand Down
53 changes: 44 additions & 9 deletions core/tracker/inclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@

// Submitted is called when a duty is submitted to the beacon node.
// It adds the duty to the list of submitted duties.
func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.SignedData, delay time.Duration) error {
func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.SignedData, delay time.Duration) (err error) {
if !inclSupported[duty.Type] {
return nil
}

var (
attRoot eth2p0.Root
err error
)
if duty.Type == core.DutyAttester {
att, ok := data.(core.Attestation)
Expand All @@ -104,15 +103,51 @@
return errors.Wrap(err, "hash aggregate")
}
} else if duty.Type == core.DutyProposer {
proposal, ok := data.(core.VersionedSignedProposal)
var (
block core.VersionedSignedProposal
blindedBlock core.VersionedSignedBlindedProposal

blinded bool
ok bool
)

block, ok = data.(core.VersionedSignedProposal)
if !ok {
return errors.New("invalid block")
blindedBlock, blinded = data.(core.VersionedSignedBlindedProposal)
if !blinded {
return errors.New("invalid block")
}

Check warning on line 119 in core/tracker/inclusion.go

View check run for this annotation

Codecov / codecov/patch

core/tracker/inclusion.go#L118-L119

Added lines #L118 - L119 were not covered by tests
}
if eth2wrap.IsSyntheticProposal(&proposal.VersionedSignedProposal) {
// Report inclusion for synthetic blocks as it is already included on-chain.
i.trackerInclFunc(duty, pubkey, data, nil)

return nil
defer func() {
if r := recover(); r != nil {
proposal := fmt.Sprintf("%+v", block)
if blinded {
proposal = fmt.Sprintf("%+v", blindedBlock)
}

err = errors.New("could not determine if proposal was synthetic or not",
z.Str("proposal", proposal),
z.Bool("blinded", blinded),
)
}
}()

switch blinded {
case true:
if eth2wrap.IsSyntheticBlindedBlock(&blindedBlock.VersionedSignedBlindedProposal) {
// Report inclusion for synthetic blocks as it is already included on-chain.
i.trackerInclFunc(duty, pubkey, data, nil)

return nil
}

Check warning on line 143 in core/tracker/inclusion.go

View check run for this annotation

Codecov / codecov/patch

core/tracker/inclusion.go#L139-L143

Added lines #L139 - L143 were not covered by tests
default:
if eth2wrap.IsSyntheticProposal(&block.VersionedSignedProposal) {
// Report inclusion for synthetic blocks as it is already included on-chain.
i.trackerInclFunc(duty, pubkey, data, nil)

return nil
}

Check warning on line 150 in core/tracker/inclusion.go

View check run for this annotation

Codecov / codecov/patch

core/tracker/inclusion.go#L146-L150

Added lines #L146 - L150 were not covered by tests
}
} else if duty.Type == core.DutyBuilderProposer {
return core.ErrDeprecatedDutyBuilderProposer
Expand All @@ -130,7 +165,7 @@
Delay: delay,
}

return nil
return err
}

// Trim removes all duties that are older than the specified slot.
Expand Down
46 changes: 43 additions & 3 deletions core/tracker/tracker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"math/rand"
"net/http"
"reflect"
"sync"
"testing"
"time"

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"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -1111,12 +1114,26 @@ func TestIsParSigEventExpected(t *testing.T) {
}

func TestAnalyseParSigs(t *testing.T) {
t.Run("full block", func(t *testing.T) {
analyseParSigs(t, func() core.SignedData {
return testutil.RandomDenebCoreVersionedSignedProposal()
})
})

t.Run("blinded block", func(t *testing.T) {
analyseParSigs(t, func() core.SignedData {
return testutil.RandomDenebVersionedSignedBlindedProposal()
})
})
}

func analyseParSigs(t *testing.T, dataGen func() core.SignedData) {
t.Helper()
require.Empty(t, extractParSigs(context.Background(), nil))

var events []event

makeEvents := func(n int, pubkey string) {
data := testutil.RandomBellatrixCoreVersionedSignedProposal()
makeEvents := func(n int, pubkey string, data core.SignedData) {
offset := len(events)
for i := 0; i < n; i++ {
data, err := data.SetSignature(testutil.RandomCoreSignature())
Expand All @@ -1137,7 +1154,8 @@ func TestAnalyseParSigs(t *testing.T) {
6: "b",
}
for n, pubkey := range expect {
makeEvents(n, pubkey)
data := dataGen()
makeEvents(n, pubkey, data)
}

allParSigMsgs := extractParSigs(context.Background(), events)
Expand Down Expand Up @@ -1304,3 +1322,25 @@ func TestIgnoreUnsupported(t *testing.T) {
func randomStep() step {
return step(rand.Intn(int(sentinel)))
}

func TestSubmittedProposals(t *testing.T) {
ic := inclusionCore{
mu: sync.Mutex{},
submissions: make(map[subkey]submission),
}

err := ic.Submitted(core.NewProposerDuty(42), testutil.RandomCorePubKey(t), testutil.RandomDenebCoreVersionedSignedProposal(), 1*time.Millisecond)
require.NoError(t, err)

err = ic.Submitted(core.NewProposerDuty(42), testutil.RandomCorePubKey(t), testutil.RandomDenebVersionedSignedBlindedProposal(), 1*time.Millisecond)
require.NoError(t, err)

require.NotPanics(t, func() {
err = ic.Submitted(core.NewProposerDuty(42), testutil.RandomCorePubKey(t), core.VersionedSignedBlindedProposal{
VersionedSignedBlindedProposal: eth2api.VersionedSignedBlindedProposal{
Version: eth2spec.DataVersionDeneb,
},
}, 1*time.Millisecond)
require.ErrorContains(t, err, "could not determine if proposal was synthetic or not")
})
}
Loading