diff --git a/core/dutydb/memory.go b/core/dutydb/memory.go index 76b3fd331..e6e1ac283 100644 --- a/core/dutydb/memory.go +++ b/core/dutydb/memory.go @@ -155,14 +155,14 @@ func (db *MemDB) Store(_ context.Context, duty core.Duty, unsignedSet core.Unsig } // AwaitProposal implements core.DutyDB, see its godoc. -func (db *MemDB) AwaitProposal(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error) { +func (db *MemDB) AwaitProposal(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *eth2api.VersionedProposal, 1) db.mu.Lock() db.proQueries = append(db.proQueries, proQuery{ - Key: int64(opts.Slot), + Key: slot, Response: response, Cancel: cancel, }) @@ -180,14 +180,14 @@ func (db *MemDB) AwaitProposal(ctx context.Context, opts *eth2api.ProposalOpts) } // AwaitBlindedProposal implements core.DutyDB, see its godoc. -func (db *MemDB) AwaitBlindedProposal(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error) { +func (db *MemDB) AwaitBlindedProposal(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *eth2api.VersionedBlindedProposal, 1) db.mu.Lock() db.builderProQueries = append(db.builderProQueries, builderProQuery{ - Key: int64(opts.Slot), + Key: slot, Response: response, Cancel: cancel, }) diff --git a/core/dutydb/memory_internal_test.go b/core/dutydb/memory_internal_test.go index 339bae902..401216d0d 100644 --- a/core/dutydb/memory_internal_test.go +++ b/core/dutydb/memory_internal_test.go @@ -6,7 +6,6 @@ import ( "context" "testing" - eth2api "github.com/attestantio/go-eth2-client/api" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/stretchr/testify/require" @@ -28,10 +27,10 @@ func TestCancelledQueries(t *testing.T) { _, err = db.AwaitAggAttestation(ctx, slot, eth2p0.Root{}) require.ErrorContains(t, err, "shutdown") - _, err = db.AwaitProposal(ctx, ð2api.ProposalOpts{Slot: slot}) + _, err = db.AwaitProposal(ctx, slot) require.ErrorContains(t, err, "shutdown") - _, err = db.AwaitBlindedProposal(ctx, ð2api.BlindedProposalOpts{Slot: slot}) + _, err = db.AwaitBlindedProposal(ctx, slot) require.ErrorContains(t, err, "shutdown") _, err = db.AwaitSyncContribution(ctx, slot, 0, eth2p0.Root{}) diff --git a/core/dutydb/memory_test.go b/core/dutydb/memory_test.go index a069877d0..8ce6c22bb 100644 --- a/core/dutydb/memory_test.go +++ b/core/dutydb/memory_test.go @@ -24,7 +24,7 @@ func TestShutdown(t *testing.T) { errChan := make(chan error, 1) go func() { - _, err := db.AwaitProposal(context.Background(), ð2api.ProposalOpts{Slot: 999}) + _, err := db.AwaitProposal(context.Background(), 999) errChan <- err }() @@ -139,7 +139,7 @@ func TestMemDBProposer(t *testing.T) { for i := 0; i < queries; i++ { awaitResponse[i] = make(chan response) go func(slot int) { - block, err := db.AwaitProposal(ctx, ð2api.ProposalOpts{Slot: eth2p0.Slot(slots[slot])}) + block, err := db.AwaitProposal(ctx, slots[slot]) require.NoError(t, err) awaitResponse[slot] <- response{block: block} }(i) @@ -387,7 +387,7 @@ func TestMemDBBuilderProposer(t *testing.T) { for i := 0; i < queries; i++ { awaitResponse[i] = make(chan response) go func(slot int) { - block, err := db.AwaitBlindedProposal(ctx, ð2api.BlindedProposalOpts{Slot: eth2p0.Slot(slots[slot])}) + block, err := db.AwaitBlindedProposal(ctx, slots[slot]) require.NoError(t, err) awaitResponse[slot] <- response{block: block} }(i) diff --git a/core/interfaces.go b/core/interfaces.go index bcfe33104..23655233f 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -45,11 +45,11 @@ type DutyDB interface { // AwaitProposal blocks and returns the proposed beacon block // for the slot when available. - AwaitProposal(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error) + AwaitProposal(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) // AwaitBlindedProposal blocks and returns the proposed blinded beacon block // for the slot when available. - AwaitBlindedProposal(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error) + AwaitBlindedProposal(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) // AwaitAttestation blocks and returns the attestation data // for the slot and committee index when available. @@ -83,11 +83,11 @@ type Consensus interface { // ValidatorAPI provides a beacon node API to validator clients. It serves duty data from the DutyDB and stores partial signed data in the ParSigDB. type ValidatorAPI interface { - // RegisterAwaitProposal registers a function to query unsigned beacon block proposals by providing necessary options. - RegisterAwaitProposal(func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error)) + // RegisterAwaitProposal registers a function to query unsigned beacon block proposals by providing the slot. + RegisterAwaitProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error)) - // RegisterAwaitBlindedProposal registers a function to query unsigned blinded beacon block proposals by providing necessary options. - RegisterAwaitBlindedProposal(func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error)) + // RegisterAwaitBlindedProposal registers a function to query unsigned blinded beacon block proposals by providing the slot. + RegisterAwaitBlindedProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error)) // RegisterAwaitAttestation registers a function to query attestation data. RegisterAwaitAttestation(func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)) @@ -216,16 +216,16 @@ type wireFuncs struct { ConsensusPropose func(context.Context, Duty, UnsignedDataSet) error ConsensusSubscribe func(func(context.Context, Duty, UnsignedDataSet) error) DutyDBStore func(context.Context, Duty, UnsignedDataSet) error - DutyDBAwaitProposal func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error) - DutyDBAwaitBlindedProposal func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error) + DutyDBAwaitProposal func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) + DutyDBAwaitBlindedProposal func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) DutyDBAwaitAttestation func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error) DutyDBPubKeyByAttestation func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error) DutyDBAwaitAggAttestation func(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) DutyDBAwaitSyncContribution func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) VAPIRegisterAwaitAttestation func(func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)) VAPIRegisterAwaitSyncContribution func(func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) - VAPIRegisterAwaitProposal func(func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error)) - VAPIRegisterAwaitBlindedProposal func(func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error)) + VAPIRegisterAwaitProposal func(func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error)) + VAPIRegisterAwaitBlindedProposal func(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error)) VAPIRegisterGetDutyDefinition func(func(context.Context, Duty) (DutyDefinitionSet, error)) VAPIRegisterPubKeyByAttestation func(func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error)) VAPIRegisterAwaitAggAttestation func(func(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error)) diff --git a/core/validatorapi/validatorapi.go b/core/validatorapi/validatorapi.go index ba1252ab1..bd98477e3 100644 --- a/core/validatorapi/validatorapi.go +++ b/core/validatorapi/validatorapi.go @@ -154,8 +154,8 @@ type Component struct { pubKeyByAttFunc func(ctx context.Context, slot, commIdx, valCommIdx int64) (core.PubKey, error) awaitAttFunc func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error) - awaitProposalFunc func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error) - awaitBlindedProposalFunc func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error) + awaitProposalFunc func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) + awaitBlindedProposalFunc func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) awaitSyncContributionFunc func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) awaitAggAttFunc func(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) awaitAggSigDBFunc func(context.Context, core.Duty, core.PubKey) (core.SignedData, error) @@ -165,13 +165,13 @@ type Component struct { // RegisterAwaitProposal registers a function to query unsigned beacon block proposals by providing necessary options. // It supports a single function, since it is an input of the component. -func (c *Component) RegisterAwaitProposal(fn func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error)) { +func (c *Component) RegisterAwaitProposal(fn func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error)) { c.awaitProposalFunc = fn } // RegisterAwaitBlindedProposal registers a function to query unsigned blinded beacon block proposals by providing necessary options. // It supports a single function, since it is an input of the component. -func (c *Component) RegisterAwaitBlindedProposal(fn func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error)) { +func (c *Component) RegisterAwaitBlindedProposal(fn func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error)) { c.awaitBlindedProposalFunc = fn } @@ -349,7 +349,7 @@ func (c Component) Proposal(ctx context.Context, opts *eth2api.ProposalOpts) (*e // - Once inserted, the query below will return. // Query unsigned proposal (this is blocking). - proposal, err := c.awaitProposalFunc(ctx, opts) + proposal, err := c.awaitProposalFunc(ctx, int64(opts.Slot)) if err != nil { return nil, err } @@ -407,7 +407,7 @@ func (c Component) BlindedProposal(ctx context.Context, opts *eth2api.BlindedPro // - Once inserted, the query below will return. // Query unsigned block (this is blocking). - proposal, err := c.awaitBlindedProposalFunc(ctx, opts) + proposal, err := c.awaitBlindedProposalFunc(ctx, int64(opts.Slot)) if err != nil { return nil, err } diff --git a/core/validatorapi/validatorapi_test.go b/core/validatorapi/validatorapi_test.go index cbbc57945..ef7539ef7 100644 --- a/core/validatorapi/validatorapi_test.go +++ b/core/validatorapi/validatorapi_test.go @@ -377,7 +377,7 @@ func TestComponent_Proposal(t *testing.T) { return core.DutyDefinitionSet{pubkey: nil}, nil }) - component.RegisterAwaitProposal(func(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.VersionedProposal, error) { + component.RegisterAwaitProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) { return block1, nil }) @@ -700,7 +700,7 @@ func TestComponent_BlindedProposal(t *testing.T) { return core.DutyDefinitionSet{pubkey: nil}, nil }) - component.RegisterAwaitBlindedProposal(func(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.VersionedBlindedProposal, error) { + component.RegisterAwaitBlindedProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) { return block1, nil })