Skip to content

Commit 8ede260

Browse files
committed
viz: show TX throughput
1 parent 245ac25 commit 8ede260

File tree

10 files changed

+90
-35
lines changed

10 files changed

+90
-35
lines changed

ui/src/app/api/messages/batch/route.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NextResponse } from "next/server";
33
import readline from "readline";
44

55
import { EMessageType, IServerMessage } from "@/components/Graph/types";
6-
import { ISimulationAggregatedDataState } from "@/contexts/GraphContext/types";
6+
import { ISimulationAggregatedDataState, ISimulationIntermediateDataState } from "@/contexts/GraphContext/types";
77
import { messagesPath } from "../../utils";
88
import { processMessage } from "./utils";
99

@@ -97,8 +97,16 @@ export async function GET(req: Request, res: Response) {
9797
const aggregatedData: ISimulationAggregatedDataState = {
9898
progress: 0,
9999
nodes: new Map(),
100+
global: {
101+
praosTxOnChain: 0,
102+
leiosTxOnChain: 0,
103+
},
100104
lastNodesUpdated: [],
101105
};
106+
const intermediate: ISimulationIntermediateDataState = {
107+
txsPerIb: new Map(),
108+
txsPerEb: new Map(),
109+
};
102110

103111
interval = setInterval(() => {
104112
if (isProcessing) {
@@ -145,7 +153,7 @@ export async function GET(req: Request, res: Response) {
145153
nodesUpdated.add(data.message.sender.toString())
146154
}
147155

148-
processMessage(data, aggregatedData);
156+
processMessage(data, aggregatedData, intermediate);
149157
}
150158

151159
const serializedData = {
@@ -167,7 +175,7 @@ export async function GET(req: Request, res: Response) {
167175
if (!line) {
168176
return;
169177
}
170-
178+
171179
eventBuffer.push(line);
172180
});
173181

ui/src/app/api/messages/batch/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import readline from "readline";
55
import {
66
ISimulationAggregatedData,
77
ISimulationAggregatedDataState,
8+
ISimulationIntermediateDataState,
89
} from "@/contexts/GraphContext/types";
910

1011
export const incrementNodeAggregationData = (
@@ -37,6 +38,7 @@ export const incrementNodeAggregationData = (
3738
export const processMessage = (
3839
json: IServerMessage,
3940
aggregatedData: ISimulationAggregatedDataState,
41+
intermediate: ISimulationIntermediateDataState,
4042
) => {
4143
const { message } = json;
4244

@@ -64,6 +66,7 @@ export const processMessage = (
6466
message.producer.toString(),
6567
"ibGenerated",
6668
);
69+
intermediate.txsPerIb.set(message.id, message.transactions.length);
6770
} else if (message.type === EMessageType.InputBlockSent) {
6871
incrementNodeAggregationData(
6972
aggregatedData.nodes,
@@ -82,6 +85,11 @@ export const processMessage = (
8285
message.producer.toString(),
8386
"pbGenerated",
8487
);
88+
aggregatedData.global.praosTxOnChain += message.transactions.length;
89+
if (message.endorsement != null) {
90+
let eb = message.endorsement.eb.id;
91+
aggregatedData.global.leiosTxOnChain += intermediate.txsPerEb.get(eb) ?? 0;
92+
}
8593
} else if (message.type === EMessageType.PraosBlockSent) {
8694
incrementNodeAggregationData(
8795
aggregatedData.nodes,
@@ -100,6 +108,10 @@ export const processMessage = (
100108
message.producer.toString(),
101109
"ebGenerated",
102110
);
111+
const txs = message.input_blocks
112+
.map(ib => intermediate.txsPerIb.get(ib.id) ?? 0)
113+
.reduce((p, c) => p + c, 0);
114+
intermediate.txsPerEb.set(message.id, txs);
103115
} else if (message.type === EMessageType.EndorserBlockSent) {
104116
incrementNodeAggregationData(
105117
aggregatedData.nodes,

ui/src/components/Graph/modules/Controls.tsx

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ export const Controls: FC = memo(() => {
1010
const { startStream, streaming, stopStream } = useStreamMessagesHandler();
1111

1212
const handleCancelSim = useCallback(() => {
13-
() => {
14-
stopStream();
15-
dispatch({
16-
type: "BATCH_UPDATE",
17-
payload: {
18-
currentNode: undefined,
19-
aggregatedData: defaultAggregatedData,
20-
},
21-
});
22-
}
13+
stopStream();
14+
dispatch({
15+
type: "BATCH_UPDATE",
16+
payload: {
17+
currentNode: undefined,
18+
aggregatedData: defaultAggregatedData,
19+
},
20+
});
2321
}, [stopStream, dispatch])
2422

2523
return (

ui/src/components/Graph/modules/NodeStats.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,41 @@ export const NodeStats: FC = () => {
2424
const { left, top } = useMemo(() => {
2525
const margin = 10;
2626
const elementRect = ref.current?.getBoundingClientRect();
27-
27+
2828
if (!elementRect) {
2929
return { left: 0, top: 0 };
3030
}
31-
31+
3232
const fx = currentNodeData?.fx ?? 0;
3333
const fy = currentNodeData?.fy ?? 0;
34-
34+
3535
// Convert node position to canvas pixel space
3636
const nodeCanvasX = fx * canvasScale + canvasOffsetX;
3737
const nodeCanvasY = fy * canvasScale + canvasOffsetY;
38-
38+
3939
// Start by placing the box with bottom-left corner at the node's position
4040
let calculatedLeft = nodeCanvasX + margin;
4141
let calculatedTop = nodeCanvasY - margin - elementRect.height;
42-
42+
4343
// If the box goes off the top of the screen, place it below the node
4444
if (calculatedTop < 0) {
4545
calculatedTop = nodeCanvasY - margin;
4646
}
47-
47+
4848
// If the box goes off the right side of the screen, place it to the left of the node
4949
if (calculatedLeft + elementRect.width > screen.width) {
5050
calculatedLeft = nodeCanvasX - elementRect.width - margin;
5151
} else if (calculatedLeft < 0) {
5252
// If it goes off the left side, adjust to the right again
5353
calculatedLeft = nodeCanvasX - margin;
5454
}
55-
55+
5656
return {
5757
left: calculatedLeft,
5858
top: calculatedTop,
5959
};
6060
}, [currentNodeData, canvasScale, canvasOffsetX, canvasOffsetY]);
61-
61+
6262
return (
6363
<div
6464
ref={ref}

ui/src/components/Graph/modules/Slider.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ export const Progress: FC = () => {
88

99
const percent = (aggregatedData.progress / maxTime) * 100;
1010

11+
const minutes = Math.floor(aggregatedData.progress / 60_000);
12+
const seconds = (aggregatedData.progress / 1000 % 60).toFixed(3);
13+
const time = minutes ? `${minutes}m${seconds}s` : `${seconds}s`;
14+
1115
return (
1216
<div className="w-full mx-auto px-4 flex flex-col items-between justify-center">
1317
<p className="mb-0">
14-
Time in ms: {aggregatedData.progress}<br/>
18+
Time: {time}<br />
1519
</p>
16-
20+
1721
<div
1822
className="relative w-full mt-2"
1923
>

ui/src/components/Graph/modules/Stats.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const Stats: FC = () => {
5353
txPropagations: 0,
5454
votesGenerated: 0,
5555
votesPropagations: 0,
56+
...aggregatedData.global,
5657
} as ISimulationAggregatedTotalData,
5758
);
5859

@@ -66,10 +67,13 @@ export const Stats: FC = () => {
6667
<h4 className="flex items-center justify-between gap-4">IB Propagations: <span>{totals.ibPropagations}</span></h4>
6768
<h4 className="flex items-center justify-between gap-4">EB Generated: <span>{totals.ebGenerated}</span></h4>
6869
<h4 className="flex items-center justify-between gap-4">EB Propagations: <span>{totals.ebPropagations}</span></h4>
69-
<h4 className="flex items-center justify-between gap-4">PB Generated: <span>{totals.pbGenerated}</span></h4>
70-
<h4 className="flex items-center justify-between gap-4">PB Propagations: <span>{totals.pbPropagations}</span></h4>
71-
<h4 className="flex items-center justify-between gap-4">Votes Generated: <span>{totals.votesGenerated}</span></h4>
72-
<h4 className="flex items-center justify-between gap-4">Votes Propagations: <span>{totals.votesPropagations}</span></h4>
70+
<h4 className="flex items-center justify-between gap-4">Blocks Generated: <span>{totals.pbGenerated}</span></h4>
71+
<h4 className="flex items-center justify-between gap-4">Block Propagations: <span>{totals.pbPropagations}</span></h4>
72+
<h4 className="flex items-center justify-between gap-4">Vote Bundles Generated: <span>{totals.votesGenerated}</span></h4>
73+
<h4 className="flex items-center justify-between gap-4">Vote Bundle Propagations: <span>{totals.votesPropagations}</span></h4>
74+
<br />
75+
<h4 className="flex items-center justify-between gap-4">Transactions On-Chain Directly<span>{totals.praosTxOnChain}</span></h4>
76+
<h4 className="flex items-center justify-between gap-4">Transactions On-Chain from Leios<span>{totals.leiosTxOnChain}</span></h4>
7377
</div>
7478
</div>
7579
);

ui/src/components/Graph/types.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ export interface IPraosBlockGenerated {
128128
id: string;
129129
slot: number;
130130
producer: number;
131+
endorsement: IEndorsement | null;
132+
transactions: number[];
133+
}
134+
135+
export interface IEndorsement {
136+
eb: { id: string }
131137
}
132138

133139
export interface IPraosBlockReceived {
@@ -151,7 +157,11 @@ export interface IEndorserBlockGenerated {
151157
id: string;
152158
slot: number;
153159
producer: number;
154-
blocks: any[] // @todo
160+
input_blocks: IInputBlock[] // @todo
161+
}
162+
163+
export interface IInputBlock {
164+
id: string;
155165
}
156166

157167
export interface IEndorserBlockReceived {

ui/src/contexts/GraphContext/GraphContextProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const GraphContextProvider: FC<
5050
}, []);
5151

5252
const [state, dispatch] = useReducer(reducer, defaultSyncedState);
53-
53+
5454
const canvasRef = useRef<HTMLCanvasElement>(defaultState.canvasRef.current);
5555
const resolvedState = useMemo(
5656
() => ({

ui/src/contexts/GraphContext/context.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { IGraphContext, IGraphContextState, ISimulationAggregatedDataState } fro
66
export const defaultAggregatedData: ISimulationAggregatedDataState = {
77
progress: 0,
88
nodes: new Map(),
9+
global: {
10+
praosTxOnChain: 0,
11+
leiosTxOnChain: 0,
12+
},
913
lastNodesUpdated: []
1014
};
1115

@@ -23,6 +27,6 @@ export const defaultState: IGraphContextState = {
2327

2428
export const GraphContext: Context<IGraphContext> = createContext({
2529
state: defaultState,
26-
dispatch: (_val) => {}
30+
dispatch: (_val) => { }
2731
});
2832
export const useGraphContext = () => useContext(GraphContext);

ui/src/contexts/GraphContext/types.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface ISimulationAggregatedTotalData {
2020
pbPropagations: number;
2121
votesGenerated: number;
2222
votesPropagations: number;
23+
praosTxOnChain: number;
24+
leiosTxOnChain: number;
2325
}
2426

2527
export interface ISimulationAggregatedData {
@@ -40,12 +42,23 @@ export interface ISimulationAggregatedData {
4042
votesSent: number;
4143
}
4244

45+
export interface ISimulationGlobalData {
46+
praosTxOnChain: number;
47+
leiosTxOnChain: number;
48+
}
49+
4350
export interface ISimulationAggregatedDataState {
4451
progress: number;
4552
nodes: Map<string, ISimulationAggregatedData>;
53+
global: ISimulationGlobalData;
4654
lastNodesUpdated: string[];
4755
}
4856

57+
export interface ISimulationIntermediateDataState {
58+
txsPerIb: Map<string, number>;
59+
txsPerEb: Map<string, number>;
60+
}
61+
4962
export interface IGraphContextState {
5063
canvasRef: RefObject<HTMLCanvasElement>;
5164
canvasScale: number;
@@ -62,11 +75,13 @@ export interface IGraphContextState {
6275
export type TGraphContextActions =
6376
| { type: "SET_CURRENT_NODE"; payload: string | undefined }
6477
| { type: "SET_BATCH_SIZE"; payload: number }
65-
| { type: "SET_CANVAS_PROPS"; payload: Partial<{
66-
canvasScale: ((prev: number) => number) | number,
67-
canvasOffsetX: ((prev: number) => number) | number,
68-
canvasOffsetY: ((prev: number) => number) | number
69-
}> }
78+
| {
79+
type: "SET_CANVAS_PROPS"; payload: Partial<{
80+
canvasScale: ((prev: number) => number) | number,
81+
canvasOffsetX: ((prev: number) => number) | number,
82+
canvasOffsetY: ((prev: number) => number) | number
83+
}>
84+
}
7085
| { type: "SET_AGGREGATED_DATA"; payload: ISimulationAggregatedDataState }
7186
| {
7287
type: "BATCH_UPDATE";

0 commit comments

Comments
 (0)