From e905186f18ecddeea0b4a975ac46f144fddc4257 Mon Sep 17 00:00:00 2001 From: LUCCA DUKIC <109136188+LuccaBitfly@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:16:25 +0100 Subject: [PATCH 1/7] update slot viz struct to new design --- backend/pkg/api/data_access/dummy.go | 13 +++---- backend/pkg/api/types/slot_viz.go | 45 +++++++++++++---------- frontend/types/api/common.ts | 2 +- frontend/types/api/slot_viz.ts | 35 +++++++++--------- frontend/types/api/validator_dashboard.ts | 20 +++++++++- 5 files changed, 68 insertions(+), 47 deletions(-) diff --git a/backend/pkg/api/data_access/dummy.go b/backend/pkg/api/data_access/dummy.go index 2e3a54e5f..964a1825b 100644 --- a/backend/pkg/api/data_access/dummy.go +++ b/backend/pkg/api/data_access/dummy.go @@ -158,14 +158,11 @@ func (d DummyService) RemoveValidatorDashboardPublicIdByPublicId(dashboardId t.V } func (d DummyService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrimary) ([]t.SlotVizEpoch, error) { - r := []t.SlotVizEpoch{} - var err error - for i := 0; i < 4; i++ { - epoch := t.SlotVizEpoch{} - err = commonFakeData(&epoch) - r = append(r, epoch) - } - return r, err + r := struct { + Epochs []t.SlotVizEpoch `faker:"slice_len=4"` + }{} + err := commonFakeData(&r) + return r.Epochs, err } func (d DummyService) GetValidatorDashboardSlotVizByPublicId(dashboardId t.VDBIdPublic) ([]t.SlotVizEpoch, error) { diff --git a/backend/pkg/api/types/slot_viz.go b/backend/pkg/api/types/slot_viz.go index 642c7bcc4..c0a084393 100644 --- a/backend/pkg/api/types/slot_viz.go +++ b/backend/pkg/api/types/slot_viz.go @@ -2,35 +2,40 @@ package types // ------------------------------------------------------------ // Slot Viz -type VDBSlotVizPassiveDuty struct { - PendingCount uint64 `json:"pending_count"` - SuccessCount uint64 `json:"success_count"` - FailedCount uint64 `json:"failed_count"` +type VDBSlotVizDuty struct { + TotalCount uint64 `json:"total_count"` + Validators []uint64 `json:"validators" faker:"slice_len=6"` // up to 6 validators that performed the duty, only for scheduled and failed } -type VDBSlotVizActiveDuty struct { - Status string `json:"status" tstype:"'success' | 'failed' | 'scheduled'" faker:"oneof: success, failed, scheduled"` - Validator uint64 `json:"validator"` - // If the duty is a proposal & it's successful, the duty_object is the proposed block - // If the duty is a proposal & it failed/scheduled, the duty_object is the slot - // If the duty is a slashing & it's successful, the duty_object is the validator you slashed - // If the duty is a slashing & it failed, the duty_object is your validator that was slashed +type VDBSlotVizTuple struct { + Validator uint64 `json:"validator"` DutyObject uint64 `json:"duty_object"` } +type VDBSlotVizSlashing struct { + TotalCount uint64 `json:"total_count"` + Slashings []VDBSlotVizTuple `json:"slashings" faker:"slice_len=6"` // up to 6 slashings, validator is always the slashing validator +} + +type VDBSlotVizStatus[T any] struct { + Success T `json:"success,omitempty"` + Failed T `json:"failed,omitempty"` + Scheduled T `json:"scheduled,omitempty"` +} + type VDBSlotVizSlot struct { - Slot uint64 `json:"slot"` - Status string `json:"status" tstype:"'proposed' | 'missed' | 'scheduled' | 'orphaned'" faker:"oneof: proposed, missed, scheduled, orphaned"` - Attestations *VDBSlotVizPassiveDuty `json:"attestations,omitempty"` - Sync *VDBSlotVizPassiveDuty `json:"sync,omitempty"` - Proposal *VDBSlotVizActiveDuty `json:"proposal,omitempty"` - Slashing []VDBSlotVizActiveDuty `json:"slashing,omitempty"` + Slot uint64 `json:"slot"` + Status string `json:"status" tstype:"'proposed' | 'missed' | 'scheduled' | 'orphaned'" faker:"oneof: proposed, missed, scheduled, orphaned"` + Proposal *VDBSlotVizTuple `json:"proposal,omitempty"` + Attestations VDBSlotVizStatus[VDBSlotVizDuty] `json:"attestations"` + Sync VDBSlotVizStatus[VDBSlotVizDuty] `json:"sync"` + Slashing VDBSlotVizStatus[VDBSlotVizSlashing] `json:"slashing"` } type SlotVizEpoch struct { Epoch uint64 `json:"epoch"` - State string `json:"state,omitempty" tstype:"'scheduled' | 'head' | 'justifying' | 'justified' | 'finalized'" faker:"oneof: scheduled, head, justifying, justified, finalized"` - Progress float64 `json:"progress,omitempty"` // only on landing page - Slots []VDBSlotVizSlot `json:"slots,omitempty" faker:"slice_len=32"` // only on dashboard page + State string `json:"state,omitempty" tstype:"'scheduled' | 'head' | 'justifying' | 'justified' | 'finalized'" faker:"oneof: scheduled, head, justifying, justified, finalized"` // only on landing page + Progress float64 `json:"progress,omitempty"` // only on landing page + Slots []VDBSlotVizSlot `json:"slots,omitempty" faker:"slice_len=32"` // only on dashboard page } type InternalGetValidatorDashboardSlotVizResponse ApiDataResponse[[]SlotVizEpoch] diff --git a/frontend/types/api/common.ts b/frontend/types/api/common.ts index a1f4f34de..2c4517eb0 100644 --- a/frontend/types/api/common.ts +++ b/frontend/types/api/common.ts @@ -42,7 +42,7 @@ export interface StatusCount { success: number /* uint64 */; failed: number /* uint64 */; } -export type ClElUnion = +export type ClElUnion = number /* float64 */ | string /* decimal.Decimal */; export interface ClElValue { el: T; diff --git a/frontend/types/api/slot_viz.ts b/frontend/types/api/slot_viz.ts index 07d5e7276..773c38d3d 100644 --- a/frontend/types/api/slot_viz.ts +++ b/frontend/types/api/slot_viz.ts @@ -9,33 +9,34 @@ import type { ApiDataResponse } from './common' * ------------------------------------------------------------ * Slot Viz */ -export interface VDBSlotVizPassiveDuty { - pending_count: number /* uint64 */; - success_count: number /* uint64 */; - failed_count: number /* uint64 */; +export interface VDBSlotVizDuty { + total_count: number /* uint64 */; + validators: number /* uint64 */[]; // up to 6 validators that performed the duty, only for scheduled and failed } -export interface VDBSlotVizActiveDuty { - status: 'success' | 'failed' | 'scheduled'; +export interface VDBSlotVizTuple { validator: number /* uint64 */; - /** - * If the duty is a proposal & it's successful, the duty_object is the proposed block - * If the duty is a proposal & it failed/scheduled, the duty_object is the slot - * If the duty is a slashing & it's successful, the duty_object is the validator you slashed - * If the duty is a slashing & it failed, the duty_object is your validator that was slashed - */ duty_object: number /* uint64 */; } +export interface VDBSlotVizSlashing { + total_count: number /* uint64 */; + slashings: VDBSlotVizTuple[]; // up to 6 slashings, validator is always the slashing validator +} +export interface VDBSlotVizStatus { + success?: T; + failed?: T; + scheduled?: T; +} export interface VDBSlotVizSlot { slot: number /* uint64 */; status: 'proposed' | 'missed' | 'scheduled' | 'orphaned'; - attestations?: VDBSlotVizPassiveDuty; - sync?: VDBSlotVizPassiveDuty; - proposal?: VDBSlotVizActiveDuty; - slashing?: VDBSlotVizActiveDuty[]; + proposal?: VDBSlotVizTuple; + attestations: VDBSlotVizStatus; + sync: VDBSlotVizStatus; + slashing: VDBSlotVizStatus; } export interface SlotVizEpoch { epoch: number /* uint64 */; - state?: 'scheduled' | 'head' | 'justifying' | 'justified' | 'finalized' ; // only on landing page + state?: 'scheduled' | 'head' | 'justifying' | 'justified' | 'finalized'; // only on landing page progress?: number /* float64 */; // only on landing page slots?: VDBSlotVizSlot[]; // only on dashboard page } diff --git a/frontend/types/api/validator_dashboard.ts b/frontend/types/api/validator_dashboard.ts index 993f27f1c..1d98a7f47 100644 --- a/frontend/types/api/validator_dashboard.ts +++ b/frontend/types/api/validator_dashboard.ts @@ -223,8 +223,15 @@ export interface VDBManageValidatorsTableRow { export type InternalGetValidatorDashboardValidatorsResponse = ApiPagingResponse; /** * ------------------------------------------------------------ - * Misc. Responses + * Misc. */ +export type VDBIdPrimary = number /* int */; +export type VDBIdPublic = string; +export type VDBIdValidatorSet = VDBValidator[]; +export interface VDBValidator { + index: number /* uint64 */; + version: number /* uint64 */; +} export interface VDBPostReturnData { id: number /* uint64 */; user_id: number /* uint64 */; @@ -232,3 +239,14 @@ export interface VDBPostReturnData { network: number /* uint64 */; created_at: string /* time.Time */; } +export interface VDBPostValidatorsData { + public_key: string; + group_id: number /* uint64 */; +} +export interface VDBPostPublicIdData { + public_id: string; + name: string; + share_settings: { + group_names: boolean; + }; +} From fab9bace3a2a984d68abe48dfbac3c5388bcb431 Mon Sep 17 00:00:00 2001 From: LUCCA DUKIC <109136188+LuccaBitfly@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:18:21 +0100 Subject: [PATCH 2/7] change slot viz struct --- backend/pkg/api/types/slot_viz.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/pkg/api/types/slot_viz.go b/backend/pkg/api/types/slot_viz.go index c0a084393..2ee712053 100644 --- a/backend/pkg/api/types/slot_viz.go +++ b/backend/pkg/api/types/slot_viz.go @@ -18,9 +18,9 @@ type VDBSlotVizSlashing struct { } type VDBSlotVizStatus[T any] struct { - Success T `json:"success,omitempty"` - Failed T `json:"failed,omitempty"` - Scheduled T `json:"scheduled,omitempty"` + Success *T `json:"success,omitempty"` + Failed *T `json:"failed,omitempty"` + Scheduled *T `json:"scheduled,omitempty"` } type VDBSlotVizSlot struct { From c0eb8871f34d35708c2f45dd7f2626a7c8c382ef Mon Sep 17 00:00:00 2001 From: LUCCA DUKIC <109136188+LuccaBitfly@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:06:11 +0100 Subject: [PATCH 3/7] slot viz: make attstations, sync and slashing optional --- backend/pkg/api/types/slot_viz.go | 12 ++++++------ frontend/types/api/slot_viz.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/pkg/api/types/slot_viz.go b/backend/pkg/api/types/slot_viz.go index 2ee712053..a23d8c117 100644 --- a/backend/pkg/api/types/slot_viz.go +++ b/backend/pkg/api/types/slot_viz.go @@ -24,12 +24,12 @@ type VDBSlotVizStatus[T any] struct { } type VDBSlotVizSlot struct { - Slot uint64 `json:"slot"` - Status string `json:"status" tstype:"'proposed' | 'missed' | 'scheduled' | 'orphaned'" faker:"oneof: proposed, missed, scheduled, orphaned"` - Proposal *VDBSlotVizTuple `json:"proposal,omitempty"` - Attestations VDBSlotVizStatus[VDBSlotVizDuty] `json:"attestations"` - Sync VDBSlotVizStatus[VDBSlotVizDuty] `json:"sync"` - Slashing VDBSlotVizStatus[VDBSlotVizSlashing] `json:"slashing"` + Slot uint64 `json:"slot"` + Status string `json:"status" tstype:"'proposed' | 'missed' | 'scheduled' | 'orphaned'" faker:"oneof: proposed, missed, scheduled, orphaned"` + Proposal *VDBSlotVizTuple `json:"proposal,omitempty"` + Attestations *VDBSlotVizStatus[VDBSlotVizDuty] `json:"attestations,omitempty"` + Sync *VDBSlotVizStatus[VDBSlotVizDuty] `json:"sync,omitempty"` + Slashing *VDBSlotVizStatus[VDBSlotVizSlashing] `json:"slashing,omitempty"` } type SlotVizEpoch struct { Epoch uint64 `json:"epoch"` diff --git a/frontend/types/api/slot_viz.ts b/frontend/types/api/slot_viz.ts index 773c38d3d..42396a85d 100644 --- a/frontend/types/api/slot_viz.ts +++ b/frontend/types/api/slot_viz.ts @@ -30,9 +30,9 @@ export interface VDBSlotVizSlot { slot: number /* uint64 */; status: 'proposed' | 'missed' | 'scheduled' | 'orphaned'; proposal?: VDBSlotVizTuple; - attestations: VDBSlotVizStatus; - sync: VDBSlotVizStatus; - slashing: VDBSlotVizStatus; + attestations?: VDBSlotVizStatus; + sync?: VDBSlotVizStatus; + slashing?: VDBSlotVizStatus; } export interface SlotVizEpoch { epoch: number /* uint64 */; From 69239cd981c75714c40044ff57e7e3dd9eaef38a Mon Sep 17 00:00:00 2001 From: Stefan Pletka Date: Tue, 5 Mar 2024 14:28:52 +0100 Subject: [PATCH 4/7] Adjust slotViz method to new structure --- backend/pkg/api/data_access/data_access.go | 104 ++++++++++++++------- backend/pkg/api/types/slot_viz.go | 10 +- 2 files changed, 79 insertions(+), 35 deletions(-) diff --git a/backend/pkg/api/data_access/data_access.go b/backend/pkg/api/data_access/data_access.go index 6aefe27cc..28789a5a7 100644 --- a/backend/pkg/api/data_access/data_access.go +++ b/backend/pkg/api/data_access/data_access.go @@ -454,22 +454,15 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima if proposerIndex, ok := dutiesInfo.PropAssignmentsForSlot[slot]; ok { // Only add results for validators we care about if _, ok := validatorsMap[uint32(proposerIndex)]; ok { - slotVizEpochs[epochIdx].Slots[slotIdx].Proposal = &t.VDBSlotVizActiveDuty{} + slotVizEpochs[epochIdx].Slots[slotIdx].Proposal = &t.VDBSlotVizTuple{} slotVizEpochs[epochIdx].Slots[slotIdx].Proposal.Validator = dutiesInfo.PropAssignmentsForSlot[slot] - - status := "scheduled" dutyObject := slot if _, ok := dutiesInfo.SlotStatus[slot]; ok { - switch dutiesInfo.SlotStatus[slot] { - case 0, 2: - status = "failed" - case 1, 3: - status = "success" + if dutiesInfo.SlotStatus[slot] == 1 || dutiesInfo.SlotStatus[slot] == 3 { dutyObject = dutiesInfo.SlotBlock[slot] } } - slotVizEpochs[epochIdx].Slots[slotIdx].Proposal.Status = status slotVizEpochs[epochIdx].Slots[slotIdx].Proposal.DutyObject = dutyObject } } @@ -482,16 +475,29 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima continue } - if slotVizEpochs[epochIdx].Slots[slotIdx].Sync == nil { - slotVizEpochs[epochIdx].Slots[slotIdx].Sync = &t.VDBSlotVizPassiveDuty{} + if slotVizEpochs[epochIdx].Slots[slotIdx].Syncs == nil { + slotVizEpochs[epochIdx].Slots[slotIdx].Syncs = &t.VDBSlotVizStatus[t.VDBSlotVizDuty]{} } + syncsRef := slotVizEpochs[epochIdx].Slots[slotIdx].Syncs if slot > dutiesInfo.LatestSlot { - slotVizEpochs[epochIdx].Slots[slotIdx].Sync.PendingCount++ + if syncsRef.Scheduled == nil { + syncsRef.Scheduled = &t.VDBSlotVizDuty{} + } + syncsRef.Scheduled.TotalCount++ + syncsRef.Scheduled.Validators = append(syncsRef.Scheduled.Validators, validator) } else if _, ok := dutiesInfo.SlotSyncParticipated[slot][validator]; ok { - slotVizEpochs[epochIdx].Slots[slotIdx].Sync.SuccessCount++ + if syncsRef.Success == nil { + syncsRef.Success = &t.VDBSlotVizDuty{} + } + syncsRef.Success.TotalCount++ + syncsRef.Success.Validators = append(syncsRef.Success.Validators, validator) } else { - slotVizEpochs[epochIdx].Slots[slotIdx].Sync.FailedCount++ + if syncsRef.Failed == nil { + syncsRef.Failed = &t.VDBSlotVizDuty{} + } + syncsRef.Failed.TotalCount++ + syncsRef.Failed.Validators = append(syncsRef.Failed.Validators, validator) } } } @@ -505,12 +511,22 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima if _, ok := validatorsMap[uint32(proposerIndex)]; ok { // One of the dashboard validators slashed for _, validator := range slashedValidators { - slotVizEpochs[epochIdx].Slots[slotIdx].Slashing = append(slotVizEpochs[epochIdx].Slots[slotIdx].Slashing, - t.VDBSlotVizActiveDuty{ - Status: "success", - Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Dashboard validator - DutyObject: validator, // Validator that got slashed - }) + if slotVizEpochs[epochIdx].Slots[slotIdx].Slashings == nil { + slotVizEpochs[epochIdx].Slots[slotIdx].Slashings = &t.VDBSlotVizStatus[t.VDBSlotVizSlashing]{} + } + slashingsRef := slotVizEpochs[epochIdx].Slots[slotIdx].Slashings + + if slashingsRef.Success == nil { + slashingsRef.Success = &t.VDBSlotVizSlashing{} + } + + slashingsRef.Success.TotalCount++ + + slashing := t.VDBSlotVizTuple{ + Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator + DutyObject: validator, // Slashed validator + } + slashingsRef.Success.Slashings = append(slashingsRef.Success.Slashings, slashing) } } } @@ -519,19 +535,29 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima continue } // One of the dashboard validators got slashed - slotVizEpochs[epochIdx].Slots[slotIdx].Slashing = append(slotVizEpochs[epochIdx].Slots[slotIdx].Slashing, - t.VDBSlotVizActiveDuty{ - Status: "failed", - Validator: validator, // Dashboard validator - DutyObject: validator, // Validator that got slashed - }) + if slotVizEpochs[epochIdx].Slots[slotIdx].Slashings == nil { + slotVizEpochs[epochIdx].Slots[slotIdx].Slashings = &t.VDBSlotVizStatus[t.VDBSlotVizSlashing]{} + } + slashingsRef := slotVizEpochs[epochIdx].Slots[slotIdx].Slashings + + if slashingsRef.Failed == nil { + slashingsRef.Failed = &t.VDBSlotVizSlashing{} + } + + slashingsRef.Failed.TotalCount++ + + slashing := t.VDBSlotVizTuple{ + Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator + DutyObject: validator, // Slashed validator + } + slashingsRef.Failed.Slashings = append(slashingsRef.Failed.Slashings, slashing) } } } // Hydrate the attestation data - for validator := range validatorsArray { - for slot, duty := range dutiesInfo.EpochAttestationDuties[uint32(validator)] { + for _, validator := range validatorsArray { + for slot, duty := range dutiesInfo.EpochAttestationDuties[validator] { epoch := utils.EpochOfSlot(uint64(slot)) epochIdx, ok := epochToIndexMap[epoch] if !ok { @@ -543,14 +569,28 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima } if slotVizEpochs[epochIdx].Slots[slotIdx].Attestations == nil { - slotVizEpochs[epochIdx].Slots[slotIdx].Attestations = &t.VDBSlotVizPassiveDuty{} + slotVizEpochs[epochIdx].Slots[slotIdx].Attestations = &t.VDBSlotVizStatus[t.VDBSlotVizDuty]{} } + attestationsRef := slotVizEpochs[epochIdx].Slots[slotIdx].Attestations + if uint64(slot) >= dutiesInfo.LatestSlot { - slotVizEpochs[epochIdx].Slots[slotIdx].Attestations.PendingCount++ + if attestationsRef.Scheduled == nil { + attestationsRef.Scheduled = &t.VDBSlotVizDuty{} + } + attestationsRef.Scheduled.TotalCount++ + attestationsRef.Scheduled.Validators = append(attestationsRef.Scheduled.Validators, uint64(validator)) } else if duty { - slotVizEpochs[epochIdx].Slots[slotIdx].Attestations.SuccessCount++ + if attestationsRef.Success == nil { + attestationsRef.Success = &t.VDBSlotVizDuty{} + } + attestationsRef.Success.TotalCount++ + attestationsRef.Success.Validators = append(attestationsRef.Success.Validators, uint64(validator)) } else { - slotVizEpochs[epochIdx].Slots[slotIdx].Attestations.FailedCount++ + if attestationsRef.Failed == nil { + attestationsRef.Failed = &t.VDBSlotVizDuty{} + } + attestationsRef.Failed.TotalCount++ + attestationsRef.Failed.Validators = append(attestationsRef.Failed.Validators, uint64(validator)) } } } diff --git a/backend/pkg/api/types/slot_viz.go b/backend/pkg/api/types/slot_viz.go index a23d8c117..25cddc333 100644 --- a/backend/pkg/api/types/slot_viz.go +++ b/backend/pkg/api/types/slot_viz.go @@ -8,7 +8,11 @@ type VDBSlotVizDuty struct { } type VDBSlotVizTuple struct { - Validator uint64 `json:"validator"` + Validator uint64 `json:"validator"` + // If the duty is a proposal & it's successful, the duty_object is the proposed block + // If the duty is a proposal & it failed/scheduled, the duty_object is the slot + // If the duty is a slashing & it's successful, the duty_object is the validator you slashed + // If the duty is a slashing & it failed, the duty_object is your validator that was slashed DutyObject uint64 `json:"duty_object"` } @@ -28,8 +32,8 @@ type VDBSlotVizSlot struct { Status string `json:"status" tstype:"'proposed' | 'missed' | 'scheduled' | 'orphaned'" faker:"oneof: proposed, missed, scheduled, orphaned"` Proposal *VDBSlotVizTuple `json:"proposal,omitempty"` Attestations *VDBSlotVizStatus[VDBSlotVizDuty] `json:"attestations,omitempty"` - Sync *VDBSlotVizStatus[VDBSlotVizDuty] `json:"sync,omitempty"` - Slashing *VDBSlotVizStatus[VDBSlotVizSlashing] `json:"slashing,omitempty"` + Syncs *VDBSlotVizStatus[VDBSlotVizDuty] `json:"sync,omitempty"` + Slashings *VDBSlotVizStatus[VDBSlotVizSlashing] `json:"slashing,omitempty"` } type SlotVizEpoch struct { Epoch uint64 `json:"epoch"` From 4475a388e6370268f12217268384a2c7825036d8 Mon Sep 17 00:00:00 2001 From: Manuel <5877862+manuelsc@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:39:55 +0100 Subject: [PATCH 5/7] handle headepoch+1 not yet in redis --- backend/pkg/api/services/service_slot_viz.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/pkg/api/services/service_slot_viz.go b/backend/pkg/api/services/service_slot_viz.go index d2e39fe9a..fc8bd3b33 100644 --- a/backend/pkg/api/services/service_slot_viz.go +++ b/backend/pkg/api/services/service_slot_viz.go @@ -100,7 +100,11 @@ func updateSlotVizData() error { encodedRedisCachedEpochAssignments, err := db.PersistentRedisDbClient.Get(ctx, key).Result() if err != nil { - return errors.Wrap(err, "error getting epoch assignments data") + if epoch == headEpoch+1 { + log.Infof("headEpoch + 1 assignments not yet available, epoch %d", epoch) + return nil + } + return errors.Wrap(err, fmt.Sprintf("error getting epoch assignments data for epoch %d", epoch)) } var serializedAssignmentsData bytes.Buffer From 987358f2538a7a489c02a803514cd39c96a45f4c Mon Sep 17 00:00:00 2001 From: Stefan Pletka Date: Tue, 5 Mar 2024 17:02:45 +0100 Subject: [PATCH 6/7] Set maxValidatorsInResponse --- backend/pkg/api/data_access/data_access.go | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/pkg/api/data_access/data_access.go b/backend/pkg/api/data_access/data_access.go index 28789a5a7..2c0742890 100644 --- a/backend/pkg/api/data_access/data_access.go +++ b/backend/pkg/api/data_access/data_access.go @@ -407,6 +407,8 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima minEpoch := headEpoch - 2 maxEpoch := headEpoch + 1 + maxValidatorsInResponse := 6 + dutiesInfo, releaseLock, err := services.GetCurrentDutiesInfo() defer releaseLock() // important to unlock once done, otherwise data updater cant update the data if err != nil { @@ -485,19 +487,22 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima syncsRef.Scheduled = &t.VDBSlotVizDuty{} } syncsRef.Scheduled.TotalCount++ - syncsRef.Scheduled.Validators = append(syncsRef.Scheduled.Validators, validator) + if len(syncsRef.Scheduled.Validators) < maxValidatorsInResponse { + syncsRef.Scheduled.Validators = append(syncsRef.Scheduled.Validators, validator) + } } else if _, ok := dutiesInfo.SlotSyncParticipated[slot][validator]; ok { if syncsRef.Success == nil { syncsRef.Success = &t.VDBSlotVizDuty{} } syncsRef.Success.TotalCount++ - syncsRef.Success.Validators = append(syncsRef.Success.Validators, validator) } else { if syncsRef.Failed == nil { syncsRef.Failed = &t.VDBSlotVizDuty{} } syncsRef.Failed.TotalCount++ - syncsRef.Failed.Validators = append(syncsRef.Failed.Validators, validator) + if len(syncsRef.Failed.Validators) < maxValidatorsInResponse { + syncsRef.Failed.Validators = append(syncsRef.Failed.Validators, validator) + } } } } @@ -526,7 +531,9 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator DutyObject: validator, // Slashed validator } - slashingsRef.Success.Slashings = append(slashingsRef.Success.Slashings, slashing) + if len(slashingsRef.Success.Slashings) < maxValidatorsInResponse { + slashingsRef.Success.Slashings = append(slashingsRef.Success.Slashings, slashing) + } } } } @@ -550,7 +557,9 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator DutyObject: validator, // Slashed validator } - slashingsRef.Failed.Slashings = append(slashingsRef.Failed.Slashings, slashing) + if len(slashingsRef.Failed.Slashings) < maxValidatorsInResponse { + slashingsRef.Failed.Slashings = append(slashingsRef.Failed.Slashings, slashing) + } } } } @@ -578,19 +587,22 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima attestationsRef.Scheduled = &t.VDBSlotVizDuty{} } attestationsRef.Scheduled.TotalCount++ - attestationsRef.Scheduled.Validators = append(attestationsRef.Scheduled.Validators, uint64(validator)) + if len(attestationsRef.Scheduled.Validators) < maxValidatorsInResponse { + attestationsRef.Scheduled.Validators = append(attestationsRef.Scheduled.Validators, uint64(validator)) + } } else if duty { if attestationsRef.Success == nil { attestationsRef.Success = &t.VDBSlotVizDuty{} } attestationsRef.Success.TotalCount++ - attestationsRef.Success.Validators = append(attestationsRef.Success.Validators, uint64(validator)) } else { if attestationsRef.Failed == nil { attestationsRef.Failed = &t.VDBSlotVizDuty{} } attestationsRef.Failed.TotalCount++ - attestationsRef.Failed.Validators = append(attestationsRef.Failed.Validators, uint64(validator)) + if len(attestationsRef.Failed.Validators) < maxValidatorsInResponse { + attestationsRef.Failed.Validators = append(attestationsRef.Failed.Validators, uint64(validator)) + } } } } From 456683fcab65329e2a173439ebd7629669910884 Mon Sep 17 00:00:00 2001 From: Stefan Pletka Date: Tue, 5 Mar 2024 17:07:39 +0100 Subject: [PATCH 7/7] Moved conditions up a bit --- backend/pkg/api/data_access/data_access.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/pkg/api/data_access/data_access.go b/backend/pkg/api/data_access/data_access.go index 2c0742890..b6be06d13 100644 --- a/backend/pkg/api/data_access/data_access.go +++ b/backend/pkg/api/data_access/data_access.go @@ -527,11 +527,11 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima slashingsRef.Success.TotalCount++ - slashing := t.VDBSlotVizTuple{ - Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator - DutyObject: validator, // Slashed validator - } if len(slashingsRef.Success.Slashings) < maxValidatorsInResponse { + slashing := t.VDBSlotVizTuple{ + Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator + DutyObject: validator, // Slashed validator + } slashingsRef.Success.Slashings = append(slashingsRef.Success.Slashings, slashing) } } @@ -553,11 +553,11 @@ func (d DataAccessService) GetValidatorDashboardSlotViz(dashboardId t.VDBIdPrima slashingsRef.Failed.TotalCount++ - slashing := t.VDBSlotVizTuple{ - Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator - DutyObject: validator, // Slashed validator - } if len(slashingsRef.Failed.Slashings) < maxValidatorsInResponse { + slashing := t.VDBSlotVizTuple{ + Validator: dutiesInfo.PropAssignmentsForSlot[slot], // Slashing validator + DutyObject: validator, // Slashed validator + } slashingsRef.Failed.Slashings = append(slashingsRef.Failed.Slashings, slashing) } }