Skip to content

Commit dc78fa0

Browse files
fix: startup slot check for shreds
1 parent f9b6c03 commit dc78fa0

5 files changed

Lines changed: 31 additions & 35 deletions

File tree

src/api/atoms.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
ResetSlot,
4040
RepairSlot,
4141
LiveProgramCache,
42+
SlotCaughtUp,
4243
} from "./types";
4344
import { rafAtom } from "../atomUtils";
4445
import type { ValuesWithHistory } from "./worker/types";
@@ -88,6 +89,8 @@ export const repairSlotAtom = atom<RepairSlot | undefined>(undefined);
8889

8990
export const turbineSlotAtom = atom<TurbineSlot | undefined>(undefined);
9091

92+
export const slotCaughtUpAtom = atom<SlotCaughtUp | undefined>(undefined);
93+
9194
export const estimatedSlotDurationAtom = atom<
9295
EstimatedSlotDuration | undefined
9396
>(undefined);

src/api/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import type {
6666
supermajorityEpochSchema,
6767
peerUpdateInfoSchema,
6868
liveProgramCacheSchema,
69+
slotCaughtUpSchema,
6970
} from "./entities";
7071

7172
export type Client = z.infer<typeof clientSchema>;
@@ -95,6 +96,7 @@ export type OptimisticallyConfirmedSlot = z.infer<
9596
>;
9697

9798
export type CompletedSlot = z.infer<typeof completedSlotSchema>;
99+
98100
export type CatchUpHistory = z.infer<typeof catchUpHistorySchema>;
99101

100102
export type ServerTimeNanos = z.infer<typeof serverTimeNanosSchema>;
@@ -104,6 +106,8 @@ export type ResetSlot = z.infer<typeof resetSlotSchema>;
104106
export type StorageSlot = z.infer<typeof storageSlotSchema>;
105107
export type VoteSlot = z.infer<typeof voteSlotSchema>;
106108

109+
export type SlotCaughtUp = z.infer<typeof slotCaughtUpSchema>;
110+
107111
export type EstimatedSlotDuration = z.infer<typeof estimatedSlotDurationSchema>;
108112

109113
export type EstimatedTps = z.infer<typeof estimatedTpsSchema>;

