Skip to content

Commit

Permalink
refactor: change luck time fields to uint64
Browse files Browse the repository at this point in the history
See: BEDS-892
  • Loading branch information
LuccaBitfly committed Oct 30, 2024
1 parent 4ee4bbc commit f692daa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
8 changes: 4 additions & 4 deletions backend/pkg/api/data_access/vdb_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,9 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
ret.Luck.Proposal.Percent = (float64(totalProposals)) / totalBlockChance * 100

// calculate the average time it takes for the set of validators to propose a single block on average
ret.Luck.Proposal.Average = time.Duration((luckHours / totalBlockChance) * float64(time.Hour))
ret.Luck.Proposal.AverageIntervalSeconds = uint64(time.Duration((luckHours / totalBlockChance) * float64(time.Hour)).Seconds())

ret.Luck.Proposal.Expected = lastBlockTs.Add(ret.Luck.Proposal.Average)
ret.Luck.Proposal.ExpectedTimestamp = uint64(lastBlockTs.Unix()) + ret.Luck.Proposal.AverageIntervalSeconds
} else {
ret.Luck.Proposal.Percent = 0
}
Expand All @@ -784,9 +784,9 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
ret.Luck.Sync.Percent = syncCommittees / totalSyncExpected * 100

// calculate the average time it takes for the set of validators to be elected into a sync committee on average
ret.Luck.Sync.Average = time.Duration((luckHours / totalSyncExpected) * float64(time.Hour))
ret.Luck.Sync.AverageIntervalSeconds = uint64(time.Duration((luckHours / totalSyncExpected) * float64(time.Hour)).Seconds())

ret.Luck.Sync.Expected = lastSyncTs.Add(ret.Luck.Sync.Average)
ret.Luck.Sync.ExpectedTimestamp = uint64(lastSyncTs.Unix()) + ret.Luck.Sync.AverageIntervalSeconds
}

if totalInclusionDelayDivisor > 0 {
Expand Down
8 changes: 3 additions & 5 deletions backend/pkg/api/types/common.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"time"

"github.com/shopspring/decimal"
)

Expand Down Expand Up @@ -41,9 +39,9 @@ type Address struct {
}

type LuckItem struct {
Percent float64 `json:"percent"`
Expected time.Time `json:"expected" swaggertype:"string" format:"date-time"`
Average time.Duration `json:"average" swaggertype:"primitive,integer"`
Percent float64 `json:"percent"`
ExpectedTimestamp uint64 `json:"expected_timestamp"`
AverageIntervalSeconds uint64 `json:"average_interval_seconds"`
}

type Luck struct {
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/dashboard/table/SummaryValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ const openValidatorModal = () => {
<b> {{ $t("common.average") }}: </b>
{{
$t("common.every_x", {
duration: formatNanoSecondDuration(
data.luck.proposal.average,
duration: formatTimeDuration(
data.luck.proposal.average_interval_seconds,
$t,
),
})
Expand All @@ -362,7 +362,7 @@ const openValidatorModal = () => {
<b> {{ $t("common.average") }}: </b>
{{
$t("common.every_x", {
duration: formatNanoSecondDuration(data.luck.sync.average, $t),
duration: formatTimeDuration(data.luck.sync.average_interval_seconds, $t),
})
}}
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/types/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export interface Address {
}
export interface LuckItem {
percent: number /* float64 */;
expected: string /* time.Time */;
average: any /* time.Duration */;
expected_timestamp: number /* uint64 */;
average_interval_seconds: number /* uint64 */;
}
export interface Luck {
proposal: LuckItem;
Expand Down
11 changes: 0 additions & 11 deletions frontend/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,6 @@ export function formatTimeDuration(
return t(translationId, { amount }, amount === 1 ? 1 : 2)
}

export function formatNanoSecondDuration(
nano: number | undefined,
t: ComposerTranslation,
): string | undefined {
if (nano === undefined) {
return undefined
}
const seconds = Math.floor(nano / 1000000000)
return formatTimeDuration(seconds, t)
}

export function formatFiat(
value: number,
currency: string,
Expand Down

0 comments on commit f692daa

Please sign in to comment.