Skip to content

Commit

Permalink
core/tracker: track blinded proposals (#3149)
Browse files Browse the repository at this point in the history
Do the same type casting we do in core/bcast to switch on the type of block proposal.

Add a test to check for this property.

category: bug
ticket: none
  • Loading branch information
gsora authored Jun 22, 2024
1 parent 80d55bc commit b66e063
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
34 changes: 28 additions & 6 deletions core/tracker/inclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,37 @@ func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.
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")
}
}
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
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
}
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
}
}
} else if duty.Type == core.DutyBuilderProposer {
return core.ErrDeprecatedDutyBuilderProposer
Expand Down
36 changes: 33 additions & 3 deletions core/tracker/tracker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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"
Expand Down Expand Up @@ -1111,12 +1113,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 +1153,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 +1321,16 @@ 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)
}

0 comments on commit b66e063

Please sign in to comment.