From 0d255ac55734f26bbddd9ea9131f7620489bffbd Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 30 Oct 2023 21:51:57 +0530 Subject: [PATCH 1/6] convert int64s to uint64s to comply with spec --- app/app.go | 10 +-- app/app_internal_test.go | 2 +- app/priorities.go | 2 +- app/qbftdebug_internal_test.go | 2 +- core/bcast/bcast.go | 6 +- core/config.go | 2 +- core/consensus/component.go | 2 +- core/consensus/msg_internal_test.go | 2 +- core/consensus/roundtimer.go | 2 +- core/consensus/strategysim_internal_test.go | 4 +- core/corepb/v1/core.pb.go | 8 +- core/corepb/v1/core.proto | 2 +- core/deadline_test.go | 2 +- core/dutydb/memory.go | 80 +++++++++---------- core/dutydb/memory_test.go | 20 ++--- core/fetcher/fetcher.go | 16 ++-- core/fetcher/fetcher_test.go | 10 +-- core/infosync/infosync.go | 8 +- core/interfaces.go | 52 ++++++------- core/scheduler/scheduler.go | 68 ++++++++-------- core/scheduler/scheduler_internal_test.go | 2 +- core/scheduler/scheduler_test.go | 13 ++-- core/tracing.go | 6 +- core/tracker/inclusion.go | 24 +++--- core/tracker/inclusion_internal_test.go | 12 +-- core/tracker/tracker.go | 4 +- core/tracker/tracker_internal_test.go | 14 ++-- core/types.go | 34 ++++---- core/validatorapi/validatorapi.go | 86 ++++++++++----------- core/validatorapi/validatorapi_test.go | 20 ++--- dkg/exchanger.go | 2 +- docs/architecture.md | 2 +- p2p/receive_test.go | 9 +-- p2p/sender_test.go | 6 -- testutil/helpers.go | 4 +- testutil/validatormock/component.go | 2 +- 36 files changed, 266 insertions(+), 274 deletions(-) diff --git a/app/app.go b/app/app.go index d02388459..31e002c2a 100644 --- a/app/app.go +++ b/app/app.go @@ -682,7 +682,7 @@ func newTracker(ctx context.Context, life *lifecycle.Manager, deadlineFunc func( // calculateTrackerDelay returns the slot to start tracking from. This mitigates noisy failed duties on // startup due to downstream VC startup delays. -func calculateTrackerDelay(ctx context.Context, cl eth2wrap.Client, now time.Time) (int64, error) { +func calculateTrackerDelay(ctx context.Context, cl eth2wrap.Client, now time.Time) (uint64, error) { const maxDelayTime = time.Second * 10 // We want to delay at most 10 seconds const minDelaySlots = 2 // But we do not want to delay less than 2 slots @@ -695,9 +695,9 @@ func calculateTrackerDelay(ctx context.Context, cl eth2wrap.Client, now time.Tim return 0, err } - currentSlot := int64(now.Sub(genesisTime) / slotDuration) + currentSlot := uint64(now.Sub(genesisTime) / slotDuration) - maxDelayTimeSlot := currentSlot + int64(maxDelayTime/slotDuration) + 1 + maxDelayTimeSlot := currentSlot + uint64(maxDelayTime/slotDuration) + 1 minDelaySlot := currentSlot + minDelaySlots if maxDelayTimeSlot < minDelaySlot { @@ -1056,7 +1056,7 @@ func hex7(input []byte) string { } // slotFromTimestamp returns slot from the provided timestamp. -func slotFromTimestamp(ctx context.Context, eth2Cl eth2wrap.Client, timestamp time.Time) (int64, error) { +func slotFromTimestamp(ctx context.Context, eth2Cl eth2wrap.Client, timestamp time.Time) (uint64, error) { genesis, err := eth2Cl.GenesisTime(ctx) if err != nil { return 0, err @@ -1071,5 +1071,5 @@ func slotFromTimestamp(ctx context.Context, eth2Cl eth2wrap.Client, timestamp ti delta := timestamp.Sub(genesis) - return int64(delta / slotDuration), nil + return uint64(delta / slotDuration), nil } diff --git a/app/app_internal_test.go b/app/app_internal_test.go index 08ea172b9..f9972bc87 100644 --- a/app/app_internal_test.go +++ b/app/app_internal_test.go @@ -16,7 +16,7 @@ import ( func TestSlotFromTimestamp(t *testing.T) { tests := []struct { name string - slot int64 + slot uint64 network string timestamp time.Time }{ diff --git a/app/priorities.go b/app/priorities.go index e8c2b64e8..274ffb440 100644 --- a/app/priorities.go +++ b/app/priorities.go @@ -41,7 +41,7 @@ func (c *mutableConfig) getInfoSync() (*infosync.Component, bool) { } // BuilderAPI returns true if the cluster supports the builder API for the provided slot. -func (c *mutableConfig) BuilderAPI(_ int64) bool { +func (c *mutableConfig) BuilderAPI(_ uint64) bool { // TODO(corver): Dynamic BuilderAPI config disabled since VCs do not support it. return c.conf.BuilderAPI } diff --git a/app/qbftdebug_internal_test.go b/app/qbftdebug_internal_test.go index 96928a846..832a8b073 100644 --- a/app/qbftdebug_internal_test.go +++ b/app/qbftdebug_internal_test.go @@ -61,7 +61,7 @@ func TestQBFTDebugger(t *testing.T) { func randomQBFTMessage() *pbv1.QBFTMsg { return &pbv1.QBFTMsg{ Type: rand.Int63(), - Duty: &pbv1.Duty{Slot: rand.Int63()}, + Duty: &pbv1.Duty{Slot: rand.Uint64()}, PeerIdx: rand.Int63(), Round: rand.Int63(), PreparedRound: rand.Int63(), diff --git a/core/bcast/bcast.go b/core/bcast/bcast.go index cee83554e..62f16d0b0 100644 --- a/core/bcast/bcast.go +++ b/core/bcast/bcast.go @@ -35,7 +35,7 @@ func New(ctx context.Context, eth2Cl eth2wrap.Client) (Broadcaster, error) { type Broadcaster struct { eth2Cl eth2wrap.Client - delayFunc func(slot int64) time.Duration + delayFunc func(slot uint64) time.Duration } // Broadcast broadcasts the aggregated signed duty data object to the beacon-node. @@ -283,7 +283,7 @@ func setToAttestations(set core.SignedDataSet) ([]*eth2p0.Attestation, error) { } // newDelayFunc returns a function that calculates the delay since the start of a slot. -func newDelayFunc(ctx context.Context, eth2Cl eth2wrap.Client) (func(slot int64) time.Duration, error) { +func newDelayFunc(ctx context.Context, eth2Cl eth2wrap.Client) (func(slot uint64) time.Duration, error) { genesis, err := eth2Cl.GenesisTime(ctx) if err != nil { return nil, err @@ -294,7 +294,7 @@ func newDelayFunc(ctx context.Context, eth2Cl eth2wrap.Client) (func(slot int64) return nil, err } - return func(slot int64) time.Duration { + return func(slot uint64) time.Duration { slotStart := genesis.Add(slotDuration * time.Duration(slot)) return time.Since(slotStart) }, nil diff --git a/core/config.go b/core/config.go index b5a144805..130cde34f 100644 --- a/core/config.go +++ b/core/config.go @@ -3,4 +3,4 @@ package core // BuilderEnabled determines whether the builderAPI is enabled for the provided slot. -type BuilderEnabled func(slot int64) bool +type BuilderEnabled func(slot uint64) bool diff --git a/core/consensus/component.go b/core/consensus/component.go index c86f583f0..fc48e9701 100644 --- a/core/consensus/component.go +++ b/core/consensus/component.go @@ -743,7 +743,7 @@ func fmtStepPeers(step roundStep) string { // leader return the deterministic leader index. func leader(duty core.Duty, round int64, nodes int) int64 { - return ((duty.Slot) + int64(duty.Type) + round) % int64(nodes) + return (int64(duty.Slot) + int64(duty.Type) + round) % int64(nodes) } func valuesByHash(values []*anypb.Any) (map[[32]byte]*anypb.Any, error) { diff --git a/core/consensus/msg_internal_test.go b/core/consensus/msg_internal_test.go index 0ab94ecb8..c6c38a01a 100644 --- a/core/consensus/msg_internal_test.go +++ b/core/consensus/msg_internal_test.go @@ -116,7 +116,7 @@ func randomMsg(t *testing.T) *pbv1.QBFTMsg { return &pbv1.QBFTMsg{ Type: msgType, - Duty: core.DutyToProto(core.Duty{Type: core.DutyType(rand.Int()), Slot: rand.Int63()}), + Duty: core.DutyToProto(core.Duty{Type: core.DutyType(rand.Int()), Slot: rand.Uint64()}), PeerIdx: rand.Int63(), Round: rand.Int63(), PreparedRound: rand.Int63(), diff --git a/core/consensus/roundtimer.go b/core/consensus/roundtimer.go index e251bb748..4e5e8e4eb 100644 --- a/core/consensus/roundtimer.go +++ b/core/consensus/roundtimer.go @@ -32,7 +32,7 @@ func getTimerFunc() timerFunc { } return func(duty core.Duty) roundTimer { - random := rand.New(rand.NewSource(int64(duty.Type) + duty.Slot)) //nolint:gosec // Required for consistent pseudo-randomness. + random := rand.New(rand.NewSource(int64(uint64(duty.Type) + duty.Slot))) //nolint:gosec // Required for consistent pseudo-randomness. return abTimers[random.Intn(len(abTimers))]() } } diff --git a/core/consensus/strategysim_internal_test.go b/core/consensus/strategysim_internal_test.go index f943c6762..8e82bb16a 100644 --- a/core/consensus/strategysim_internal_test.go +++ b/core/consensus/strategysim_internal_test.go @@ -196,7 +196,7 @@ func testRoundTimers(t *testing.T, timers []roundTimerFunc, itersPerConfig int) // fmt.Printf("undedicded config=%#v\n", config) // fmt.Printf("results=%#v\n", results) // fmt.Println(buf.String()) - //} + // } return Named[[]result]{name, results}, nil }, allConfigs, @@ -396,7 +396,7 @@ func testStrategySimulator(t *testing.T, conf ssConfig, syncer zapcore.WriteSync log.Debug(ctx, "Starting peer") - err := qbft.Run(ctx, def, transports[p.Idx], core.Duty{Slot: int64(conf.seed)}, p.Idx, valCh) + err := qbft.Run(ctx, def, transports[p.Idx], core.Duty{Slot: uint64(conf.seed)}, p.Idx, valCh) if err != nil && !errors.Is(err, context.Canceled) { return res, err } diff --git a/core/corepb/v1/core.pb.go b/core/corepb/v1/core.pb.go index 700d4baf6..a6f83a270 100644 --- a/core/corepb/v1/core.pb.go +++ b/core/corepb/v1/core.pb.go @@ -25,8 +25,8 @@ type Duty struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Slot int64 `protobuf:"varint,1,opt,name=slot,proto3" json:"slot,omitempty"` // int64 - Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // core.DutyType + Slot uint64 `protobuf:"varint,1,opt,name=slot,proto3" json:"slot,omitempty"` // int64 + Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // core.DutyType } func (x *Duty) Reset() { @@ -61,7 +61,7 @@ func (*Duty) Descriptor() ([]byte, []int) { return file_core_corepb_v1_core_proto_rawDescGZIP(), []int{0} } -func (x *Duty) GetSlot() int64 { +func (x *Duty) GetSlot() uint64 { if x != nil { return x.Slot } @@ -247,7 +247,7 @@ var file_core_corepb_v1_core_proto_rawDesc = []byte{ 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x70, 0x62, 0x2e, 0x76, 0x31, 0x22, 0x2e, 0x0a, 0x04, 0x44, 0x75, 0x74, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x6c, 0x6f, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x04, 0x73, 0x6c, 0x6f, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x04, 0x52, 0x04, 0x73, 0x6c, 0x6f, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x85, 0x01, 0x0a, 0x0f, 0x55, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x12, 0x3a, 0x0a, 0x03, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, diff --git a/core/corepb/v1/core.proto b/core/corepb/v1/core.proto index 0d82ca2d6..526faee3b 100644 --- a/core/corepb/v1/core.proto +++ b/core/corepb/v1/core.proto @@ -5,7 +5,7 @@ package core.corepb.v1; option go_package = "github.com/obolnetwork/charon/core/corepb/v1"; message Duty { // core.Duty - int64 slot = 1; // int64 + uint64 slot = 1; // int64 int32 type = 2; // core.DutyType } diff --git a/core/deadline_test.go b/core/deadline_test.go index 77ce83afe..41fa4c01b 100644 --- a/core/deadline_test.go +++ b/core/deadline_test.go @@ -50,7 +50,7 @@ func TestDeadliner(t *testing.T) { // Wait till all the duties are added to the deadliner. wg.Wait() - var maxSlot int64 + var maxSlot uint64 for _, duty := range nonExpiredDuties { if maxSlot < duty.Slot { maxSlot = duty.Slot diff --git a/core/dutydb/memory.go b/core/dutydb/memory.go index e6e1ac283..f7f78b37b 100644 --- a/core/dutydb/memory.go +++ b/core/dutydb/memory.go @@ -20,13 +20,13 @@ func NewMemDB(deadliner core.Deadliner) *MemDB { return &MemDB{ attDuties: make(map[attKey]*eth2p0.AttestationData), attPubKeys: make(map[pkKey]core.PubKey), - attKeysBySlot: make(map[int64][]pkKey), - builderProDuties: make(map[int64]*eth2api.VersionedBlindedProposal), - proDuties: make(map[int64]*eth2api.VersionedProposal), + attKeysBySlot: make(map[uint64][]pkKey), + builderProDuties: make(map[uint64]*eth2api.VersionedBlindedProposal), + proDuties: make(map[uint64]*eth2api.VersionedProposal), aggDuties: make(map[aggKey]core.AggregatedAttestation), - aggKeysBySlot: make(map[int64][]aggKey), + aggKeysBySlot: make(map[uint64][]aggKey), contribDuties: make(map[contribKey]*altair.SyncCommitteeContribution), - contribKeysBySlot: make(map[int64][]contribKey), + contribKeysBySlot: make(map[uint64][]contribKey), shutdown: make(chan struct{}), deadliner: deadliner, } @@ -40,25 +40,25 @@ type MemDB struct { // DutyAttester attDuties map[attKey]*eth2p0.AttestationData attPubKeys map[pkKey]core.PubKey - attKeysBySlot map[int64][]pkKey + attKeysBySlot map[uint64][]pkKey attQueries []attQuery // DutyBuilderProposer - builderProDuties map[int64]*eth2api.VersionedBlindedProposal + builderProDuties map[uint64]*eth2api.VersionedBlindedProposal builderProQueries []builderProQuery // DutyProposer - proDuties map[int64]*eth2api.VersionedProposal + proDuties map[uint64]*eth2api.VersionedProposal proQueries []proQuery // DutyAggregator aggDuties map[aggKey]core.AggregatedAttestation - aggKeysBySlot map[int64][]aggKey + aggKeysBySlot map[uint64][]aggKey aggQueries []aggQuery // DutySyncContribution contribDuties map[contribKey]*altair.SyncCommitteeContribution - contribKeysBySlot map[int64][]contribKey + contribKeysBySlot map[uint64][]contribKey contribQueries []contribQuery shutdown chan struct{} @@ -155,7 +155,7 @@ 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, slot int64) (*eth2api.VersionedProposal, error) { +func (db *MemDB) AwaitProposal(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *eth2api.VersionedProposal, 1) @@ -180,7 +180,7 @@ func (db *MemDB) AwaitProposal(ctx context.Context, slot int64) (*eth2api.Versio } // AwaitBlindedProposal implements core.DutyDB, see its godoc. -func (db *MemDB) AwaitBlindedProposal(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) { +func (db *MemDB) AwaitBlindedProposal(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *eth2api.VersionedBlindedProposal, 1) @@ -205,7 +205,7 @@ func (db *MemDB) AwaitBlindedProposal(ctx context.Context, slot int64) (*eth2api } // AwaitAttestation implements core.DutyDB, see its godoc. -func (db *MemDB) AwaitAttestation(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error) { +func (db *MemDB) AwaitAttestation(ctx context.Context, slot uint64, commIdx uint64) (*eth2p0.AttestationData, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *eth2p0.AttestationData, 1) // Instance of one so resolving never blocks @@ -234,7 +234,7 @@ func (db *MemDB) AwaitAttestation(ctx context.Context, slot int64, commIdx int64 // AwaitAggAttestation blocks and returns the aggregated attestation for the slot // and attestation when available. -func (db *MemDB) AwaitAggAttestation(ctx context.Context, slot int64, attestationRoot eth2p0.Root, +func (db *MemDB) AwaitAggAttestation(ctx context.Context, slot uint64, attestationRoot eth2p0.Root, ) (*eth2p0.Attestation, error) { cancel := make(chan struct{}) defer close(cancel) @@ -274,7 +274,7 @@ func (db *MemDB) AwaitAggAttestation(ctx context.Context, slot int64, attestatio // AwaitSyncContribution blocks and returns the sync committee contribution data for the slot and // the subcommittee and the beacon block root when available. -func (db *MemDB) AwaitSyncContribution(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) { +func (db *MemDB) AwaitSyncContribution(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) { cancel := make(chan struct{}) defer close(cancel) response := make(chan *altair.SyncCommitteeContribution, 1) // Instance of one so resolving never blocks @@ -303,7 +303,7 @@ func (db *MemDB) AwaitSyncContribution(ctx context.Context, slot, subcommIdx int } // PubKeyByAttestation implements core.DutyDB, see its godoc. -func (db *MemDB) PubKeyByAttestation(_ context.Context, slot, commIdx, valCommIdx int64) (core.PubKey, error) { +func (db *MemDB) PubKeyByAttestation(_ context.Context, slot, commIdx, valCommIdx uint64) (core.PubKey, error) { db.mu.Lock() defer db.mu.Unlock() @@ -335,9 +335,9 @@ func (db *MemDB) storeAttestationUnsafe(pubkey core.PubKey, unsignedData core.Un // Store key and value for PubKeyByAttestation pKey := pkKey{ - Slot: int64(attData.Data.Slot), - CommIdx: int64(attData.Data.Index), - ValCommIdx: int64(attData.Duty.ValidatorCommitteeIndex), + Slot: uint64(attData.Data.Slot), + CommIdx: uint64(attData.Data.Index), + ValCommIdx: attData.Duty.ValidatorCommitteeIndex, } if value, ok := db.attPubKeys[pKey]; ok { if value != pubkey { @@ -345,13 +345,13 @@ func (db *MemDB) storeAttestationUnsafe(pubkey core.PubKey, unsignedData core.Un } } else { db.attPubKeys[pKey] = pubkey - db.attKeysBySlot[int64(attData.Duty.Slot)] = append(db.attKeysBySlot[int64(attData.Duty.Slot)], pKey) + db.attKeysBySlot[uint64(attData.Duty.Slot)] = append(db.attKeysBySlot[uint64(attData.Duty.Slot)], pKey) } // Store key and value for AwaitAttestation aKey := attKey{ - Slot: int64(attData.Data.Slot), - CommIdx: int64(attData.Data.Index), + Slot: uint64(attData.Data.Slot), + CommIdx: uint64(attData.Data.Index), } if value, ok := db.attDuties[aKey]; ok { @@ -382,7 +382,7 @@ func (db *MemDB) storeAggAttestationUnsafe(unsignedData core.UnsignedData) error return errors.Wrap(err, "hash aggregated attestation root") } - slot := int64(aggAtt.Attestation.Data.Slot) + slot := uint64(aggAtt.Attestation.Data.Slot) // Store key and value for PubKeyByAttestation key := aggKey{ @@ -429,8 +429,8 @@ func (db *MemDB) storeSyncContributionUnsafe(unsignedData core.UnsignedData) err } key := contribKey{ - Slot: int64(contrib.Slot), - SubcommIdx: int64(contrib.SubcommitteeIndex), + Slot: uint64(contrib.Slot), + SubcommIdx: contrib.SubcommitteeIndex, Root: contrib.BeaconBlockRoot, } @@ -445,7 +445,7 @@ func (db *MemDB) storeSyncContributionUnsafe(unsignedData core.UnsignedData) err } } else { db.contribDuties[key] = &contrib.SyncCommitteeContribution - db.contribKeysBySlot[int64(contrib.Slot)] = append(db.contribKeysBySlot[int64(contrib.Slot)], key) + db.contribKeysBySlot[uint64(contrib.Slot)] = append(db.contribKeysBySlot[uint64(contrib.Slot)], key) } return nil @@ -468,7 +468,7 @@ func (db *MemDB) storeProposalUnsafe(unsignedData core.UnsignedData) error { return err } - if existing, ok := db.proDuties[int64(slot)]; ok { + if existing, ok := db.proDuties[uint64(slot)]; ok { existingRoot, err := existing.Root() if err != nil { return errors.Wrap(err, "proposal root") @@ -483,7 +483,7 @@ func (db *MemDB) storeProposalUnsafe(unsignedData core.UnsignedData) error { return errors.New("clashing blocks") } } else { - db.proDuties[int64(slot)] = &proposal.VersionedProposal + db.proDuties[uint64(slot)] = &proposal.VersionedProposal } return nil @@ -506,7 +506,7 @@ func (db *MemDB) storeBlindedBeaconBlockUnsafe(unsignedData core.UnsignedData) e return err } - if existing, ok := db.builderProDuties[int64(slot)]; ok { + if existing, ok := db.builderProDuties[uint64(slot)]; ok { existingRoot, err := existing.Root() if err != nil { return errors.Wrap(err, "blinded block root") @@ -521,7 +521,7 @@ func (db *MemDB) storeBlindedBeaconBlockUnsafe(unsignedData core.UnsignedData) e return errors.New("clashing blinded blocks") } } else { - db.builderProDuties[int64(slot)] = &block.VersionedBlindedProposal + db.builderProDuties[uint64(slot)] = &block.VersionedBlindedProposal } return nil @@ -664,27 +664,27 @@ func (db *MemDB) deleteDutyUnsafe(duty core.Duty) error { // attKey is the key to lookup an attester value in the DB. type attKey struct { - Slot int64 - CommIdx int64 + Slot uint64 + CommIdx uint64 } // pkKey is the key to lookup pubkeys by attestation in the DB. type pkKey struct { - Slot int64 - CommIdx int64 - ValCommIdx int64 + Slot uint64 + CommIdx uint64 + ValCommIdx uint64 } // aggKey is the key to lookup an aggregated attestation by root in the DB. type aggKey struct { - Slot int64 + Slot uint64 Root eth2p0.Root } // contribKey is the key to look up sync contribution by root and subcommittee index in the DB. type contribKey struct { - Slot int64 - SubcommIdx int64 + Slot uint64 + SubcommIdx uint64 Root eth2p0.Root } @@ -697,7 +697,7 @@ type attQuery struct { // proQuery is a waiting proQuery with a response channel. type proQuery struct { - Key int64 + Key uint64 Response chan<- *eth2api.VersionedProposal Cancel <-chan struct{} } @@ -711,7 +711,7 @@ type aggQuery struct { // builderProQuery is a waiting builderProQuery with a response channel. type builderProQuery struct { - Key int64 + Key uint64 Response chan<- *eth2api.VersionedBlindedProposal Cancel <-chan struct{} } diff --git a/core/dutydb/memory_test.go b/core/dutydb/memory_test.go index 8ce6c22bb..7274afd4c 100644 --- a/core/dutydb/memory_test.go +++ b/core/dutydb/memory_test.go @@ -116,11 +116,11 @@ func TestMemDB(t *testing.T) { } // Assert that two pubkeys can be resolved. - pkA, err := db.PubKeyByAttestation(ctx, int64(attData.Slot), int64(attData.Index), valCommIdxA) + pkA, err := db.PubKeyByAttestation(ctx, uint64(attData.Slot), uint64(attData.Index), valCommIdxA) require.NoError(t, err) require.Equal(t, pubkeysByIdx[vIdxA], pkA) - pkB, err := db.PubKeyByAttestation(ctx, int64(attData.Slot), int64(attData.Index), valCommIdxB) + pkB, err := db.PubKeyByAttestation(ctx, uint64(attData.Slot), uint64(attData.Index), valCommIdxB) require.NoError(t, err) require.Equal(t, pubkeysByIdx[vIdxB], pkB) } @@ -130,7 +130,7 @@ func TestMemDBProposer(t *testing.T) { db := dutydb.NewMemDB(new(testDeadliner)) const queries = 3 - slots := [queries]int64{123, 456, 789} + slots := [queries]uint64{123, 456, 789} type response struct { block *eth2api.VersionedProposal @@ -187,7 +187,7 @@ func TestMemDBAggregator(t *testing.T) { set := core.UnsignedDataSet{ testutil.RandomCorePubKey(t): core.NewAggregatedAttestation(agg), } - slot := int64(agg.Data.Slot) + slot := uint64(agg.Data.Slot) go func() { err := db.Store(ctx, core.NewAggregatorDuty(slot), set) require.NoError(t, err) @@ -215,7 +215,7 @@ func TestMemDBSyncContribution(t *testing.T) { } var ( - slot = int64(contrib.Slot) + slot = uint64(contrib.Slot) subcommIdx = contrib.SubcommitteeIndex beaconBlockRoot = contrib.BeaconBlockRoot ) @@ -225,7 +225,7 @@ func TestMemDBSyncContribution(t *testing.T) { require.NoError(t, err) }() - resp, err := db.AwaitSyncContribution(ctx, slot, int64(subcommIdx), beaconBlockRoot) + resp, err := db.AwaitSyncContribution(ctx, slot, subcommIdx, beaconBlockRoot) require.NoError(t, err) require.Equal(t, contrib, resp) } @@ -378,7 +378,7 @@ func TestMemDBBuilderProposer(t *testing.T) { db := dutydb.NewMemDB(new(testDeadliner)) const queries = 3 - slots := [queries]int64{123, 456, 789} + slots := [queries]uint64{123, 456, 789} type response struct { block *eth2api.VersionedBlindedProposal @@ -507,7 +507,7 @@ func TestDutyExpiry(t *testing.T) { db := dutydb.NewMemDB(deadliner) // Add attestation data - const slot = int64(123) + const slot = uint64(123) att1 := testutil.RandomCoreAttestationData(t) att1.Duty.Slot = eth2p0.Slot(slot) err := db.Store(ctx, core.NewAttesterDuty(slot), core.UnsignedDataSet{ @@ -516,7 +516,7 @@ func TestDutyExpiry(t *testing.T) { require.NoError(t, err) // Ensure it exists - pk, err := db.PubKeyByAttestation(ctx, int64(att1.Data.Slot), int64(att1.Data.Index), int64(att1.Duty.ValidatorCommitteeIndex)) + pk, err := db.PubKeyByAttestation(ctx, uint64(att1.Data.Slot), uint64(att1.Data.Index), att1.Duty.ValidatorCommitteeIndex) require.NoError(t, err) require.NotEmpty(t, pk) @@ -532,7 +532,7 @@ func TestDutyExpiry(t *testing.T) { require.NoError(t, err) // Pubkey not found. - _, err = db.PubKeyByAttestation(ctx, int64(att1.Data.Slot), int64(att1.Data.Index), int64(att1.Duty.ValidatorCommitteeIndex)) + _, err = db.PubKeyByAttestation(ctx, uint64(att1.Data.Slot), uint64(att1.Data.Index), att1.Duty.ValidatorCommitteeIndex) require.Error(t, err) } diff --git a/core/fetcher/fetcher.go b/core/fetcher/fetcher.go index 7c1fe264c..3fbd575bc 100644 --- a/core/fetcher/fetcher.go +++ b/core/fetcher/fetcher.go @@ -34,7 +34,7 @@ type Fetcher struct { feeRecipientFunc func(core.PubKey) string subs []func(context.Context, core.Duty, core.UnsignedDataSet) error aggSigDBFunc func(context.Context, core.Duty, core.PubKey) (core.SignedData, error) - awaitAttDataFunc func(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error) + awaitAttDataFunc func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error) } // Subscribe registers a callback for fetched duties. @@ -106,12 +106,12 @@ func (f *Fetcher) RegisterAggSigDB(fn func(context.Context, core.Duty, core.PubK // RegisterAwaitAttData registers a function to get attestation data from DutyDB. // Note: This is not thread safe and should only be called *before* Fetch. -func (f *Fetcher) RegisterAwaitAttData(fn func(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error)) { +func (f *Fetcher) RegisterAwaitAttData(fn func(ctx context.Context, slot uint64, commIdx uint64) (*eth2p0.AttestationData, error)) { f.awaitAttDataFunc = fn } // fetchAttesterData returns the fetched attestation data set for committees and validators in the arg set. -func (f *Fetcher) fetchAttesterData(ctx context.Context, slot int64, defSet core.DutyDefinitionSet, +func (f *Fetcher) fetchAttesterData(ctx context.Context, slot uint64, defSet core.DutyDefinitionSet, ) (core.UnsignedDataSet, error) { // We may have multiple validators in the same committee, use the same attestation data in that case. dataByCommIdx := make(map[eth2p0.CommitteeIndex]*eth2p0.AttestationData) @@ -155,7 +155,7 @@ func (f *Fetcher) fetchAttesterData(ctx context.Context, slot int64, defSet core } // fetchAggregatorData fetches the attestation aggregation data. -func (f *Fetcher) fetchAggregatorData(ctx context.Context, slot int64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { +func (f *Fetcher) fetchAggregatorData(ctx context.Context, slot uint64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { // We may have multiple aggregators in the same committee, use the same aggregated attestation in that case. aggAttByCommIdx := make(map[eth2p0.CommitteeIndex]*eth2p0.Attestation) @@ -197,7 +197,7 @@ func (f *Fetcher) fetchAggregatorData(ctx context.Context, slot int64, defSet co } // Query DutyDB for Attestation data to get attestation data root. - attData, err := f.awaitAttDataFunc(ctx, slot, int64(attDef.CommitteeIndex)) + attData, err := f.awaitAttDataFunc(ctx, slot, uint64(attDef.CommitteeIndex)) if err != nil { return core.UnsignedDataSet{}, err } @@ -234,7 +234,7 @@ func (f *Fetcher) fetchAggregatorData(ctx context.Context, slot int64, defSet co return resp, nil } -func (f *Fetcher) fetchProposerData(ctx context.Context, slot int64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { +func (f *Fetcher) fetchProposerData(ctx context.Context, slot uint64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { resp := make(core.UnsignedDataSet) for pubkey := range defSet { // Fetch previously aggregated randao reveal from AggSigDB @@ -276,7 +276,7 @@ func (f *Fetcher) fetchProposerData(ctx context.Context, slot int64, defSet core return resp, nil } -func (f *Fetcher) fetchBuilderProposerData(ctx context.Context, slot int64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { +func (f *Fetcher) fetchBuilderProposerData(ctx context.Context, slot uint64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { resp := make(core.UnsignedDataSet) for pubkey := range defSet { // Fetch previously aggregated randao reveal from AggSigDB @@ -321,7 +321,7 @@ func (f *Fetcher) fetchBuilderProposerData(ctx context.Context, slot int64, defS } // fetchContributionData fetches the sync committee contribution data. -func (f *Fetcher) fetchContributionData(ctx context.Context, slot int64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { +func (f *Fetcher) fetchContributionData(ctx context.Context, slot uint64, defSet core.DutyDefinitionSet) (core.UnsignedDataSet, error) { resp := make(core.UnsignedDataSet) for pubkey := range defSet { // Query AggSigDB for DutyPrepareSyncContribution to get sync committee selection. diff --git a/core/fetcher/fetcher_test.go b/core/fetcher/fetcher_test.go index 4a07edffc..9e1c689e2 100644 --- a/core/fetcher/fetcher_test.go +++ b/core/fetcher/fetcher_test.go @@ -108,9 +108,9 @@ func TestFetchAggregator(t *testing.T) { attA := testutil.RandomAttestation() attB := testutil.RandomAttestation() - attByCommIdx := map[int64]*eth2p0.Attestation{ - int64(attA.Data.Index): attA, - int64(attB.Data.Index): attB, + attByCommIdx := map[uint64]*eth2p0.Attestation{ + uint64(attA.Data.Index): attA, + uint64(attB.Data.Index): attB, } newDefSet := func(commLength uint64, sameCommitteeIndex bool) core.DutyDefinitionSet { @@ -166,7 +166,7 @@ func TestFetchAggregator(t *testing.T) { return signedCommSubByPubKey[key], nil }) - fetch.RegisterAwaitAttData(func(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error) { + fetch.RegisterAwaitAttData(func(ctx context.Context, slot uint64, commIdx uint64) (*eth2p0.AttestationData, error) { return attByCommIdx[commIdx].Data, nil }) @@ -179,7 +179,7 @@ func TestFetchAggregator(t *testing.T) { aggregated, ok := aggAtt.(core.AggregatedAttestation) require.True(t, ok) - att, ok := attByCommIdx[int64(aggregated.Attestation.Data.Index)] + att, ok := attByCommIdx[uint64(aggregated.Attestation.Data.Index)] require.True(t, ok) require.Equal(t, aggregated.Attestation, *att) } diff --git a/core/infosync/infosync.go b/core/infosync/infosync.go index 5f087c074..e2aba4074 100644 --- a/core/infosync/infosync.go +++ b/core/infosync/infosync.go @@ -86,7 +86,7 @@ type Component struct { // Protocols returns the latest cluster wide supported protocols before the slot. // It returns the local protocols if no results before the slot are available. -func (c *Component) Protocols(slot int64) []protocol.ID { +func (c *Component) Protocols(slot uint64) []protocol.ID { c.mu.Lock() defer c.mu.Unlock() @@ -105,7 +105,7 @@ func (c *Component) Protocols(slot int64) []protocol.ID { // Proposals returns the latest cluster wide supported proposal types before the slot. // It returns the default "full" proposal type if no results before the slot are available. -func (c *Component) Proposals(slot int64) []core.ProposalType { +func (c *Component) Proposals(slot uint64) []core.ProposalType { c.mu.Lock() defer c.mu.Unlock() @@ -140,7 +140,7 @@ func (c *Component) addResult(result result) { } } -func (c *Component) Trigger(ctx context.Context, slot int64) error { +func (c *Component) Trigger(ctx context.Context, slot uint64) error { return c.prioritiser.Prioritise(ctx, core.NewInfoSyncDuty(slot), priority.TopicProposal{ Topic: topicVersion, @@ -188,7 +188,7 @@ func proposalsToStrings(proposals []core.ProposalType) []string { // result is a cluster-wide agreed-upon infosync result. type result struct { - slot int64 + slot uint64 versions []string protocols []protocol.ID proposals []core.ProposalType diff --git a/core/interfaces.go b/core/interfaces.go index 23655233f..fd551b036 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -35,7 +35,7 @@ type Fetcher interface { RegisterAggSigDB(func(context.Context, Duty, PubKey) (SignedData, error)) // RegisterAwaitAttData registers a function to get attestation data from DutyDB. - RegisterAwaitAttData(func(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error)) + RegisterAwaitAttData(func(ctx context.Context, slot uint64, commIdx uint64) (*eth2p0.AttestationData, error)) } // DutyDB persists unsigned duty data sets and makes it available for querying. It also acts as slashing database. @@ -45,28 +45,28 @@ type DutyDB interface { // AwaitProposal blocks and returns the proposed beacon block // for the slot when available. - AwaitProposal(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) + AwaitProposal(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error) // AwaitBlindedProposal blocks and returns the proposed blinded beacon block // for the slot when available. - AwaitBlindedProposal(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) + AwaitBlindedProposal(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error) // AwaitAttestation blocks and returns the attestation data // for the slot and committee index when available. - AwaitAttestation(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error) + AwaitAttestation(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error) // PubKeyByAttestation returns the validator PubKey for the provided attestation data // slot, committee index and validator committee index. This allows mapping of attestation // data response to validator. - PubKeyByAttestation(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error) + PubKeyByAttestation(ctx context.Context, slot, commIdx, valCommIdx uint64) (PubKey, error) // AwaitAggAttestation blocks and returns the aggregated attestation for the slot // and attestation when available. - AwaitAggAttestation(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) + AwaitAggAttestation(ctx context.Context, slot uint64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) // AwaitSyncContribution blocks and returns the sync committee contribution data for the slot and // the subcommittee and the beacon block root when available. - AwaitSyncContribution(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) + AwaitSyncContribution(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) } // Consensus comes to consensus on proposed duty data. @@ -84,25 +84,25 @@ 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 the slot. - RegisterAwaitProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error)) + RegisterAwaitProposal(func(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, 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)) + RegisterAwaitBlindedProposal(func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error)) // RegisterAwaitAttestation registers a function to query attestation data. - RegisterAwaitAttestation(func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)) + RegisterAwaitAttestation(func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error)) // RegisterAwaitSyncContribution registers a function to query sync contribution data. - RegisterAwaitSyncContribution(func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) + RegisterAwaitSyncContribution(func(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) // RegisterPubKeyByAttestation registers a function to query validator by attestation. - RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error)) + RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx uint64) (PubKey, error)) // RegisterGetDutyDefinition registers a function to query duty definitions. RegisterGetDutyDefinition(func(context.Context, Duty) (DutyDefinitionSet, error)) // RegisterAwaitAggAttestation registers a function to query aggregated attestation. - RegisterAwaitAggAttestation(fn func(ctx context.Context, slot int64, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error)) + RegisterAwaitAggAttestation(fn func(ctx context.Context, slot uint64, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error)) // RegisterAwaitAggSigDB registers a function to query aggregated signed data from aggSigDB. RegisterAwaitAggSigDB(func(context.Context, Duty, PubKey) (SignedData, error)) @@ -211,24 +211,24 @@ type wireFuncs struct { FetcherFetch func(context.Context, Duty, DutyDefinitionSet) error FetcherSubscribe func(func(context.Context, Duty, UnsignedDataSet) error) FetcherRegisterAggSigDB func(func(context.Context, Duty, PubKey) (SignedData, error)) - FetcherRegisterAwaitAttData func(func(ctx context.Context, slot int64, commIdx int64) (*eth2p0.AttestationData, error)) + FetcherRegisterAwaitAttData func(func(ctx context.Context, slot uint64, commIdx uint64) (*eth2p0.AttestationData, error)) ConsensusParticipate func(context.Context, Duty) error 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, 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, slot int64) (*eth2api.VersionedProposal, error)) - VAPIRegisterAwaitBlindedProposal func(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error)) + DutyDBAwaitProposal func(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error) + DutyDBAwaitBlindedProposal func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error) + DutyDBAwaitAttestation func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error) + DutyDBPubKeyByAttestation func(ctx context.Context, slot, commIdx, valCommIdx uint64) (PubKey, error) + DutyDBAwaitAggAttestation func(ctx context.Context, slot uint64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) + DutyDBAwaitSyncContribution func(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) + VAPIRegisterAwaitAttestation func(func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error)) + VAPIRegisterAwaitSyncContribution func(func(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) + VAPIRegisterAwaitProposal func(func(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error)) + VAPIRegisterAwaitBlindedProposal func(func(ctx context.Context, slot uint64) (*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)) + VAPIRegisterPubKeyByAttestation func(func(ctx context.Context, slot, commIdx, valCommIdx uint64) (PubKey, error)) + VAPIRegisterAwaitAggAttestation func(func(ctx context.Context, slot uint64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error)) VAPIRegisterAwaitAggSigDB func(func(context.Context, Duty, PubKey) (SignedData, error)) VAPISubscribe func(func(context.Context, Duty, ParSignedDataSet) error) ParSigDBStoreInternal func(context.Context, Duty, ParSignedDataSet) error diff --git a/core/scheduler/scheduler.go b/core/scheduler/scheduler.go index 581860422..d3fb4664f 100644 --- a/core/scheduler/scheduler.go +++ b/core/scheduler/scheduler.go @@ -33,7 +33,7 @@ func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, pubkeys [ ) *Scheduler { t.Helper() - s, err := New(pubkeys, eth2Cl, func(int64) bool { return builderAPI }) + s, err := New(pubkeys, eth2Cl, func(uint64) bool { return builderAPI }) require.NoError(t, err) s.clock = clock @@ -49,7 +49,7 @@ func New(pubkeys []core.PubKey, eth2Cl eth2wrap.Client, builderEnabled core.Buil pubkeys: pubkeys, quit: make(chan struct{}), duties: make(map[core.Duty]core.DutyDefinitionSet), - dutiesByEpoch: make(map[int64][]core.Duty), + dutiesByEpoch: make(map[uint64][]core.Duty), clock: clockwork.NewRealClock(), delayFunc: func(_ core.Duty, deadline time.Time) <-chan time.Time { return time.After(time.Until(deadline)) @@ -67,9 +67,9 @@ type Scheduler struct { clock clockwork.Clock delayFunc delayFunc metricSubmitter metricSubmitter - resolvedEpoch int64 + resolvedEpoch uint64 duties map[core.Duty]core.DutyDefinitionSet - dutiesByEpoch map[int64][]core.Duty + dutiesByEpoch map[uint64][]core.Duty dutiesMutex sync.Mutex dutySubs []func(context.Context, core.Duty, core.DutyDefinitionSet) error slotSubs []func(context.Context, core.Slot) error @@ -112,7 +112,7 @@ func (s *Scheduler) Run() error { case <-s.quit: return nil case slot := <-slotTicker: - log.Debug(ctx, "Slot ticked", z.I64("slot", slot.Slot)) // Not adding slot to context since duty will be added that also contains slot. + log.Debug(ctx, "Slot ticked", z.U64("slot", slot.Slot)) // Not adding slot to context since duty will be added that also contains slot. instrumentSlot(slot) @@ -132,7 +132,7 @@ func (s *Scheduler) emitCoreSlot(ctx context.Context, slot core.Slot) { go func(sub func(context.Context, core.Slot) error) { err := sub(ctx, slot) if err != nil { - log.Error(ctx, "Emit scheduled slot event", err, z.I64("slot", slot.Slot)) + log.Error(ctx, "Emit scheduled slot event", err, z.U64("slot", slot.Slot)) } }(sub) } @@ -152,20 +152,20 @@ func (s *Scheduler) GetDutyDefinition(ctx context.Context, duty core.Duty) (core return nil, err } - epoch := duty.Slot / int64(slotsPerEpoch) + epoch := duty.Slot / slotsPerEpoch if !s.isEpochResolved(epoch) { return nil, errors.New("epoch not resolved yet", - z.Str("duty", duty.String()), z.I64("epoch", epoch)) + z.Str("duty", duty.String()), z.U64("epoch", epoch)) } if s.isEpochTrimmed(epoch) { return nil, errors.New("epoch already trimmed", - z.Str("duty", duty.String()), z.I64("epoch", epoch)) + z.Str("duty", duty.String()), z.U64("epoch", epoch)) } defSet, ok := s.getDutyDefinitionSet(duty) if !ok { return nil, errors.Wrap(core.ErrNotFound, "duty not present for resolved epoch", - z.Any("duty", duty), z.I64("epoch", epoch)) + z.Any("duty", duty), z.U64("epoch", epoch)) } return defSet.Clone() // Clone before returning. @@ -176,7 +176,7 @@ func (s *Scheduler) scheduleSlot(ctx context.Context, slot core.Slot) { if s.getResolvedEpoch() != slot.Epoch() { err := s.resolveDuties(ctx, slot) if err != nil { - log.Warn(ctx, "Resolving duties error (retrying next slot)", err, z.I64("slot", slot.Slot)) + log.Warn(ctx, "Resolving duties error (retrying next slot)", err, z.U64("slot", slot.Slot)) } } @@ -211,7 +211,7 @@ func (s *Scheduler) scheduleSlot(ctx context.Context, slot core.Slot) { } if err := sub(dutyCtx, duty, clone); err != nil { - log.Error(dutyCtx, "Trigger duty subscriber error", err, z.I64("slot", slot.Slot)) + log.Error(dutyCtx, "Trigger duty subscriber error", err, z.U64("slot", slot.Slot)) } } }() @@ -220,7 +220,7 @@ func (s *Scheduler) scheduleSlot(ctx context.Context, slot core.Slot) { if slot.LastInEpoch() { err := s.resolveDuties(ctx, slot.Next()) if err != nil { - log.Warn(ctx, "Resolving duties error (retrying next slot)", err, z.I64("slot", slot.Slot)) + log.Warn(ctx, "Resolving duties error (retrying next slot)", err, z.U64("slot", slot.Slot)) } } } @@ -255,7 +255,7 @@ func (s *Scheduler) resolveDuties(ctx context.Context, slot core.Slot) error { activeValsGauge.Set(float64(len(vals))) if len(vals) == 0 { - log.Info(ctx, "No active validators for slot", z.I64("slot", slot.Slot)) + log.Info(ctx, "No active validators for slot", z.U64("slot", slot.Slot)) s.setResolvedEpoch(slot.Epoch()) return nil @@ -319,11 +319,11 @@ func (s *Scheduler) resolveAttDuties(ctx context.Context, slot core.Slot, vals v continue } - duty := core.NewAttesterDuty(int64(attDuty.Slot)) + duty := core.NewAttesterDuty(uint64(attDuty.Slot)) pubkey, ok := vals.PubKeyFromIndex(attDuty.ValidatorIndex) if !ok { - log.Warn(ctx, "Ignoring unexpected attester duty", nil, z.U64("vidx", uint64(attDuty.ValidatorIndex)), z.I64("slot", slot.Slot)) + log.Warn(ctx, "Ignoring unexpected attester duty", nil, z.U64("vidx", uint64(attDuty.ValidatorIndex)), z.U64("slot", slot.Slot)) continue } @@ -343,7 +343,7 @@ func (s *Scheduler) resolveAttDuties(ctx context.Context, slot core.Slot, vals v ) // Schedule aggregation duty as well. - aggDuty := core.NewAggregatorDuty(int64(attDuty.Slot)) + aggDuty := core.NewAggregatorDuty(uint64(attDuty.Slot)) if !s.setDutyDefinition(aggDuty, slot.Epoch(), pubkey, core.NewAttesterDefinition(attDuty)) { continue @@ -352,8 +352,8 @@ func (s *Scheduler) resolveAttDuties(ctx context.Context, slot core.Slot, vals v if len(remaining) > 0 { log.Warn(ctx, "Missing attester duties", nil, - z.I64("slot", slot.Slot), - z.U64("epoch", uint64(slot.Epoch())), + z.U64("slot", slot.Slot), + z.U64("epoch", slot.Epoch()), z.Any("validator_indexes", remaining), ) } @@ -388,15 +388,15 @@ func (s *Scheduler) resolveProDuties(ctx context.Context, slot core.Slot, vals v var duty core.Duty - if s.builderEnabled(int64(proDuty.Slot)) { - duty = core.Duty{Slot: int64(proDuty.Slot), Type: core.DutyBuilderProposer} + if s.builderEnabled(uint64(proDuty.Slot)) { + duty = core.Duty{Slot: uint64(proDuty.Slot), Type: core.DutyBuilderProposer} } else { - duty = core.Duty{Slot: int64(proDuty.Slot), Type: core.DutyProposer} + duty = core.Duty{Slot: uint64(proDuty.Slot), Type: core.DutyProposer} } pubkey, ok := vals.PubKeyFromIndex(proDuty.ValidatorIndex) if !ok { - log.Warn(ctx, "Ignoring unexpected proposer duty", nil, z.U64("vidx", uint64(proDuty.ValidatorIndex)), z.I64("slot", slot.Slot)) + log.Warn(ctx, "Ignoring unexpected proposer duty", nil, z.U64("vidx", uint64(proDuty.ValidatorIndex)), z.U64("slot", slot.Slot)) continue } @@ -442,7 +442,7 @@ func (s *Scheduler) resolveSyncCommDuties(ctx context.Context, slot core.Slot, v vIdx := syncCommDuty.ValidatorIndex pubkey, ok := vals.PubKeyFromIndex(vIdx) if !ok { - log.Warn(ctx, "Ignoring unexpected sync committee duty", nil, z.U64("vidx", uint64(vIdx)), z.I64("slot", slot.Slot)) + log.Warn(ctx, "Ignoring unexpected sync committee duty", nil, z.U64("vidx", uint64(vIdx)), z.U64("slot", slot.Slot)) continue } @@ -484,7 +484,7 @@ func (s *Scheduler) getDutyDefinitionSet(duty core.Duty) (core.DutyDefinitionSet } // setDutyDefinition returns true if the duty definition for the pubkey was set, false if it was already set. -func (s *Scheduler) setDutyDefinition(duty core.Duty, epoch int64, pubkey core.PubKey, set core.DutyDefinition) bool { +func (s *Scheduler) setDutyDefinition(duty core.Duty, epoch uint64, pubkey core.PubKey, set core.DutyDefinition) bool { s.dutiesMutex.Lock() defer s.dutiesMutex.Unlock() @@ -503,22 +503,22 @@ func (s *Scheduler) setDutyDefinition(duty core.Duty, epoch int64, pubkey core.P return true } -func (s *Scheduler) getResolvedEpoch() int64 { +func (s *Scheduler) getResolvedEpoch() uint64 { s.dutiesMutex.Lock() defer s.dutiesMutex.Unlock() return s.resolvedEpoch } -func (s *Scheduler) setResolvedEpoch(epoch int64) { +func (s *Scheduler) setResolvedEpoch(epoch uint64) { s.dutiesMutex.Lock() defer s.dutiesMutex.Unlock() s.resolvedEpoch = epoch } -// isEpochResolved returns true if the. -func (s *Scheduler) isEpochResolved(epoch int64) bool { +// isEpochResolved returns true if the epoch is resolved. +func (s *Scheduler) isEpochResolved(epoch uint64) bool { if s.getResolvedEpoch() == math.MaxInt64 { return false } @@ -527,7 +527,7 @@ func (s *Scheduler) isEpochResolved(epoch int64) bool { } // isEpochTrimmed returns true if the epoch's duties have been trimmed. -func (s *Scheduler) isEpochTrimmed(epoch int64) bool { +func (s *Scheduler) isEpochTrimmed(epoch uint64) bool { if s.getResolvedEpoch() == math.MaxInt64 { return false } @@ -536,7 +536,7 @@ func (s *Scheduler) isEpochTrimmed(epoch int64) bool { } // trimDuties deletes all duties for the provided epoch. -func (s *Scheduler) trimDuties(epoch int64) { +func (s *Scheduler) trimDuties(epoch uint64) { s.dutiesMutex.Lock() defer s.dutiesMutex.Unlock() @@ -576,9 +576,9 @@ func newSlotTicker(ctx context.Context, eth2Cl eth2wrap.Client, clock clockwork. startTime := genesis.Add(time.Duration(slot) * slotDuration) return core.Slot{ - Slot: slot, + Slot: uint64(slot), Time: startTime, - SlotsPerEpoch: int64(slotsPerEpoch), + SlotsPerEpoch: slotsPerEpoch, SlotDuration: slotDuration, } } @@ -597,7 +597,7 @@ func newSlotTicker(ctx context.Context, eth2Cl eth2wrap.Client, clock clockwork. // to pause-the-world events (i.e. resources are already constrained). if clock.Now().After(slot.Next().Time) { actual := currentSlot() - log.Warn(ctx, "Slot(s) skipped", nil, z.I64("actual_slot", actual.Slot), z.I64("expect_slot", slot.Slot)) + log.Warn(ctx, "Slot(s) skipped", nil, z.U64("actual_slot", actual.Slot), z.U64("expect_slot", slot.Slot)) skipCounter.Inc() slot = actual diff --git a/core/scheduler/scheduler_internal_test.go b/core/scheduler/scheduler_internal_test.go index dfced1a18..5a4db109c 100644 --- a/core/scheduler/scheduler_internal_test.go +++ b/core/scheduler/scheduler_internal_test.go @@ -95,7 +95,7 @@ func setupScheduler(t *testing.T) (*Scheduler, validators) { sched := &Scheduler{ eth2Cl: eth2Cl, - builderEnabled: func(_ int64) bool { + builderEnabled: func(_ uint64) bool { return false }, } diff --git a/core/scheduler/scheduler_test.go b/core/scheduler/scheduler_test.go index 6294743ef..411acd375 100644 --- a/core/scheduler/scheduler_test.go +++ b/core/scheduler/scheduler_test.go @@ -52,7 +52,7 @@ func TestIntegration(t *testing.T) { "0xb790b322e1cce41c48e3c344cf8d752bdc3cfd51e8eeef44a4bdaac081bc92b53b73e823a9878b5d7a532eb9d9dce1e3", } - builderDisabled := func(int64) bool { return false } + builderDisabled := func(uint64) bool { return false } s, err := scheduler.New(pubkeys, eth2Cl, builderDisabled) require.NoError(t, err) @@ -140,7 +140,8 @@ func TestSchedulerWait(t *testing.T) { }, err } - sched := scheduler.NewForT(t, clock, new(delayer).delay, nil, eth2Cl, false) + dd := new(delayer) + sched := scheduler.NewForT(t, clock, dd.delay, nil, eth2Cl, false) sched.Stop() // Just run wait functions, then quit. require.NoError(t, sched.Run()) require.EqualValues(t, test.WaitSecs, clock.Since(t0).Seconds()) @@ -285,7 +286,7 @@ func TestScheduler_GetDuty(t *testing.T) { var ( ctx = context.Background() t0 time.Time - slot = int64(1) + slot = uint64(1) valSet = beaconmock.ValidatorSetA ) @@ -305,7 +306,8 @@ func TestScheduler_GetDuty(t *testing.T) { // Construct scheduler. clock := newTestClock(t0) - sched := scheduler.NewForT(t, clock, new(delayer).delay, pubkeys, eth2Cl, false) + dd := new(delayer) + sched := scheduler.NewForT(t, clock, dd.delay, pubkeys, eth2Cl, false) _, err = sched.GetDutyDefinition(ctx, core.NewAttesterDuty(slot)) require.ErrorContains(t, err, "epoch not resolved yet") @@ -388,7 +390,8 @@ func TestNoActive(t *testing.T) { // Construct scheduler. clock := newTestClock(t0) - sched := scheduler.NewForT(t, clock, new(delayer).delay, nil, eth2Cl, false) + dd := new(delayer) + sched := scheduler.NewForT(t, clock, dd.delay, nil, eth2Cl, false) clock.CallbackAfter(t0.Add(slotDuration*2), func() { _, err := sched.GetDutyDefinition(ctx, core.NewAttesterDuty(1)) diff --git a/core/tracing.go b/core/tracing.go index 7422922d3..fa7c34346 100644 --- a/core/tracing.go +++ b/core/tracing.go @@ -29,7 +29,7 @@ func StartDutyTrace(ctx context.Context, duty Duty, spanName string, opts ...tra ctx, outerSpan = tracer.Start(tracer.RootedCtx(ctx, traceID), fmt.Sprintf("core/duty.%s", strings.Title(duty.Type.String()))) ctx, innerSpan = tracer.Start(ctx, spanName, opts...) - outerSpan.SetAttributes(attribute.Int64("slot", duty.Slot)) + outerSpan.SetAttributes(attribute.Int64("slot", int64(duty.Slot))) return ctx, withEndSpan{ Span: innerSpan, @@ -77,13 +77,13 @@ func WithTracing() WireOption { return clone.DutyDBStore(ctx, duty, set) } - w.DutyDBAwaitAttestation = func(parent context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error) { + w.DutyDBAwaitAttestation = func(parent context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error) { ctx, span := tracer.Start(parent, "core/dutydb.AwaitAttestation") defer span.End() return clone.DutyDBAwaitAttestation(ctx, slot, commIdx) } - w.DutyDBPubKeyByAttestation = func(parent context.Context, slot, commIdx, valCommIdx int64) (PubKey, error) { + w.DutyDBPubKeyByAttestation = func(parent context.Context, slot, commIdx, valCommIdx uint64) (PubKey, error) { ctx, span := tracer.Start(parent, "core/dutydb.PubKeyByAttestation") defer span.End() diff --git a/core/tracker/inclusion.go b/core/tracker/inclusion.go index 188730388..868950811 100644 --- a/core/tracker/inclusion.go +++ b/core/tracker/inclusion.go @@ -47,7 +47,7 @@ type submission struct { // block is a simplified block with its attestations. type block struct { - Slot int64 + Slot uint64 AttestationsByDataRoot map[eth2p0.Root]*eth2p0.Attestation } @@ -144,7 +144,7 @@ func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core. // Trim removes all duties that are older than the specified slot. // It also calls the missedFunc for any duties that have not been included. -func (i *inclusionCore) Trim(ctx context.Context, slot int64) { +func (i *inclusionCore) Trim(ctx context.Context, slot uint64) { i.mu.Lock() defer i.mu.Unlock() @@ -268,7 +268,7 @@ func reportMissed(ctx context.Context, sub submission) { log.Warn(ctx, msg, nil, z.Any("pubkey", sub.Pubkey), - z.I64("attestation_slot", sub.Duty.Slot), + z.U64("attestation_slot", sub.Duty.Slot), z.Any("broadcast_delay", sub.Delay), ) case core.DutyProposer, core.DutyBuilderProposer: @@ -279,7 +279,7 @@ func reportMissed(ctx context.Context, sub submission) { log.Warn(ctx, msg, nil, z.Any("pubkey", sub.Pubkey), - z.I64("block_slot", sub.Duty.Slot), + z.U64("block_slot", sub.Duty.Slot), z.Any("broadcast_delay", sub.Delay), ) default: @@ -291,7 +291,7 @@ func reportMissed(ctx context.Context, sub submission) { func reportAttInclusion(ctx context.Context, sub submission, block block) { att := block.AttestationsByDataRoot[sub.AttDataRoot] aggIndices := att.AggregationBits.BitIndices() - attSlot := int64(att.Data.Slot) + attSlot := uint64(att.Data.Slot) blockSlot := block.Slot inclDelay := block.Slot - attSlot @@ -301,10 +301,10 @@ func reportAttInclusion(ctx context.Context, sub submission, block block) { } log.Info(ctx, msg, - z.I64("block_slot", blockSlot), - z.I64("attestation_slot", attSlot), + z.U64("block_slot", blockSlot), + z.U64("attestation_slot", attSlot), z.Any("pubkey", sub.Pubkey), - z.I64("inclusion_delay", inclDelay), + z.U64("inclusion_delay", inclDelay), z.Any("broadcast_delay", sub.Delay), z.Int("aggregate_len", len(aggIndices)), z.Bool("aggregated", len(aggIndices) > 1), @@ -369,20 +369,20 @@ func (a *InclusionChecker) Run(ctx context.Context) { ticker := time.NewTicker(time.Second) defer ticker.Stop() - var checkedSlot int64 + var checkedSlot uint64 for { select { case <-ctx.Done(): return case <-ticker.C: - slot := int64(time.Since(a.genesis)/a.slotDuration) - InclCheckLag + slot := uint64(time.Since(a.genesis)/a.slotDuration) - InclCheckLag if checkedSlot == slot || slot < 0 { continue } if err := a.checkBlock(ctx, slot); err != nil { - log.Warn(ctx, "Failed to check inclusion", err, z.I64("slot", slot)) + log.Warn(ctx, "Failed to check inclusion", err, z.U64("slot", slot)) continue } @@ -392,7 +392,7 @@ func (a *InclusionChecker) Run(ctx context.Context) { } } -func (a *InclusionChecker) checkBlock(ctx context.Context, slot int64) error { +func (a *InclusionChecker) checkBlock(ctx context.Context, slot uint64) error { atts, err := a.eth2Cl.BlockAttestations(ctx, fmt.Sprint(slot)) if err != nil { return err diff --git a/core/tracker/inclusion_internal_test.go b/core/tracker/inclusion_internal_test.go index b53663a80..b4d874029 100644 --- a/core/tracker/inclusion_internal_test.go +++ b/core/tracker/inclusion_internal_test.go @@ -67,7 +67,7 @@ func TestDuplicateAttData(t *testing.T) { close(done) } - err = incl.checkBlock(ctx, int64(attData.Slot)) + err = incl.checkBlock(ctx, uint64(attData.Slot)) require.NoError(t, err) <-done @@ -89,20 +89,20 @@ func TestInclusion(t *testing.T) { // Create some duties att1 := testutil.RandomAttestation() - att1Duty := core.NewAttesterDuty(int64(att1.Data.Slot)) + att1Duty := core.NewAttesterDuty(uint64(att1.Data.Slot)) agg2 := testutil.RandomSignedAggregateAndProof() - agg2Duty := core.NewAggregatorDuty(int64(agg2.Message.Aggregate.Data.Slot)) + agg2Duty := core.NewAggregatorDuty(uint64(agg2.Message.Aggregate.Data.Slot)) att3 := testutil.RandomAttestation() - att3Duty := core.NewAttesterDuty(int64(att3.Data.Slot)) + att3Duty := core.NewAttesterDuty(uint64(att3.Data.Slot)) block4 := testutil.RandomVersionedSignedProposal() - block4Duty := core.NewProposerDuty(int64(block4.Capella.Message.Slot)) + block4Duty := core.NewProposerDuty(uint64(block4.Capella.Message.Slot)) block5 := testutil.RandomCapellaVersionedSignedBlindedProposal() block5.Capella.Message.Body.Graffiti = eth2wrap.GetSyntheticGraffiti() // Ignored, not included or missed. - block5Duty := core.NewBuilderProposerDuty(int64(block5.Capella.Message.Slot)) + block5Duty := core.NewBuilderProposerDuty(uint64(block5.Capella.Message.Slot)) // Submit all duties err := incl.Submitted(att1Duty, "", core.NewAttestation(att1), 0) diff --git a/core/tracker/tracker.go b/core/tracker/tracker.go index 952a7ad3a..f93447804 100644 --- a/core/tracker/tracker.go +++ b/core/tracker/tracker.go @@ -93,7 +93,7 @@ type Tracker struct { // deleter triggers duty deletion after all associated analysis are done. deleter core.Deadliner // fromSlot indicates the slot to start tracking events from. - fromSlot int64 + fromSlot uint64 quit chan struct{} // parSigReporter instruments partial signature data inconsistencies. @@ -107,7 +107,7 @@ type Tracker struct { } // New returns a new Tracker. The deleter deadliner must return well after analyser deadliner since duties of the same slot are often analysed together. -func New(analyser core.Deadliner, deleter core.Deadliner, peers []p2p.Peer, fromSlot int64) *Tracker { +func New(analyser core.Deadliner, deleter core.Deadliner, peers []p2p.Peer, fromSlot uint64) *Tracker { t := &Tracker{ input: make(chan event), events: make(map[core.Duty][]event), diff --git a/core/tracker/tracker_internal_test.go b/core/tracker/tracker_internal_test.go index 04f700b80..d166a08b2 100644 --- a/core/tracker/tracker_internal_test.go +++ b/core/tracker/tracker_internal_test.go @@ -125,10 +125,10 @@ func TestTrackerFailedDuty(t *testing.T) { func TestAnalyseDutyFailed(t *testing.T) { slot := 1 - attDuty := core.NewAttesterDuty(int64(slot)) - proposerDuty := core.NewProposerDuty(int64(slot)) - randaoDuty := core.NewRandaoDuty(int64(slot)) - syncMsgDuty := core.NewSyncMessageDuty(int64(slot)) + attDuty := core.NewAttesterDuty(uint64(slot)) + proposerDuty := core.NewProposerDuty(uint64(slot)) + randaoDuty := core.NewRandaoDuty(uint64(slot)) + syncMsgDuty := core.NewSyncMessageDuty(uint64(slot)) // Note the order of the events inserted by subtests below is important. events := make(map[core.Duty][]event) @@ -336,7 +336,7 @@ func TestAnalyseDutyFailed(t *testing.T) { t.Run("Attester Duty Success", func(t *testing.T) { var ( events = make(map[core.Duty][]event) - attDuty = core.NewAttesterDuty(int64(1)) + attDuty = core.NewAttesterDuty(uint64(1)) ) require.Equal(t, chainInclusion, lastStep(attDuty.Type)) @@ -355,7 +355,7 @@ func TestAnalyseDutyFailed(t *testing.T) { t.Run("SyncContrib Duty Success", func(t *testing.T) { var ( events = make(map[core.Duty][]event) - syncContribDuty = core.NewSyncContributionDuty(int64(1)) + syncContribDuty = core.NewSyncContributionDuty(uint64(1)) ) require.Equal(t, bcast, lastStep(syncContribDuty.Type)) @@ -681,7 +681,7 @@ func setupData(t *testing.T, slots []int, numVals int) ([]testDutyData, []core.P var data []testDutyData for _, slot := range slots { - duty := core.NewAttesterDuty(int64(slot)) + duty := core.NewAttesterDuty(uint64(slot)) defset := make(core.DutyDefinitionSet) unsignedset := make(core.UnsignedDataSet) diff --git a/core/types.go b/core/types.go index d12baad9a..8e560c114 100644 --- a/core/types.go +++ b/core/types.go @@ -80,7 +80,7 @@ func AllDutyTypes() []DutyType { // Duty is the unit of work of the core workflow. type Duty struct { // Slot is the Ethereum consensus layer slot. - Slot int64 + Slot uint64 // Type is the duty type performed in the slot. Type DutyType } @@ -109,7 +109,7 @@ const ( // core.Duty{Slot: slot, Type: core.DutyAttester} // vs // core.NewAttesterDuty(slot) -func NewAttesterDuty(slot int64) Duty { +func NewAttesterDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyAttester, @@ -122,7 +122,7 @@ func NewAttesterDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyRandao} // vs // core.NewRandaoDuty(slot) -func NewRandaoDuty(slot int64) Duty { +func NewRandaoDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyRandao, @@ -135,7 +135,7 @@ func NewRandaoDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyProposer} // vs // core.NewProposerDuty(slot) -func NewProposerDuty(slot int64) Duty { +func NewProposerDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyProposer, @@ -148,7 +148,7 @@ func NewProposerDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyExit} // vs // core.NewVoluntaryExit(slot) -func NewVoluntaryExit(slot int64) Duty { +func NewVoluntaryExit(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyExit, @@ -161,7 +161,7 @@ func NewVoluntaryExit(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyBuilderProposer} // vs // core.NewBuilderProposerDuty(slot) -func NewBuilderProposerDuty(slot int64) Duty { +func NewBuilderProposerDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyBuilderProposer, @@ -174,7 +174,7 @@ func NewBuilderProposerDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyBuilderRegistration} // vs // core.NewBuilderRegistrationDuty(slot) -func NewBuilderRegistrationDuty(slot int64) Duty { +func NewBuilderRegistrationDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyBuilderRegistration, @@ -187,7 +187,7 @@ func NewBuilderRegistrationDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutySignature} // vs // core.NewSignatureDuty(slot) -func NewSignatureDuty(slot int64) Duty { +func NewSignatureDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutySignature, @@ -200,7 +200,7 @@ func NewSignatureDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyPrepareAggregator} // vs // core.NewPrepareAggregatorDuty(slot) -func NewPrepareAggregatorDuty(slot int64) Duty { +func NewPrepareAggregatorDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyPrepareAggregator, @@ -213,7 +213,7 @@ func NewPrepareAggregatorDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyAggregator} // vs // core.NewAggregatorDuty(slot) -func NewAggregatorDuty(slot int64) Duty { +func NewAggregatorDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyAggregator, @@ -226,7 +226,7 @@ func NewAggregatorDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutySyncMessage} // vs // core.NewSyncMessageDuty(slot) -func NewSyncMessageDuty(slot int64) Duty { +func NewSyncMessageDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutySyncMessage, @@ -239,7 +239,7 @@ func NewSyncMessageDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutyPrepareSyncContribution} // vs // core.NewPrepareSyncContributionDuty(slot) -func NewPrepareSyncContributionDuty(slot int64) Duty { +func NewPrepareSyncContributionDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyPrepareSyncContribution, @@ -252,7 +252,7 @@ func NewPrepareSyncContributionDuty(slot int64) Duty { // core.Duty{Slot: slot, Type: core.DutySyncContribution} // vs // core.NewSyncContributionDuty(slot) -func NewSyncContributionDuty(slot int64) Duty { +func NewSyncContributionDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutySyncContribution, @@ -261,7 +261,7 @@ func NewSyncContributionDuty(slot int64) Duty { // NewInfoSyncDuty returns a new info sync duty. It is a convenience function that is // slightly more readable and concise than the struct literal equivalent. -func NewInfoSyncDuty(slot int64) Duty { +func NewInfoSyncDuty(slot uint64) Duty { return Duty{ Slot: slot, Type: DutyInfoSync, @@ -467,10 +467,10 @@ func (s SignedDataSet) Clone() (SignedDataSet, error) { // Slot is a beacon chain slot including chain metadata to infer epoch and next slot. type Slot struct { - Slot int64 + Slot uint64 Time time.Time SlotDuration time.Duration - SlotsPerEpoch int64 + SlotsPerEpoch uint64 } // Next returns the next slot. @@ -484,7 +484,7 @@ func (s Slot) Next() Slot { } // Epoch returns the epoch of the slot. -func (s Slot) Epoch() int64 { +func (s Slot) Epoch() uint64 { return s.Slot / s.SlotsPerEpoch } diff --git a/core/validatorapi/validatorapi.go b/core/validatorapi/validatorapi.go index bd98477e3..9cc0c9b15 100644 --- a/core/validatorapi/validatorapi.go +++ b/core/validatorapi/validatorapi.go @@ -39,7 +39,7 @@ func NewComponentInsecure(_ *testing.T, eth2Cl eth2wrap.Client, shareIdx int) (* return &Component{ eth2Cl: eth2Cl, shareIdx: shareIdx, - builderEnabled: func(int64) bool { return false }, + builderEnabled: func(uint64) bool { return false }, insecureTest: true, }, nil } @@ -152,12 +152,12 @@ type Component struct { // Registered input functions - 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, 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) + pubKeyByAttFunc func(ctx context.Context, slot, commIdx, valCommIdx uint64) (core.PubKey, error) + awaitAttFunc func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error) + awaitProposalFunc func(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error) + awaitBlindedProposalFunc func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error) + awaitSyncContributionFunc func(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) + awaitAggAttFunc func(ctx context.Context, slot uint64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error) awaitAggSigDBFunc func(context.Context, core.Duty, core.PubKey) (core.SignedData, error) dutyDefFunc func(ctx context.Context, duty core.Duty) (core.DutyDefinitionSet, error) subs []func(context.Context, core.Duty, core.ParSignedDataSet) error @@ -165,31 +165,31 @@ 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, slot int64) (*eth2api.VersionedProposal, error)) { +func (c *Component) RegisterAwaitProposal(fn func(ctx context.Context, slot uint64) (*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, slot int64) (*eth2api.VersionedBlindedProposal, error)) { +func (c *Component) RegisterAwaitBlindedProposal(fn func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error)) { c.awaitBlindedProposalFunc = fn } // RegisterAwaitAttestation registers a function to query attestation data. // It only supports a single function, since it is an input of the component. -func (c *Component) RegisterAwaitAttestation(fn func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)) { +func (c *Component) RegisterAwaitAttestation(fn func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error)) { c.awaitAttFunc = fn } // RegisterAwaitSyncContribution registers a function to query sync contribution data. // It only supports a single function, since it is an input of the component. -func (c *Component) RegisterAwaitSyncContribution(fn func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) { +func (c *Component) RegisterAwaitSyncContribution(fn func(ctx context.Context, slot, subcommIdx uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)) { c.awaitSyncContributionFunc = fn } // RegisterPubKeyByAttestation registers a function to query pubkeys by attestation. // It only supports a single function, since it is an input of the component. -func (c *Component) RegisterPubKeyByAttestation(fn func(ctx context.Context, slot, commIdx, valCommIdx int64) (core.PubKey, error)) { +func (c *Component) RegisterPubKeyByAttestation(fn func(ctx context.Context, slot, commIdx, valCommIdx uint64) (core.PubKey, error)) { c.pubKeyByAttFunc = fn } @@ -201,7 +201,7 @@ func (c *Component) RegisterGetDutyDefinition(fn func(ctx context.Context, duty // RegisterAwaitAggAttestation registers a function to query an aggregated attestation. // It supports a single function, since it is an input of the component. -func (c *Component) RegisterAwaitAggAttestation(fn func(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error)) { +func (c *Component) RegisterAwaitAggAttestation(fn func(ctx context.Context, slot uint64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error)) { c.awaitAggAttFunc = fn } @@ -226,10 +226,10 @@ func (c *Component) Subscribe(fn func(context.Context, core.Duty, core.ParSigned // AttestationData implements the eth2client.AttesterDutiesProvider for the router. func (c Component) AttestationData(parent context.Context, opts *eth2api.AttestationDataOpts) (*eth2api.Response[*eth2p0.AttestationData], error) { - ctx, span := core.StartDutyTrace(parent, core.NewAttesterDuty(int64(opts.Slot)), "core/validatorapi.AttestationData") + ctx, span := core.StartDutyTrace(parent, core.NewAttesterDuty(uint64(opts.Slot)), "core/validatorapi.AttestationData") defer span.End() - att, err := c.awaitAttFunc(ctx, int64(opts.Slot), int64(opts.CommitteeIndex)) + att, err := c.awaitAttFunc(ctx, uint64(opts.Slot), uint64(opts.CommitteeIndex)) if err != nil { return nil, err } @@ -239,7 +239,7 @@ func (c Component) AttestationData(parent context.Context, opts *eth2api.Attesta // SubmitAttestations implements the eth2client.AttestationsSubmitter for the router. func (c Component) SubmitAttestations(ctx context.Context, attestations []*eth2p0.Attestation) error { - duty := core.NewAttesterDuty(int64(attestations[0].Data.Slot)) + duty := core.NewAttesterDuty(uint64(attestations[0].Data.Slot)) if len(attestations) > 0 { // Pick the first attestation slot to use as trace root. var span trace.Span @@ -247,9 +247,9 @@ func (c Component) SubmitAttestations(ctx context.Context, attestations []*eth2p defer span.End() } - setsBySlot := make(map[int64]core.ParSignedDataSet) + setsBySlot := make(map[uint64]core.ParSignedDataSet) for _, att := range attestations { - slot := int64(att.Data.Slot) + slot := uint64(att.Data.Slot) // Determine the validator that sent this by mapping values from original AttestationDuty via the dutyDB indices := att.AggregationBits.BitIndices() @@ -258,9 +258,9 @@ func (c Component) SubmitAttestations(ctx context.Context, attestations []*eth2p z.Str("aggbits", fmt.Sprintf("%#x", []byte(att.AggregationBits)))) } - pubkey, err := c.pubKeyByAttFunc(ctx, slot, int64(att.Data.Index), int64(indices[0])) + pubkey, err := c.pubKeyByAttFunc(ctx, slot, uint64(att.Data.Index), uint64(indices[0])) if err != nil { - return errors.Wrap(err, "failed to find pubkey", z.I64("slot", slot), + return errors.Wrap(err, "failed to find pubkey", z.U64("slot", slot), z.Int("commIdx", int(att.Data.Index)), z.Int("valCommIdx", indices[0])) } @@ -301,7 +301,7 @@ func (c Component) SubmitAttestations(ctx context.Context, attestations []*eth2p func (c Component) Proposal(ctx context.Context, opts *eth2api.ProposalOpts) (*eth2api.Response[*eth2api.VersionedProposal], error) { // Get proposer pubkey (this is a blocking query). - pubkey, err := c.getProposerPubkey(ctx, core.NewProposerDuty(int64(opts.Slot))) + pubkey, err := c.getProposerPubkey(ctx, core.NewProposerDuty(uint64(opts.Slot))) if err != nil { return nil, err } @@ -316,7 +316,7 @@ func (c Component) Proposal(ctx context.Context, opts *eth2api.ProposalOpts) (*e Signature: opts.RandaoReveal, } - duty := core.NewRandaoDuty(int64(opts.Slot)) + duty := core.NewRandaoDuty(uint64(opts.Slot)) parSig := core.NewPartialSignedRandao(sigEpoch.Epoch, sigEpoch.Signature, c.shareIdx) // Verify randao signature @@ -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, int64(opts.Slot)) + proposal, err := c.awaitProposalFunc(ctx, uint64(opts.Slot)) if err != nil { return nil, err } @@ -359,7 +359,7 @@ func (c Component) Proposal(ctx context.Context, opts *eth2api.ProposalOpts) (*e func (c Component) BlindedProposal(ctx context.Context, opts *eth2api.BlindedProposalOpts) (*eth2api.Response[*eth2api.VersionedBlindedProposal], error) { // Get proposer pubkey (this is a blocking query). - pubkey, err := c.getProposerPubkey(ctx, core.NewBuilderProposerDuty(int64(opts.Slot))) + pubkey, err := c.getProposerPubkey(ctx, core.NewBuilderProposerDuty(uint64(opts.Slot))) if err != nil { return nil, err } @@ -374,7 +374,7 @@ func (c Component) BlindedProposal(ctx context.Context, opts *eth2api.BlindedPro Signature: opts.RandaoReveal, } - duty := core.NewRandaoDuty(int64(opts.Slot)) + duty := core.NewRandaoDuty(uint64(opts.Slot)) parSig := core.NewPartialSignedRandao(sigEpoch.Epoch, sigEpoch.Signature, c.shareIdx) // Verify randao signature @@ -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, int64(opts.Slot)) + proposal, err := c.awaitBlindedProposalFunc(ctx, uint64(opts.Slot)) if err != nil { return nil, err } @@ -421,13 +421,13 @@ func (c Component) SubmitProposal(ctx context.Context, proposal *eth2api.Version return err } - pubkey, err := c.getProposerPubkey(ctx, core.NewProposerDuty(int64(slot))) + pubkey, err := c.getProposerPubkey(ctx, core.NewProposerDuty(uint64(slot))) if err != nil { return err } // Save Partially Signed Block to ParSigDB - duty := core.NewProposerDuty(int64(slot)) + duty := core.NewProposerDuty(uint64(slot)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) signedData, err := core.NewPartialVersionedSignedProposal(proposal, c.shareIdx) @@ -461,13 +461,13 @@ func (c Component) SubmitBlindedProposal(ctx context.Context, proposal *eth2api. return err } - pubkey, err := c.getProposerPubkey(ctx, core.NewBuilderProposerDuty(int64(slot))) + pubkey, err := c.getProposerPubkey(ctx, core.NewBuilderProposerDuty(uint64(slot))) if err != nil { return err } // Save Partially Signed Blinded Block to ParSigDB - duty := core.NewBuilderProposerDuty(int64(slot)) + duty := core.NewBuilderProposerDuty(uint64(slot)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) signedData, err := core.NewPartialVersionedSignedBlindedProposal(proposal, c.shareIdx) @@ -524,7 +524,7 @@ func (c Component) submitRegistration(ctx context.Context, registration *eth2api return err } - duty := core.NewBuilderRegistrationDuty(int64(slot)) + duty := core.NewBuilderRegistrationDuty(uint64(slot)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) signedData, err := core.NewPartialVersionedSignedValidatorRegistration(registration, c.shareIdx) @@ -563,7 +563,7 @@ func (c Component) SubmitValidatorRegistrations(ctx context.Context, registratio } // Swallow unexpected validator registrations from VCs (for ex: vouch) - if !c.builderEnabled(int64(slot)) { + if !c.builderEnabled(uint64(slot)) { return nil } @@ -600,7 +600,7 @@ func (c Component) SubmitVoluntaryExit(ctx context.Context, exit *eth2p0.SignedV return err } - duty := core.NewVoluntaryExit(int64(slotsPerEpoch) * int64(exit.Message.Epoch)) + duty := core.NewVoluntaryExit(slotsPerEpoch * uint64(exit.Message.Epoch)) ctx = log.WithCtx(ctx, z.Any("duty", duty)) parSigData := core.NewPartialSignedVoluntaryExit(exit, c.shareIdx) @@ -660,7 +660,7 @@ func (c Component) AggregateBeaconCommitteeSelections(ctx context.Context, selec } for slot, data := range psigsBySlot { - duty := core.NewPrepareAggregatorDuty(int64(slot)) + duty := core.NewPrepareAggregatorDuty(uint64(slot)) for _, sub := range c.subs { err = sub(ctx, duty, data) if err != nil { @@ -675,7 +675,7 @@ func (c Component) AggregateBeaconCommitteeSelections(ctx context.Context, selec // AggregateAttestation returns the aggregate attestation for the given attestation root. // It does a blocking query to DutyAggregator unsigned data from dutyDB. func (c Component) AggregateAttestation(ctx context.Context, opts *eth2api.AggregateAttestationOpts) (*eth2api.Response[*eth2p0.Attestation], error) { - aggAtt, err := c.awaitAggAttFunc(ctx, int64(opts.Slot), opts.AttestationDataRoot) + aggAtt, err := c.awaitAggAttFunc(ctx, uint64(opts.Slot), opts.AttestationDataRoot) if err != nil { return nil, err } @@ -730,7 +730,7 @@ func (c Component) SubmitAggregateAttestations(ctx context.Context, aggregateAnd } for slot, data := range psigsBySlot { - duty := core.NewAggregatorDuty(int64(slot)) + duty := core.NewAggregatorDuty(uint64(slot)) for _, sub := range c.subs { err = sub(ctx, duty, data) if err != nil { @@ -744,7 +744,7 @@ func (c Component) SubmitAggregateAttestations(ctx context.Context, aggregateAnd // SyncCommitteeContribution returns sync committee contribution data for the given subcommittee and beacon block root. func (c Component) SyncCommitteeContribution(ctx context.Context, opts *eth2api.SyncCommitteeContributionOpts) (*eth2api.Response[*altair.SyncCommitteeContribution], error) { - contrib, err := c.awaitSyncContributionFunc(ctx, int64(opts.Slot), int64(opts.SubcommitteeIndex), opts.BeaconBlockRoot) + contrib, err := c.awaitSyncContributionFunc(ctx, uint64(opts.Slot), opts.SubcommitteeIndex, opts.BeaconBlockRoot) if err != nil { return nil, err } @@ -787,7 +787,7 @@ func (c Component) SubmitSyncCommitteeMessages(ctx context.Context, messages []* } for slot, data := range psigsBySlot { - duty := core.NewSyncMessageDuty(int64(slot)) + duty := core.NewSyncMessageDuty(uint64(slot)) for _, sub := range c.subs { err = sub(ctx, duty, data) if err != nil { @@ -849,7 +849,7 @@ func (c Component) SubmitSyncCommitteeContributions(ctx context.Context, contrib } for slot, data := range psigsBySlot { - duty := core.NewSyncContributionDuty(int64(slot)) + duty := core.NewSyncContributionDuty(uint64(slot)) for _, sub := range c.subs { err = sub(ctx, duty, data) if err != nil { @@ -897,7 +897,7 @@ func (c Component) AggregateSyncCommitteeSelections(ctx context.Context, partial } for slot, data := range psigsBySlot { - duty := core.NewPrepareSyncContributionDuty(int64(slot)) + duty := core.NewPrepareSyncContributionDuty(uint64(slot)) for _, sub := range c.subs { err = sub(ctx, duty, data) if err != nil { @@ -1108,7 +1108,7 @@ func (c Component) verifyPartialSig(ctx context.Context, parSig core.ParSignedDa func (c Component) getAggregateBeaconCommSelection(ctx context.Context, psigsBySlot map[eth2p0.Slot]core.ParSignedDataSet) ([]*eth2exp.BeaconCommitteeSelection, error) { var resp []*eth2exp.BeaconCommitteeSelection for slot, data := range psigsBySlot { - duty := core.NewPrepareAggregatorDuty(int64(slot)) + duty := core.NewPrepareAggregatorDuty(uint64(slot)) for pk := range data { // Query aggregated subscription from aggsigdb for each duty and public key (this is blocking). s, err := c.awaitAggSigDBFunc(ctx, duty, pk) @@ -1131,7 +1131,7 @@ func (c Component) getAggregateBeaconCommSelection(ctx context.Context, psigsByS func (c Component) getAggregateSyncCommSelection(ctx context.Context, psigsBySlot map[eth2p0.Slot]core.ParSignedDataSet) ([]*eth2exp.SyncCommitteeSelection, error) { var resp []*eth2exp.SyncCommitteeSelection for slot, data := range psigsBySlot { - duty := core.NewPrepareSyncContributionDuty(int64(slot)) + duty := core.NewPrepareSyncContributionDuty(uint64(slot)) for pk := range data { // Query aggregated sync committee selection from aggsigdb for each duty and public key (this is blocking). s, err := c.awaitAggSigDBFunc(ctx, duty, pk) @@ -1189,7 +1189,7 @@ func (c Component) ProposerConfig(ctx context.Context) (*eth2exp.ProposerConfigR resp.Proposers[eth2Share] = eth2exp.ProposerConfig{ FeeRecipient: c.feeRecipientFunc(pubkey), Builder: eth2exp.Builder{ - Enabled: c.builderEnabled(int64(slot)), + Enabled: c.builderEnabled(uint64(slot)), GasLimit: gasLimit, Overrides: map[string]string{ "timestamp": fmt.Sprint(timestamp.Unix()), diff --git a/core/validatorapi/validatorapi_test.go b/core/validatorapi/validatorapi_test.go index ef7539ef7..4aa7de192 100644 --- a/core/validatorapi/validatorapi_test.go +++ b/core/validatorapi/validatorapi_test.go @@ -87,13 +87,13 @@ func TestComponent_ValidSubmitAttestations(t *testing.T) { atts := []*eth2p0.Attestation{attA, attB} - component.RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx int64) (core.PubKey, error) { + component.RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx uint64) (core.PubKey, error) { return pubkeysByIdx[eth2p0.ValidatorIndex(valCommIdx)], nil }) component.Subscribe(func(ctx context.Context, duty core.Duty, set core.ParSignedDataSet) error { require.Equal(t, core.DutyAttester, duty.Type) - require.Equal(t, int64(slot), duty.Slot) + require.Equal(t, uint64(slot), duty.Slot) parSignedDataA := set[pubkeysByIdx[vIdxA]] actAttA, ok := parSignedDataA.SignedData.(core.Attestation) @@ -188,7 +188,7 @@ func TestSubmitAttestations_Verify(t *testing.T) { vapi, err := validatorapi.NewComponent(bmock, allPubSharesByKey, shareIdx, nil, testutil.BuilderFalse, nil) require.NoError(t, err) - vapi.RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx int64) (core.PubKey, error) { + vapi.RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx uint64) (core.PubKey, error) { require.EqualValues(t, slot, epochSlot) require.EqualValues(t, commIdx, vIdx) require.EqualValues(t, valCommIdx, 0) @@ -295,7 +295,7 @@ func TestSignAndVerify(t *testing.T) { // Setup validatorapi component. vapi, err := validatorapi.NewComponent(bmock, allPubSharesByKey, shareIdx, nil, testutil.BuilderFalse, nil) require.NoError(t, err) - vapi.RegisterPubKeyByAttestation(func(context.Context, int64, int64, int64) (core.PubKey, error) { + vapi.RegisterPubKeyByAttestation(func(context.Context, uint64, uint64, uint64) (core.PubKey, error) { return core.PubKeyFromBytes(pubkey[:]) }) @@ -377,7 +377,7 @@ func TestComponent_Proposal(t *testing.T) { return core.DutyDefinitionSet{pubkey: nil}, nil }) - component.RegisterAwaitProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedProposal, error) { + component.RegisterAwaitProposal(func(ctx context.Context, slot uint64) (*eth2api.VersionedProposal, error) { return block1, nil }) @@ -700,11 +700,11 @@ func TestComponent_BlindedProposal(t *testing.T) { return core.DutyDefinitionSet{pubkey: nil}, nil }) - component.RegisterAwaitBlindedProposal(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedProposal, error) { + component.RegisterAwaitBlindedProposal(func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedProposal, error) { return block1, nil }) - // component.RegisterAwaitBlindedBeaconBlock(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedBeaconBlock, error) { + // component.RegisterAwaitBlindedBeaconBlock(func(ctx context.Context, slot uint64) (*eth2api.VersionedBlindedBeaconBlock, error) { // return block1, nil // }) @@ -1449,7 +1449,7 @@ func TestComponent_SubmitAggregateAttestations(t *testing.T) { require.NoError(t, err) vapi.Subscribe(func(_ context.Context, duty core.Duty, set core.ParSignedDataSet) error { - require.Equal(t, core.NewAggregatorDuty(int64(slot)), duty) + require.Equal(t, core.NewAggregatorDuty(uint64(slot)), duty) pk, err := core.PubKeyFromBytes(pubkey[:]) require.NoError(t, err) @@ -1539,7 +1539,7 @@ func TestComponent_SubmitSyncCommitteeMessages(t *testing.T) { require.NoError(t, err) vapi.Subscribe(func(_ context.Context, duty core.Duty, set core.ParSignedDataSet) error { - require.Equal(t, core.NewSyncMessageDuty(int64(msg.Slot)), duty) + require.Equal(t, core.NewSyncMessageDuty(uint64(msg.Slot)), duty) pk, err := core.PubKeyFromBytes(pubkey[:]) require.NoError(t, err) @@ -1564,7 +1564,7 @@ func TestComponent_SubmitSyncCommitteeContributions(t *testing.T) { ctx = context.Background() contrib = testutil.RandomSignedSyncContributionAndProof() pubkey = beaconmock.ValidatorSetA[vIdx].Validator.PublicKey - expectedDuty = core.NewSyncContributionDuty(int64(contrib.Message.Contribution.Slot)) + expectedDuty = core.NewSyncContributionDuty(uint64(contrib.Message.Contribution.Slot)) ) contrib.Message.AggregatorIndex = vIdx diff --git a/dkg/exchanger.go b/dkg/exchanger.go index a333b8b5c..6801db178 100644 --- a/dkg/exchanger.go +++ b/dkg/exchanger.go @@ -131,7 +131,7 @@ func newExchanger(tcpNode host.Host, peerIdx int, peers []peer.ID, vals int, sig // signatures of the group according to public key of each DV. func (e *exchanger) exchange(ctx context.Context, sigType sigType, set core.ParSignedDataSet) (map[core.PubKey][]core.ParSignedData, error) { // Start the process by storing current peer's ParSignedDataSet - duty := core.NewSignatureDuty(int64(sigType)) + duty := core.NewSignatureDuty(uint64(sigType)) err := e.sigdb.StoreInternal(ctx, duty, set) if err != nil { return nil, err diff --git a/docs/architecture.md b/docs/architecture.md index e3108bf63..95005e03e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -107,7 +107,7 @@ A duty therefore has a slot and a type and is defined as: // Duty is the unit of work of the core workflow. type Duty struct { // Slot is the Ethereum consensus slot of the duty. - Slot int64 + Slot uint64 // Type is the type of duty. Type DutyType } diff --git a/p2p/receive_test.go b/p2p/receive_test.go index 53f188062..dad69e381 100644 --- a/p2p/receive_test.go +++ b/p2p/receive_test.go @@ -53,20 +53,15 @@ func TestSendReceive(t *testing.T) { }, ) - sendReceive := func(slot int64) (*pbv1.Duty, error) { + sendReceive := func(slot uint64) (*pbv1.Duty, error) { resp := new(pbv1.Duty) err := p2p.SendReceive(ctx, client, server.ID(), &pbv1.Duty{Slot: slot}, resp, pID) return resp, err } - t.Run("server error", func(t *testing.T) { - _, err := sendReceive(-1) - require.ErrorContains(t, err, "read response: EOF") - }) - t.Run("ok", func(t *testing.T) { - slot := int64(100) + slot := uint64(100) resp, err := sendReceive(slot) require.NoError(t, err) require.Equal(t, slot, resp.Slot) diff --git a/p2p/sender_test.go b/p2p/sender_test.go index 128777d86..fd9ed9a2a 100644 --- a/p2p/sender_test.go +++ b/p2p/sender_test.go @@ -212,12 +212,6 @@ func testSend(t *testing.T, clientBasicProtoID, serverBasicProtoID, delimitedID return } - t.Run("server error", func(t *testing.T) { - err := p2p.Send(ctx, client, clientBasicProtoID, server.ID(), &pbv1.Duty{Slot: -1}, clientOpt...) - require.NoError(t, err) - require.ErrorContains(t, <-serverErrChan, "negative slot") - }) - t.Run("ok", func(t *testing.T) { err := p2p.Send(ctx, client, clientBasicProtoID, server.ID(), &pbv1.Duty{Slot: 100}, clientOpt...) require.NoError(t, err) diff --git a/testutil/helpers.go b/testutil/helpers.go index b1c6e258e..ada2466e5 100644 --- a/testutil/helpers.go +++ b/testutil/helpers.go @@ -13,10 +13,10 @@ import ( ) // BuilderFalse is a core.BuilderEnabled function that always returns false. -var BuilderFalse = func(slot int64) bool { return false } +var BuilderFalse = func(slot uint64) bool { return false } // BuilderTrue is a core.BuilderEnabled function that always returns true. -var BuilderTrue = func(slot int64) bool { return true } +var BuilderTrue = func(slot uint64) bool { return true } // NewTCPNodeCallback returns a callback that can be used to connect a TCP node to all other TCP nodes. func NewTCPNodeCallback(t *testing.T, protocols ...protocol.ID) func(host host.Host) { diff --git a/testutil/validatormock/component.go b/testutil/validatormock/component.go index 44ba0f84c..0dcc1e572 100644 --- a/testutil/validatormock/component.go +++ b/testutil/validatormock/component.go @@ -107,7 +107,7 @@ func dutiesForSlot(slot metaSlot, types ...core.DutyType) map[scheduleTuple]stru resp[scheduleTuple{ duty: core.Duty{ Type: dutyType, - Slot: int64(checkSlot.Slot), + Slot: checkSlot.Slot, }, startTime: startTime, }] = struct{}{} From 0a03a1c58642f7f1971849399344e5b774662bd5 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 31 Oct 2023 15:30:32 +0530 Subject: [PATCH 2/6] convert int64s to uint64s to comply with spec --- core/aggsigdb/memory_internal_test.go | 4 ++-- core/fetcher/fetcher.go | 6 +++--- core/gater.go | 2 +- core/leadercast/leadercast_internal_test.go | 2 +- core/leadercast/transport_test.go | 4 ++-- core/priority/calculate_internal_test.go | 4 ++-- core/priority/prioritiser_test.go | 6 +++--- core/scheduler/scheduler.go | 6 +++--- core/tracker/inclusion.go | 2 +- p2p/receive_test.go | 14 +++++--------- p2p/sender_test.go | 14 +++----------- testutil/validatormock/component.go | 6 +++--- 12 files changed, 29 insertions(+), 41 deletions(-) diff --git a/core/aggsigdb/memory_internal_test.go b/core/aggsigdb/memory_internal_test.go index 674c65049..db69ed6b6 100644 --- a/core/aggsigdb/memory_internal_test.go +++ b/core/aggsigdb/memory_internal_test.go @@ -27,7 +27,7 @@ func TestDutyExpiration(t *testing.T) { db.Run(ctx) }() - slot := int64(99) + slot := uint64(99) duty := core.NewAttesterDuty(slot) pubkey := testutil.RandomCorePubKey(t) sig := testutil.RandomCoreSignature() @@ -66,7 +66,7 @@ func TestCancelledQuery(t *testing.T) { go db.Run(ctx) - slot := int64(99) + slot := uint64(99) duty := core.NewAttesterDuty(slot) pubkey := testutil.RandomCorePubKey(t) sig := testutil.RandomCoreSignature() diff --git a/core/fetcher/fetcher.go b/core/fetcher/fetcher.go index 3fbd575bc..8728339e9 100644 --- a/core/fetcher/fetcher.go +++ b/core/fetcher/fetcher.go @@ -129,7 +129,7 @@ func (f *Fetcher) fetchAttesterData(ctx context.Context, slot uint64, defSet cor if !ok { var err error opts := ð2api.AttestationDataOpts{ - Slot: eth2p0.Slot(uint64(slot)), + Slot: eth2p0.Slot(slot), CommitteeIndex: commIdx, } eth2Resp, err := f.eth2Cl.AttestationData(ctx, opts) @@ -252,7 +252,7 @@ func (f *Fetcher) fetchProposerData(ctx context.Context, slot uint64, defSet cor copy(graffiti[:], fmt.Sprintf("charon/%v-%s", version.Version, commitSHA)) opts := ð2api.ProposalOpts{ - Slot: eth2p0.Slot(uint64(slot)), + Slot: eth2p0.Slot(slot), RandaoReveal: randao, Graffiti: graffiti, } @@ -297,7 +297,7 @@ func (f *Fetcher) fetchBuilderProposerData(ctx context.Context, slot uint64, def copy(graffiti[:], fmt.Sprintf("charon/%v-%s", version.Version, commitSHA)) opts := ð2api.BlindedProposalOpts{ - Slot: eth2p0.Slot(uint64(slot)), + Slot: eth2p0.Slot(slot), RandaoReveal: randao, Graffiti: graffiti, } diff --git a/core/gater.go b/core/gater.go index 8996b2077..63138b7c4 100644 --- a/core/gater.go +++ b/core/gater.go @@ -65,7 +65,7 @@ func NewDutyGater(ctx context.Context, eth2Cl eth2wrap.Client, opts ...func(*dut currentSlot := o.nowFunc().Sub(genesisTime) / slotDuration currentEpoch := uint64(currentSlot) / slotsPerEpoch - dutyEpoch := uint64(duty.Slot) / slotsPerEpoch + dutyEpoch := duty.Slot / slotsPerEpoch return dutyEpoch <= currentEpoch+uint64(o.allowedFutureEpochs) }, nil diff --git a/core/leadercast/leadercast_internal_test.go b/core/leadercast/leadercast_internal_test.go index bb00b73dd..2681417b1 100644 --- a/core/leadercast/leadercast_internal_test.go +++ b/core/leadercast/leadercast_internal_test.go @@ -13,7 +13,7 @@ import ( func TestIsLeader(t *testing.T) { tests := []struct { - Slot int64 + Slot uint64 DutyType core.DutyType Leader, Total int }{ diff --git a/core/leadercast/transport_test.go b/core/leadercast/transport_test.go index 70f8c5b4c..b66d39f49 100644 --- a/core/leadercast/transport_test.go +++ b/core/leadercast/transport_test.go @@ -57,7 +57,7 @@ func TestMemTransport(t *testing.T) { // propose attestation for each slot var expected []core.UnsignedDataSet for i := 0; i < slots; i++ { - duty := core.Duty{Slot: int64(i)} + duty := core.Duty{Slot: uint64(i)} data := core.UnsignedDataSet{} for j := 0; j < n; j++ { unsignedData := core.AttestationData{ @@ -173,7 +173,7 @@ func TestP2PTransport(t *testing.T) { // propose attestation for each slot var expected []core.UnsignedDataSet for i := 0; i < slots; i++ { - duty := core.NewAttesterDuty(int64(i)) + duty := core.NewAttesterDuty(uint64(i)) data := core.UnsignedDataSet{} for j := 0; j < n; j++ { unsignedData := core.AttestationData{ diff --git a/core/priority/calculate_internal_test.go b/core/priority/calculate_internal_test.go index 666bf16b4..a16a8a60a 100644 --- a/core/priority/calculate_internal_test.go +++ b/core/priority/calculate_internal_test.go @@ -36,7 +36,7 @@ func TestCalculateResults(t *testing.T) { Priorities [][]string Result []string Scores []int64 - Slot int64 // Defaults to test index if not provided. + Slot uint64 // Defaults to test index if not provided. }{ { Name: "1*v1", @@ -155,7 +155,7 @@ func TestCalculateResults(t *testing.T) { var msgs []*pbv1.PriorityMsg for j, prioritySet := range test.Priorities { if test.Slot == 0 { - test.Slot = int64(i) + test.Slot = uint64(i) } msgs = append(msgs, &pbv1.PriorityMsg{ Topics: []*pbv1.PriorityTopicProposal{ diff --git a/core/priority/prioritiser_test.go b/core/priority/prioritiser_test.go index 242dfa0b6..ad3cf480a 100644 --- a/core/priority/prioritiser_test.go +++ b/core/priority/prioritiser_test.go @@ -106,7 +106,7 @@ func TestPrioritiser(t *testing.T) { type testConsensus struct { t *testing.T mu sync.Mutex - proposed map[int64]*pbv1.PriorityResult + proposed map[uint64]*pbv1.PriorityResult subs []func(ctx context.Context, duty core.Duty, result *pbv1.PriorityResult) error } @@ -130,7 +130,7 @@ func (t *testConsensus) ProposePriority(ctx context.Context, duty core.Duty, res } if t.proposed == nil { - t.proposed = make(map[int64]*pbv1.PriorityResult) + t.proposed = make(map[uint64]*pbv1.PriorityResult) } t.proposed[duty.Slot] = result @@ -151,7 +151,7 @@ func mustAny(pb proto.Message) *anypb.Any { } func prioToAny(prio int) *anypb.Any { - return mustAny(&pbv1.Duty{Slot: int64(prio)}) + return mustAny(&pbv1.Duty{Slot: uint64(prio)}) } func requireAnyDuty(t *testing.T, anyOf []core.Duty, actual core.Duty) { diff --git a/core/scheduler/scheduler.go b/core/scheduler/scheduler.go index d3fb4664f..c441a8262 100644 --- a/core/scheduler/scheduler.go +++ b/core/scheduler/scheduler.go @@ -339,7 +339,7 @@ func (s *Scheduler) resolveAttDuties(ctx context.Context, slot core.Slot, vals v z.U64("slot", uint64(attDuty.Slot)), z.U64("vidx", uint64(attDuty.ValidatorIndex)), z.Any("pubkey", pubkey), - z.U64("epoch", uint64(slot.Epoch())), + z.U64("epoch", slot.Epoch()), ) // Schedule aggregation duty as well. @@ -412,7 +412,7 @@ func (s *Scheduler) resolveProDuties(ctx context.Context, slot core.Slot, vals v z.U64("slot", uint64(proDuty.Slot)), z.U64("vidx", uint64(proDuty.ValidatorIndex)), z.Any("pubkey", pubkey), - z.U64("epoch", uint64(slot.Epoch())), + z.U64("epoch", slot.Epoch()), ) } @@ -467,7 +467,7 @@ func (s *Scheduler) resolveSyncCommDuties(ctx context.Context, slot core.Slot, v log.Info(ctx, "Resolved sync committee duty", z.U64("vidx", uint64(vIdx)), z.Any("pubkey", pubkey), - z.U64("epoch", uint64(slot.Epoch())), + z.U64("epoch", slot.Epoch()), ) } diff --git a/core/tracker/inclusion.go b/core/tracker/inclusion.go index 868950811..f71a09c1a 100644 --- a/core/tracker/inclusion.go +++ b/core/tracker/inclusion.go @@ -377,7 +377,7 @@ func (a *InclusionChecker) Run(ctx context.Context) { return case <-ticker.C: slot := uint64(time.Since(a.genesis)/a.slotDuration) - InclCheckLag - if checkedSlot == slot || slot < 0 { + if checkedSlot == slot { continue } diff --git a/p2p/receive_test.go b/p2p/receive_test.go index dad69e381..5ad651d8a 100644 --- a/p2p/receive_test.go +++ b/p2p/receive_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" - "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" pbv1 "github.com/obolnetwork/charon/core/corepb/v1" "github.com/obolnetwork/charon/p2p" @@ -21,11 +20,10 @@ import ( func TestSendReceive(t *testing.T) { var ( - pID = protocol.ID("delimited") - errNegative = errors.New("negative slot") - ctx = context.Background() - server = testutil.CreateHost(t, testutil.AvailableAddr(t)) - client = testutil.CreateHost(t, testutil.AvailableAddr(t)) + pID = protocol.ID("delimited") + ctx = context.Background() + server = testutil.CreateHost(t, testutil.AvailableAddr(t)) + client = testutil.CreateHost(t, testutil.AvailableAddr(t)) ) client.Peerstore().AddAddrs(server.ID(), server.Addrs(), peerstore.PermanentAddrTTL) @@ -43,9 +41,7 @@ func TestSendReceive(t *testing.T) { duty, ok := req.(*pbv1.Duty) require.True(t, ok) - if duty.Slot < 0 { - return nil, false, errNegative - } else if duty.Slot%2 == 0 { + if duty.Slot%2 == 0 { return duty, true, nil } else { return nil, false, nil diff --git a/p2p/sender_test.go b/p2p/sender_test.go index fd9ed9a2a..42a8902a8 100644 --- a/p2p/sender_test.go +++ b/p2p/sender_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" - "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" pbv1 "github.com/obolnetwork/charon/core/corepb/v1" "github.com/obolnetwork/charon/p2p" @@ -144,10 +143,9 @@ func testSend(t *testing.T, clientBasicProtoID, serverBasicProtoID, delimitedID t.Helper() var ( - errNegative = errors.New("negative slot") - ctx = context.Background() - server = testutil.CreateHost(t, testutil.AvailableAddr(t)) - client = testutil.CreateHost(t, testutil.AvailableAddr(t)) + ctx = context.Background() + server = testutil.CreateHost(t, testutil.AvailableAddr(t)) + client = testutil.CreateHost(t, testutil.AvailableAddr(t)) ) var serverOpt []p2p.SendRecvOption @@ -174,18 +172,12 @@ func testSend(t *testing.T, clientBasicProtoID, serverBasicProtoID, delimitedID log.Info(ctx, "See protocol logging field") require.Equal(t, client.ID(), peerID) - duty, ok := req.(*pbv1.Duty) - require.True(t, ok) var err error defer func() { serverErrChan <- err }() - if duty.Slot < 0 { - err = errNegative - } - return nil, false, err }, serverOpt..., diff --git a/testutil/validatormock/component.go b/testutil/validatormock/component.go index 0dcc1e572..19398fce0 100644 --- a/testutil/validatormock/component.go +++ b/testutil/validatormock/component.go @@ -152,7 +152,7 @@ func (m *Component) SlotTicked(ctx context.Context, slot core.Slot) error { return nil } - return m.scheduleSlot(ctx, metaSlot{Slot: uint64(slot.Slot), meta: m.meta}) + return m.scheduleSlot(ctx, metaSlot{Slot: slot.Slot, meta: m.meta}) } // delayOnStartup returns true if we need to omit performing duties in the upcoming slot. @@ -235,13 +235,13 @@ func (m *Component) runDuty(ctx context.Context, duty core.Duty) error { } metaSlot := metaSlot{ - Slot: uint64(duty.Slot), + Slot: duty.Slot, meta: m.meta, } epoch := metaSlot.Epoch().Epoch - attester := m.slotAttester(uint64(duty.Slot)) + attester := m.slotAttester(duty.Slot) syncComm := m.syncCommMember(epoch) eth2Slot := eth2p0.Slot(duty.Slot) From b9a8267be2c330d6018b44a85a339fe29c3d1993 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 31 Oct 2023 16:18:34 +0530 Subject: [PATCH 3/6] fix codeql error --- core/tracing.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/tracing.go b/core/tracing.go index fa7c34346..dbabb0490 100644 --- a/core/tracing.go +++ b/core/tracing.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "hash/fnv" + "math" "strings" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" @@ -29,7 +30,7 @@ func StartDutyTrace(ctx context.Context, duty Duty, spanName string, opts ...tra ctx, outerSpan = tracer.Start(tracer.RootedCtx(ctx, traceID), fmt.Sprintf("core/duty.%s", strings.Title(duty.Type.String()))) ctx, innerSpan = tracer.Start(ctx, spanName, opts...) - outerSpan.SetAttributes(attribute.Int64("slot", int64(duty.Slot))) + outerSpan.SetAttributes(attribute.Int64("slot", safeInt64(duty.Slot))) return ctx, withEndSpan{ Span: innerSpan, @@ -133,3 +134,13 @@ func WithTracing() WireOption { } } } + +// safeInt64 converts the provided uint64 value to an int64 integer. +// It panics if the provided value can't fit in an int64. +func safeInt64(value uint64) int64 { + if value <= math.MaxInt64 { + return int64(value) + } + + panic("integer overflow") +} From 6e2d47c1245c0dd761c1d7a7a685fbf94b748d5c Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 2 Nov 2023 22:46:57 +0530 Subject: [PATCH 4/6] edit comment in core proto --- core/corepb/v1/core.pb.go | 2 +- core/corepb/v1/core.proto | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/corepb/v1/core.pb.go b/core/corepb/v1/core.pb.go index a6f83a270..75c421d12 100644 --- a/core/corepb/v1/core.pb.go +++ b/core/corepb/v1/core.pb.go @@ -25,7 +25,7 @@ type Duty struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Slot uint64 `protobuf:"varint,1,opt,name=slot,proto3" json:"slot,omitempty"` // int64 + Slot uint64 `protobuf:"varint,1,opt,name=slot,proto3" json:"slot,omitempty"` // uint64 Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // core.DutyType } diff --git a/core/corepb/v1/core.proto b/core/corepb/v1/core.proto index 526faee3b..d588c527d 100644 --- a/core/corepb/v1/core.proto +++ b/core/corepb/v1/core.proto @@ -5,7 +5,7 @@ package core.corepb.v1; option go_package = "github.com/obolnetwork/charon/core/corepb/v1"; message Duty { // core.Duty - uint64 slot = 1; // int64 + uint64 slot = 1; // uint64 int32 type = 2; // core.DutyType } From d3eeb7122992407f101ad2dba2659703a94f5a22 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 3 Nov 2023 21:17:39 +0530 Subject: [PATCH 5/6] fix tests --- app/eth2wrap/success.go | 10 +++++----- app/eth2wrap/synthproposer.go | 28 ++++++++++++++-------------- app/eth2wrap/synthproposer_test.go | 10 +++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/eth2wrap/success.go b/app/eth2wrap/success.go index 5ac63e494..2ae99db75 100644 --- a/app/eth2wrap/success.go +++ b/app/eth2wrap/success.go @@ -3,17 +3,17 @@ package eth2wrap import ( - "github.com/attestantio/go-eth2-client/api" - apiv1 "github.com/attestantio/go-eth2-client/api/v1" - "github.com/attestantio/go-eth2-client/spec/phase0" + eth2api "github.com/attestantio/go-eth2-client/api" + eth2v1 "github.com/attestantio/go-eth2-client/api/v1" + eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" ) // isSyncStateOk returns true if the sync state is not syncing. -func isSyncStateOk(resp *api.Response[*apiv1.SyncState]) bool { +func isSyncStateOk(resp *eth2api.Response[*eth2v1.SyncState]) bool { return !resp.Data.IsSyncing } // isAggregateAttestationOk returns true if the aggregate attestation is not nil (which can happen if the subscription wasn't successful). -func isAggregateAttestationOk(resp *api.Response[*phase0.Attestation]) bool { +func isAggregateAttestationOk(resp *eth2api.Response[*eth2p0.Attestation]) bool { return resp.Data != nil } diff --git a/app/eth2wrap/synthproposer.go b/app/eth2wrap/synthproposer.go index 0c2788576..184b270c8 100644 --- a/app/eth2wrap/synthproposer.go +++ b/app/eth2wrap/synthproposer.go @@ -14,7 +14,7 @@ import ( eth2v1 "github.com/attestantio/go-eth2-client/api/v1" eth2bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix" eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella" - "github.com/attestantio/go-eth2-client/spec" + eth2spec "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/go-eth2-client/spec/capella" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" @@ -139,7 +139,7 @@ func (h *synthWrapper) BlindedProposal(ctx context.Context, opts *eth2api.Blinde // syntheticProposal returns a synthetic unsigned beacon block to propose. func (h *synthWrapper) syntheticProposal(ctx context.Context, slot eth2p0.Slot, vIdx eth2p0.ValidatorIndex) (*eth2api.VersionedProposal, error) { - var signedBlock *spec.VersionedSignedBeaconBlock + var signedBlock *eth2spec.VersionedSignedBeaconBlock // Work our way back from previous slot to find a proposal to base the synthetic proposal on. for prev := slot - 1; prev > 0; prev-- { @@ -168,24 +168,24 @@ func (h *synthWrapper) syntheticProposal(ctx context.Context, slot eth2p0.Slot, proposal := ð2api.VersionedProposal{Version: signedBlock.Version} switch signedBlock.Version { - case spec.DataVersionPhase0: + case eth2spec.DataVersionPhase0: proposal.Phase0 = signedBlock.Phase0.Message proposal.Phase0.Body.Graffiti = GetSyntheticGraffiti() proposal.Phase0.Slot = slot proposal.Phase0.ProposerIndex = vIdx - case spec.DataVersionAltair: + case eth2spec.DataVersionAltair: proposal.Altair = signedBlock.Altair.Message proposal.Altair.Body.Graffiti = GetSyntheticGraffiti() proposal.Altair.Slot = slot proposal.Altair.ProposerIndex = vIdx - case spec.DataVersionBellatrix: + case eth2spec.DataVersionBellatrix: proposal.Bellatrix = signedBlock.Bellatrix.Message proposal.Bellatrix.Body.Graffiti = GetSyntheticGraffiti() proposal.Bellatrix.Slot = slot proposal.Bellatrix.ProposerIndex = vIdx proposal.Bellatrix.Body.ExecutionPayload.FeeRecipient = feeRecipient proposal.Bellatrix.Body.ExecutionPayload.Transactions = fraction(proposal.Bellatrix.Body.ExecutionPayload.Transactions) - case spec.DataVersionCapella: + case eth2spec.DataVersionCapella: proposal.Capella = signedBlock.Capella.Message proposal.Capella.Body.Graffiti = GetSyntheticGraffiti() proposal.Capella.Slot = slot @@ -237,9 +237,9 @@ func GetSyntheticGraffiti() [32]byte { func IsSyntheticBlindedBlock(block *eth2api.VersionedSignedBlindedProposal) bool { var graffiti [32]byte switch block.Version { - case spec.DataVersionBellatrix: + case eth2spec.DataVersionBellatrix: graffiti = block.Bellatrix.Message.Body.Graffiti - case spec.DataVersionCapella: + case eth2spec.DataVersionCapella: graffiti = block.Capella.Message.Body.Graffiti default: return false @@ -252,13 +252,13 @@ func IsSyntheticBlindedBlock(block *eth2api.VersionedSignedBlindedProposal) bool func IsSyntheticProposal(block *eth2api.VersionedSignedProposal) bool { var graffiti [32]byte switch block.Version { - case spec.DataVersionPhase0: + case eth2spec.DataVersionPhase0: graffiti = block.Phase0.Message.Body.Graffiti - case spec.DataVersionAltair: + case eth2spec.DataVersionAltair: graffiti = block.Altair.Message.Body.Graffiti - case spec.DataVersionBellatrix: + case eth2spec.DataVersionBellatrix: graffiti = block.Bellatrix.Message.Body.Graffiti - case spec.DataVersionCapella: + case eth2spec.DataVersionCapella: graffiti = block.Capella.Message.Body.Graffiti default: return false @@ -436,7 +436,7 @@ func blindedProposal(proposal *eth2api.VersionedProposal) (*eth2api.VersionedBli var resp *eth2api.VersionedBlindedProposal // Blinded blocks are only available from bellatrix. switch proposal.Version { - case spec.DataVersionBellatrix: + case eth2spec.DataVersionBellatrix: resp = ð2api.VersionedBlindedProposal{ Version: proposal.Version, Bellatrix: ð2bellatrix.BlindedBeaconBlock{ @@ -473,7 +473,7 @@ func blindedProposal(proposal *eth2api.VersionedProposal) (*eth2api.VersionedBli }, }, } - case spec.DataVersionCapella: + case eth2spec.DataVersionCapella: resp = ð2api.VersionedBlindedProposal{ Version: proposal.Version, Capella: ð2capella.BlindedBeaconBlock{ diff --git a/app/eth2wrap/synthproposer_test.go b/app/eth2wrap/synthproposer_test.go index 63b75f7f0..e3bafeee2 100644 --- a/app/eth2wrap/synthproposer_test.go +++ b/app/eth2wrap/synthproposer_test.go @@ -9,7 +9,7 @@ import ( eth2api "github.com/attestantio/go-eth2-client/api" eth2v1 "github.com/attestantio/go-eth2-client/api/v1" eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella" - "github.com/attestantio/go-eth2-client/spec" + eth2spec "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/bellatrix" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/stretchr/testify/require" @@ -59,7 +59,7 @@ func TestSynthProposer(t *testing.T) { return cached(ctx) } signedBeaconBlock := bmock.SignedBeaconBlock - bmock.SignedBeaconBlockFunc = func(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error) { + bmock.SignedBeaconBlockFunc = func(ctx context.Context, blockID string) (*eth2spec.VersionedSignedBeaconBlock, error) { opts := ð2api.SignedBeaconBlockOpts{Block: blockID} resp, err := signedBeaconBlock(ctx, opts) if err != nil { @@ -120,7 +120,7 @@ func TestSynthProposer(t *testing.T) { continue } - require.Equal(t, spec.DataVersionCapella, block.Version) + require.Equal(t, eth2spec.DataVersionCapella, block.Version) signed := testutil.RandomVersionedSignedProposal() signed.Capella.Message = block.Capella @@ -146,10 +146,10 @@ func TestSynthProposer(t *testing.T) { } else { require.Equal(t, feeRecipient, block.Capella.Body.ExecutionPayloadHeader.FeeRecipient) } - require.Equal(t, spec.DataVersionCapella, block.Version) + require.Equal(t, eth2spec.DataVersionCapella, block.Version) signed := ð2api.VersionedSignedBlindedProposal{ - Version: spec.DataVersionCapella, + Version: eth2spec.DataVersionCapella, Capella: ð2capella.SignedBlindedBeaconBlock{ Message: block.Capella, Signature: testutil.RandomEth2Signature(), From 09a368cfdd5a9cbfb458b9efed065dd15b921ea5 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 3 Nov 2023 21:22:44 +0530 Subject: [PATCH 6/6] rebase --- core/tracker/inclusion.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tracker/inclusion.go b/core/tracker/inclusion.go index f71a09c1a..b20a71775 100644 --- a/core/tracker/inclusion.go +++ b/core/tracker/inclusion.go @@ -203,7 +203,7 @@ func (i *inclusionCore) CheckBlock(ctx context.Context, block block) { } log.Info(ctx, msg, - z.I64("block_slot", block.Slot), + z.U64("block_slot", block.Slot), z.Any("pubkey", sub.Pubkey), z.Any("broadcast_delay", sub.Delay), )