src/api/useSetAtomWsData.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
rootSlotAtom,
8989
optimisticallyConfirmedSlotAtom,
9090
liveProgramCacheAtom,
91+
slotCaughtUpAtom,
9192
} from "./atoms";
9293
import {
9394
estimatedTpsDebounceMs,
@@ -427,6 +428,7 @@ function useUpdateAtoms() {
427428
const setOptimisticallyConfirmedSlot = useSetAtom(
428429
optimisticallyConfirmedSlotAtom,
429430
);
431+
const setSlotCaughtUp = useSetAtom(slotCaughtUpAtom);
430432

431433
const addLiveShreds = useSetAtom(shredsAtoms.addShredEvents);
432434

@@ -630,6 +632,9 @@ function useUpdateAtoms() {
630632
setOptimisticallyConfirmedSlot(value);
631633
break;
632634
}
635+
case "slot_caught_up":
636+
setSlotCaughtUp(value);
637+
break;
633638
case "catch_up_history": {
634639
addTurbineSlots(value.turbine);
635640
addRepairSlots(value.repair);
@@ -649,7 +654,6 @@ function useUpdateAtoms() {
649654
case "live_program_cache":
650655
setLiveProgramCache(value);
651656
break;
652-
case "slot_caught_up":
653657
case "estimated_slot":
654658
case "ping":
655659
case "vote_key":
@@ -788,6 +792,7 @@ function useUpdateAtoms() {
788792
setServerTimeNanos,
789793
setSkipRate,
790794
setSkippedSlots,
795+
setSlotCaughtUp,
791796
setSlotRankings,
792797
setSlotResponse,
793798
setStartupProgress,

src/features/Overview/ShredsProgression/atoms.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ShredEvent } from "../../../api/entities";
44
import { delayMs, xRangeMs } from "./const";
55
import { nsPerMs, slotsPerLeader } from "../../../consts";
66
import { getSlotGroupLeader } from "../../../utils";
7-
import { startupFinalTurbineHeadAtom } from "../../StartupProgress/atoms";
87
import { serverTimeMsAtom } from "../../../atoms";
8+
import { slotCaughtUpAtom } from "../../../api/atoms";
99

1010
type ShredEventTsDeltaMs = number | undefined;
1111
/**
@@ -44,14 +44,14 @@ export function createLiveShredsAtoms() {
4444
}>();
4545
const rangeAfterStartupAtom = atom((get) => {
4646
const range = get(_slotRangeAtom);
47-
const startupFinalTurbineHead = get(startupFinalTurbineHeadAtom);
48-
if (!range || startupFinalTurbineHead == null) return;
47+
const slotCaughtUp = get(slotCaughtUpAtom);
48+
if (!range || slotCaughtUp == null) return;
4949

50-
// no slots after final turbine head
51-
if (startupFinalTurbineHead + 1 > range.max) return;
50+
// no slots after startup
51+
if (slotCaughtUp + 1 > range.max) return;
5252

5353
return {
54-
min: Math.max(startupFinalTurbineHead + 1, range.min),
54+
min: Math.max(slotCaughtUp + 1, range.min),
5555
max: range.max,
5656
};
5757
});
@@ -62,16 +62,18 @@ export function createLiveShredsAtoms() {
6262
minCompletedSlot: atom((get) => get(_minCompletedSlotAtom)),
6363
range: atom((get) => get(_slotRangeAtom)),
6464
rangeAfterStartup: rangeAfterStartupAtom,
65-
// leader slots after turbine head at the end of startup
65+
/**
66+
* leader slots after startup, used for labels
67+
* */
6668
groupLeaderSlots: atom((get) => {
67-
const range = get(rangeAfterStartupAtom);
68-
const startupFinalTurbineHead = get(startupFinalTurbineHeadAtom);
69-
if (!range || startupFinalTurbineHead == null) return [];
70-
71-
const min = Math.max(startupFinalTurbineHead + 1, range.min);
72-
73-
const slots = [getSlotGroupLeader(min)];
74-
while (slots[slots.length - 1] + slotsPerLeader - 1 < range.max) {
69+
const rangeAfterStartup = get(rangeAfterStartupAtom);
70+
if (!rangeAfterStartup) return [];
71+
72+
const slots = [getSlotGroupLeader(rangeAfterStartup.min)];
73+
while (
74+
slots[slots.length - 1] + slotsPerLeader - 1 <
75+
rangeAfterStartup.max
76+
) {
7577
slots.push(
7678
getSlotGroupLeader(slots[slots.length - 1] + slotsPerLeader),
7779
);

src/features/StartupProgress/atoms.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { atom } from "jotai";
22
import { bootProgressAtom } from "../../api/atoms";
33
import { BootPhaseEnum } from "../../api/entities";
44
import type { BootPhase } from "../../api/types";
5-
import { latestTurbineSlotAtom } from "./Firedancer/CatchingUp/atoms";
65
import { isFrankendancer } from "../../client";
76

87
export const bootProgressPhaseAtom = atom(
@@ -91,24 +90,7 @@ export const bootProgressCompletedPhasesAtom = atom((get) => {
9190
return completed;
9291
});
9392

94-
export const [showStartupProgressAtom, startupFinalTurbineHeadAtom] =
95-
(function getShowStartupProgressAtom() {
96-
const _showStartupProgressAtom = atom(true);
97-
const _startupFinalTurbineHeadAtom = atom<number>();
98-
return [
99-
atom(
100-
(get) => get(_showStartupProgressAtom),
101-
(get, set, show: boolean) => {
102-
set(_showStartupProgressAtom, show);
103-
set(
104-
_startupFinalTurbineHeadAtom,
105-
show ? undefined : (get(latestTurbineSlotAtom) ?? -1),
106-
);
107-
},
108-
),
109-
atom((get) => get(_startupFinalTurbineHeadAtom)),
110-
];
111-
})();
93+
export const showStartupProgressAtom = atom(true);
11294

11395
export const isStartupProgressExpandedAtom = atom(true);
11496
export const expandStartupProgressElAtom = atom<HTMLButtonElement | null>(null);

0 commit comments

Comments
 (0)