Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/api/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
RepairSlot,
LiveProgramCache,
SlotCaughtUp,
AccountsStats,
} from "./types";
import { rafAtom } from "../atomUtils";
import type { ValuesWithHistory } from "./worker/types";
Expand Down Expand Up @@ -191,3 +192,5 @@ export const slotRankingsAtom = atom<SlotRankings | undefined>(undefined);
export const liveProgramCacheAtom = atom<LiveProgramCache | undefined>(
undefined,
);

export const accountsStatsAtom = rafAtom<AccountsStats | undefined>(undefined);
137 changes: 137 additions & 0 deletions src/api/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const supermajorityTopicSchema = z.object({
topic: z.literal("wait_for_supermajority"),
});

const accountsTopicSchema = z.object({
topic: z.literal("accounts"),
});

export const topicSchema = z.discriminatedUnion("topic", [
summaryTopicSchema,
epochTopicSchema,
Expand All @@ -39,6 +43,7 @@ export const topicSchema = z.discriminatedUnion("topic", [
slotTopicSchema,
blockEngineTopicSchema,
supermajorityTopicSchema,
accountsTopicSchema,
]);

export const versionSchema = z.string();
Expand Down Expand Up @@ -988,3 +993,135 @@ export const supermajoritySchema = z.discriminatedUnion("key", [
value: supermajorityPeerRemoveSchema,
}),
]);

export const accountsDiskSchema = z.object({
accounts_total: z.number(),
accounts_capacity: z.number(),
allocated_bytes: z.number(),
current_bytes: z.number(),
used_bytes: z.number(),
});

export const accountsCompactionSchema = z.object({
in_compaction: z.number(),
compactions_requested: z.number(),
compactions_completed: z.number(),
accounts_relocated_bytes: z.number(),
relocated_bytes_per_sec: z.number(),
});

export const accountsCacheClassSchema = z.object({
class: z.number(),
used_slots: z.number(),
max_slots: z.number(),
reserved_slots: z.number(),
target_used_slots: z.number(),
low_water_used_slots: z.number(),
not_found: z.number(),
evicted: z.number(),
preevicted: z.number(),
committed_new: z.number(),
committed_overwrite: z.number(),
not_found_per_sec: z.number(),
evicted_per_sec: z.number(),
preevicted_per_sec: z.number(),
committed_new_per_sec: z.number(),
committed_overwrite_per_sec: z.number(),
reads_per_sec: z.number(),
writes_per_sec: z.number(),
hit_rate_ema: z.number(),
});

export const accountsCacheSchema = z.object({
hit_rate_ema: z.number(),
size_bytes: z.number(),
classes: accountsCacheClassSchema.array(),
});

export const accountsIoSchema = z.object({
acquired: z.number(),
acquired_writable: z.number(),
bytes_read: z.number(),
bytes_copied: z.number(),
bytes_written: z.number(),
bytes_written_accdb: z.number(),
read_ops: z.number(),
write_ops: z.number(),
acquired_per_sec: z.number(),
acquired_writable_per_sec: z.number(),
bytes_read_per_sec: z.number(),
bytes_copied_per_sec: z.number(),
bytes_written_per_sec: z.number(),
read_ops_per_sec: z.number(),
write_ops_per_sec: z.number(),
prewrite_ratio: z.number(),
});

export const accountsPartitionSchema = z.object({
partition_idx: z.number(),
file_offset: z.number(),
tier: z.number(),
write_offset: z.number(),
bytes_freed: z.number(),
read_ops: z.number(),
bytes_read: z.number(),
write_ops: z.number(),
bytes_written: z.number(),
read_ops_per_sec: z.number(),
bytes_read_per_sec: z.number(),
write_ops_per_sec: z.number(),
bytes_written_per_sec: z.number(),
utilization: z.number(),
fragmentation: z.number(),
used_frac: z.number(),
fragmented_frac: z.number(),
compaction_trigger_frac: z.number(),
age_seconds: z.number(),
filled_seconds: z.number(),
/* 0 = idle, 1 = queued, 2 = compacting */
compaction_state: z.number(),
compaction_frac: z.number(),
is_write_head: z.boolean(),
});

