Skip to content

Commit b53bfd4

Browse files
committed
Cleanup remaining todos and unused code
1 parent cf0069d commit b53bfd4

File tree

5 files changed

+32
-62
lines changed

5 files changed

+32
-62
lines changed

ui/src/components/Sim/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export interface ITransactionSent {
8484
recipient: string;
8585
}
8686

87-
8887
export interface IRankingBlockGenerated {
8988
type: EServerMessageType.RBGenerated;
9089
id: string;
@@ -133,7 +132,6 @@ export interface ITransaction {
133132
id: string;
134133
}
135134

136-
137135
export interface IEndorserBlock {
138136
id: string;
139137
}
@@ -198,7 +196,6 @@ export type TServerMessageType =
198196
| ITransactionSent
199197
| IUnknown;
200198

201-
// TODO: should rename ServerMessage -> ServerMessage
202199
export interface IServerMessage<T = TServerMessageType> {
203200
time_s: number;
204201
message: T;

ui/src/contexts/SimContext/context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from "./types";
88

99
export const defaultAggregatedData: ISimulationAggregatedDataState = {
10-
progress: 0,
1110
nodes: new Map(),
1211
global: {
1312
praosTxOnChain: 0,

ui/src/contexts/SimContext/reducer.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { defaultAggregatedData } from "./context";
22
import { ISimContextState, TSimContextActions } from "./types";
3-
import { computeAggregatedDataAtTime, clearLatencyCache } from "@/utils/timelineAggregation";
3+
import {
4+
computeAggregatedDataAtTime,
5+
clearLatencyCache,
6+
} from "@/utils/timelineAggregation";
47

58
export const reducer = (
69
state: ISimContextState,
@@ -46,7 +49,6 @@ export const reducer = (
4649
};
4750
}
4851

49-
5052
case "SET_CURRENT_NODE": {
5153
return {
5254
...state,
@@ -57,8 +59,6 @@ export const reducer = (
5759
};
5860
}
5961

60-
61-
6262
case "SET_CANVAS_PROPS": {
6363
return {
6464
...state,
@@ -80,13 +80,6 @@ export const reducer = (
8080
};
8181
}
8282

83-
case "SET_SPEED": {
84-
return {
85-
...state,
86-
speedMultiplier: action.payload.speedMultiplier,
87-
};
88-
}
89-
9083
case "BATCH_UPDATE": {
9184
return {
9285
...state,
@@ -114,12 +107,6 @@ export const reducer = (
114107
topologyLoaded: true,
115108
};
116109

117-
case "ADD_TIMELINE_EVENT":
118-
return {
119-
...state,
120-
events: [...state.events, action.payload],
121-
};
122-
123110
case "ADD_TIMELINE_EVENT_BATCH":
124111
return {
125112
...state,
@@ -164,7 +151,6 @@ export const reducer = (
164151
speedMultiplier: action.payload,
165152
};
166153

167-
168154
case "RESET_TIMELINE":
169155
return {
170156
...state,

ui/src/contexts/SimContext/types.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { IServerMessage, ITransformedNodeMap } from "@/components/Sim/types";
22
import { Dispatch, RefObject } from "react";
33

4-
// TODO: unused
5-
export enum ESpeedOptions {
6-
"1% Speed" = 0.01,
7-
"3% Speed" = 0.03,
8-
"10% Speed" = 0.1,
9-
}
10-
114
// Types of messages submitted between nodes
125
export enum EMessageType {
136
EB = "eb",
@@ -51,7 +44,6 @@ export interface IMessageAnimation {
5144
}
5245

5346
export interface ISimulationAggregatedDataState {
54-
progress: number; // TODO: unused
5547
nodes: Map<string, ISimulationAggregatedData>;
5648
global: ISimulationGlobalData;
5749
lastNodesUpdated: string[];
@@ -98,12 +90,6 @@ export type TSimContextActions =
9890
| { type: "SET_SCENARIOS"; payload: IScenario[] }
9991
| { type: "SET_SCENARIO"; payload: string }
10092
| { type: "SET_CURRENT_NODE"; payload: string | undefined }
101-
| {
102-
type: "SET_SPEED";
103-
payload: {
104-
speedMultiplier: number;
105-
};
106-
}
10793
| {
10894
type: "SET_CANVAS_PROPS";
10995
payload: Partial<{
@@ -112,26 +98,13 @@ export type TSimContextActions =
11298
canvasOffsetY: ((prev: number) => number) | number;
11399
}>;
114100
}
115-
| {
116-
type: "BATCH_UPDATE";
117-
payload: Partial<ISimContextState>;
118-
}
101+
| { type: "BATCH_UPDATE"; payload: Partial<ISimContextState> }
119102
| { type: "RESET_TOPOLOGY"; payload: string }
120103
| {
121104
type: "SET_TOPOLOGY";
122-
payload: {
123-
topologyPath: string;
124-
topology: ITransformedNodeMap;
125-
};
126-
}
127-
| {
128-
type: "ADD_TIMELINE_EVENT";
129-
payload: IServerMessage;
130-
}
131-
| {
132-
type: "ADD_TIMELINE_EVENT_BATCH";
133-
payload: IServerMessage[];
105+
payload: { topologyPath: string; topology: ITransformedNodeMap };
134106
}
107+
| { type: "ADD_TIMELINE_EVENT_BATCH"; payload: IServerMessage[] }
135108
| { type: "SET_TIMELINE_TIME"; payload: number }
136109
| { type: "SET_TIMELINE_PLAYING"; payload: boolean }
137110
| { type: "SET_TIMELINE_SPEED"; payload: number }

ui/src/utils/timelineAggregation.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,26 @@ export const computeAggregatedDataAtTime = (
132132
const messageBytes = new Map<EMessageType, Map<string, number>>();
133133

134134
// Helper functions for efficient byte storage/retrieval
135-
const setMessageBytes = (messageType: EMessageType, messageId: string, size: number) => {
135+
const setMessageBytes = (
136+
messageType: EMessageType,
137+
messageId: string,
138+
size: number,
139+
) => {
136140
if (!messageBytes.has(messageType)) {
137141
messageBytes.set(messageType, new Map());
138142
}
139143
messageBytes.get(messageType)!.set(messageId, size);
140144
};
141145

142-
const getMessageBytes = (messageType: EMessageType, messageId: string): number => {
146+
const getMessageBytes = (
147+
messageType: EMessageType,
148+
messageId: string,
149+
): number => {
143150
return messageBytes.get(messageType)?.get(messageId) || 0;
144151
};
145152

146153
// Initialize result structure
147154
const result: ISimulationAggregatedDataState = {
148-
progress: targetTime,
149155
nodes: nodeStats,
150156
global: {
151157
praosTxOnChain: 0,
@@ -182,7 +188,10 @@ export const computeAggregatedDataAtTime = (
182188
case EServerMessageType.TransactionGenerated: {
183189
const stats = nodeStats.get(message.publisher);
184190
if (stats) {
185-
stats.generated.set(EMessageType.TX, (stats.generated.get(EMessageType.TX) || 0) + 1);
191+
stats.generated.set(
192+
EMessageType.TX,
193+
(stats.generated.get(EMessageType.TX) || 0) + 1,
194+
);
186195
setMessageBytes(EMessageType.TX, message.id, message.size_bytes);
187196
}
188197
break;
@@ -231,13 +240,13 @@ export const computeAggregatedDataAtTime = (
231240
break;
232241
}
233242

234-
235-
236-
237243
case EServerMessageType.EBGenerated: {
238244
const stats = nodeStats.get(message.producer);
239245
if (stats) {
240-
stats.generated.set(EMessageType.EB, (stats.generated.get(EMessageType.EB) || 0) + 1);
246+
stats.generated.set(
247+
EMessageType.EB,
248+
(stats.generated.get(EMessageType.EB) || 0) + 1,
249+
);
241250
setMessageBytes(EMessageType.EB, message.id, message.size_bytes);
242251
}
243252

@@ -316,7 +325,10 @@ export const computeAggregatedDataAtTime = (
316325
case EServerMessageType.RBGenerated: {
317326
const stats = nodeStats.get(message.producer);
318327
if (stats) {
319-
stats.generated.set(EMessageType.RB, (stats.generated.get(EMessageType.RB) || 0) + 1);
328+
stats.generated.set(
329+
EMessageType.RB,
330+
(stats.generated.get(EMessageType.RB) || 0) + 1,
331+
);
320332
setMessageBytes(EMessageType.RB, message.id, message.size_bytes);
321333
}
322334

@@ -396,7 +408,10 @@ export const computeAggregatedDataAtTime = (
396408
case EServerMessageType.VTBundleGenerated: {
397409
const stats = nodeStats.get(message.producer);
398410
if (stats) {
399-
stats.generated.set(EMessageType.Votes, (stats.generated.get(EMessageType.Votes) || 0) + 1);
411+
stats.generated.set(
412+
EMessageType.Votes,
413+
(stats.generated.get(EMessageType.Votes) || 0) + 1,
414+
);
400415
setMessageBytes(EMessageType.Votes, message.id, message.size_bytes);
401416
}
402417
break;

0 commit comments

Comments
 (0)