Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update slot viz struct to new design #59

Merged
merged 8 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 25 additions & 20 deletions backend/pkg/api/types/slot_viz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion frontend/types/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends ClElUnion> {
el: T;
Expand Down
35 changes: 18 additions & 17 deletions frontend/types/api/slot_viz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends any> {
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<VDBSlotVizDuty>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Discord, please make all 4 properties (proposal, attestations, sync, slashing) optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sync: VDBSlotVizStatus<VDBSlotVizDuty>;
slashing: VDBSlotVizStatus<VDBSlotVizSlashing>;
}
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
}
Expand Down
20 changes: 19 additions & 1 deletion frontend/types/api/validator_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,30 @@ export interface VDBManageValidatorsTableRow {
export type InternalGetValidatorDashboardValidatorsResponse = ApiPagingResponse<VDBManageValidatorsTableRow>;
/**
* ------------------------------------------------------------
* 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 */;
name: string;
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;
};
}
Loading