Skip to content

Commit 7b92f53

Browse files
chore: use server time for shreds
1 parent a3b7e37 commit 7b92f53

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

src/api/atoms.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
GossipPeersSize,
3030
GossipPeersRowsUpdate,
3131
GossipPeersCellUpdate,
32+
ServerTimeNanos,
3233
} from "./types";
3334
import { rafAtom } from "../atomUtils";
3435

@@ -61,6 +62,7 @@ export const optimisticallyConfirmedSlotAtom = atom<
6162
>(undefined);
6263

6364
export const completedSlotAtom = atom<CompletedSlot | undefined>(undefined);
65+
export const serverTimeNanosAtom = atom<ServerTimeNanos | undefined>(undefined);
6466

6567
export const estimatedSlotAtom = atom<EstimatedSlot | undefined>(undefined);
6668

src/api/entities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export const catchUpHistorySchema = z.object({
121121
turbine: z.number().array(),
122122
});
123123

124+
export const serverTimeNanosSchema = z.coerce.number();
125+
124126
export const estimatedSlotSchema = z.number();
125127
export const resetSlotSchema = z.number().nullable();
126128
export const storageSlotSchema = z.number().nullable();
@@ -565,6 +567,10 @@ export const summarySchema = z.discriminatedUnion("key", [
565567
key: z.literal("catch_up_history"),
566568
value: catchUpHistorySchema,
567569
}),
570+
summaryTopicSchema.extend({
571+
key: z.literal("server_time_nanos"),
572+
value: serverTimeNanosSchema,
573+
}),
568574
]);
569575

570576
export const epochNewSchema = z.object({

src/api/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import type {
5757
gossipStorageStatsSchema,
5858
gossipMessageStatsSchema,
5959
schedulerCountsSchema,
60+
serverTimeNanosSchema,
6061
} from "./entities";
6162

6263
export type Client = z.infer<typeof clientSchema>;
@@ -94,6 +95,8 @@ export type OptimisticallyConfirmedSlot = z.infer<
9495
export type CompletedSlot = z.infer<typeof completedSlotSchema>;
9596
export type CatchUpHistory = z.infer<typeof catchUpHistorySchema>;
9697

98+
export type ServerTimeNanos = z.infer<typeof serverTimeNanosSchema>;
99+
97100
// export type SlotCompleted = z.infer<typeof slotCompletedSchema>;
98101

99102
export type EstimatedSlot = z.infer<typeof estimatedSlotSchema>;

src/api/useSetAtomWsData.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
gossipPeersSizeAtom,
2828
gossipPeersRowsUpdateAtom,
2929
gossipPeersCellUpdateAtom,
30+
serverTimeNanosAtom,
3031
} from "./atoms";
3132
import {
3233
blockEngineSchema,
@@ -196,6 +197,7 @@ export function useSetAtomWsData() {
196197
const setBlockEngine = useSetAtom(blockEngineAtom);
197198

198199
const setCompletedSlot = useSetAtom(completedSlotAtom);
200+
const setServerTimeNanos = useSetAtom(serverTimeNanosAtom);
199201

200202
const addSkippedClusterSlots = useSetAtom(addSkippedClusterSlotsAtom);
201203
const deleteSkippedClusterSlot = useSetAtom(deleteSkippedClusterSlotAtom);
@@ -383,6 +385,10 @@ export function useSetAtomWsData() {
383385
addRepairSlots(value.repair);
384386
break;
385387
}
388+
case "server_time_nanos": {
389+
setServerTimeNanos(value);
390+
break;
391+
}
386392
case "root_slot":
387393
case "optimistically_confirmed_slot":
388394
case "estimated_slot":

src/features/Overview/ShredsProgression/shredsProgressionPlugin.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { skippedClusterSlotsAtom } from "../../../atoms";
2222
import { clamp } from "lodash";
2323
import { ShredEvent } from "../../../api/entities";
2424
import { getSlotGroupLabelId, getSlotLabelId } from "./utils";
25-
import { slotsPerLeader } from "../../../consts";
25+
import { nsPerMs, slotsPerLeader } from "../../../consts";
26+
import { serverTimeNanosAtom } from "../../../api/atoms";
2627

2728
const store = getDefaultStore();
2829
export const shredsXScaleKey = "shredsXScaleKey";
@@ -55,10 +56,16 @@ export function shredsProgressionPlugin(
5556
const minCompletedSlot = store.get(atoms.minCompletedSlot);
5657
const skippedSlotsCluster = store.get(skippedClusterSlotsAtom);
5758
const rangeAfterStartup = store.get(atoms.rangeAfterStartup);
59+
const serverTimeNanos = store.get(serverTimeNanosAtom);
5860

5961
const maxX = u.scales[shredsXScaleKey].max;
6062

61-
if (!liveShreds || !slotRange || maxX == null) {
63+
if (
64+
!liveShreds ||
65+
!slotRange ||
66+
maxX == null ||
67+
serverTimeNanos == null
68+
) {
6269
return;
6370
}
6471

@@ -74,7 +81,7 @@ export function shredsProgressionPlugin(
7481
}
7582

7683
// Offset to convert shred event delta to chart x value
77-
const delayedNow = Date.now() - delayMs;
84+
const delayedNow = Math.trunc(serverTimeNanos / nsPerMs) - delayMs;
7885

7986
const tsXValueOffset = delayedNow - liveShreds.referenceTs;
8087

0 commit comments

Comments
 (0)