export const accountsTileSchema = z.object({
name: z.string(),
kind_id: z.number(),
joiner_type: z.enum(["RO", "RW"]),
/* 1 = running, 2 = shutdown */
status: z.number(),
acquired: z.number(),
bytes_read: z.number(),
bytes_written: z.number(),
acquired_per_sec: z.number(),
acquired_writable_per_sec: z.number(),
bytes_read_per_sec: z.number(),
bytes_copied_per_sec: z.number(),
bytes_written_per_sec: z.number(),
read_ops_per_sec: z.number(),
write_ops_per_sec: z.number(),
not_found_per_sec: z.number(),
evicted_per_sec: z.number(),
committed_per_sec: z.number(),
acquire_calls_per_sec: z.number(),
hit_rate_ema: z.number(),
acquired_history: z.array(z.number()),
acquired_writable_history: z.array(z.number()),
});

export const accountsStatsSchema = z.object({
sample_time_nanos: z.number(),
disk: accountsDiskSchema,
compaction: accountsCompactionSchema,
cache: accountsCacheSchema,
io: accountsIoSchema,
tiles: accountsTileSchema.array(),
partitions: accountsPartitionSchema.array(),
});

export const accountsSchema = z.discriminatedUnion("key", [
accountsTopicSchema.extend({
key: z.literal("stats"),
value: accountsStatsSchema,
}),
]);
9 changes: 9 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ import type {
peerUpdateInfoSchema,
liveProgramCacheSchema,
slotCaughtUpSchema,
accountsStatsSchema,
accountsPartitionSchema,
accountsTileSchema,
} from "./entities";

export type Client = z.infer<typeof clientSchema>;
Expand Down Expand Up @@ -191,3 +194,9 @@ export type SlotRankings = z.infer<typeof slotRankingsSchema>;
export type LiveShreds = z.infer<typeof liveShredsSchema>;

export type LiveProgramCache = z.infer<typeof liveProgramCacheSchema>;

export type AccountsStats = z.infer<typeof accountsStatsSchema>;

export type AccountsPartition = z.infer<typeof accountsPartitionSchema>;

export type AccountsTile = z.infer<typeof accountsTileSchema>;
12 changes: 12 additions & 0 deletions src/api/useSetAtomWsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
optimisticallyConfirmedSlotAtom,
liveProgramCacheAtom,
slotCaughtUpAtom,
accountsStatsAtom,
} from "./atoms";
import {
estimatedTpsDebounceMs,
Expand Down Expand Up @@ -433,6 +434,7 @@ function useUpdateAtoms() {
const addLiveShreds = useSetAtom(shredsAtoms.addShredEvents);

const setLiveProgramCache = useSetAtom(liveProgramCacheAtom);
const setAccountsStats = useSetAtom(accountsStatsAtom);

const peersBuffer = useRef(new Map<string, Peer>());
const removePeersBuffer = useRef(new Map<string, PeerRemove>());
Expand Down Expand Up @@ -752,6 +754,15 @@ function useUpdateAtoms() {
}
break;
}
case "accounts": {
switch (key) {
case "stats": {
setAccountsStats(value);
break;
}
}
break;
}
}
},
[
Expand Down Expand Up @@ -784,6 +795,7 @@ function useUpdateAtoms() {
setIdentityBalance,
setIdentityKey,
setLateVoteHistory,
setAccountsStats,
setLiveProgramCache,
setOptimisticallyConfirmedSlot,
setResetSlot,
Expand Down
5 changes: 4 additions & 1 deletion src/api/worker/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import z from "zod";
import {
accountsSchema,
blockEngineSchema,
epochSchema,
gossipSchema,
Expand All @@ -18,6 +19,7 @@ export const WsMessageSchema = z.discriminatedUnion("topic", [
slotSchema,
blockEngineSchema,
supermajoritySchema,
accountsSchema,
]);

export type WsMessage = z.infer<typeof WsMessageSchema>;
Expand All @@ -41,7 +43,8 @@ export type WsEntity =
| KvFrom<typeof peersSchema, "peers">
| KvFrom<typeof slotSchema, "slot">
| KvFrom<typeof blockEngineSchema, "block_engine">
| KvFrom<typeof supermajoritySchema, "wait_for_supermajority">;
| KvFrom<typeof supermajoritySchema, "wait_for_supermajority">
| KvFrom<typeof accountsSchema, "accounts">;

export type FromWorkerMessage =
| { type: "connecting" }
Expand Down
Loading
Loading