Skip to content

Commit bc02a54

Browse files
committed
Parse EBReceived events
1 parent f923bef commit bc02a54

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

ui/src/components/Sim/hooks/useLokiWebSocket.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
IRankingBlockSent,
66
IRankingBlockReceived,
77
IEndorserBlockSent,
8+
IEndorserBlockReceived,
89
} from "@/components/Sim/types";
910
import { useRef } from "react";
1011

@@ -209,6 +210,53 @@ const parseEndorserBlockSent = (
209210
return null;
210211
};
211212

213+
const parseEndorserBlockReceived = (
214+
streamLabels: any,
215+
timestamp: number,
216+
logLine: string,
217+
): IServerMessage | null => {
218+
try {
219+
const log = JSON.parse(logLine);
220+
221+
// From cardano-node ns=LeiosFetch.Remote.Receive.Block
222+
// {"mux_at":"2025-12-05T12:45:21.98320066Z","peer":{"connectionId":"127.0.0.1:3003 127.0.0.1:3002"},"kind":"Recv","msg":{"kind":"MsgLeiosBlock","eb":"\u003celided\u003e","ebBytesSize":27471}}
223+
if (log.kind === "Recv" && log.msg && log.msg.kind === "MsgLeiosBlock") {
224+
const recipient = streamLabels.process;
225+
const connectionId = log.peer?.connectionId;
226+
let sender = "Node0";
227+
228+
if (connectionId) {
229+
const endpoints = connectionId.split(" ");
230+
if (endpoints.length === 2) {
231+
const senderEndpoint = endpoints[1];
232+
sender = HOST_PORT_TO_NODE[senderEndpoint] || sender;
233+
}
234+
}
235+
236+
const message: IEndorserBlockReceived = {
237+
type: EServerMessageType.EBReceived,
238+
slot: 0, // FIXME: use correct slot
239+
id: `eb-${log.msg.eb}`, // FIXME: msg.eb is always elided
240+
sender,
241+
recipient,
242+
};
243+
244+
return {
245+
time_s: timestamp,
246+
message,
247+
};
248+
}
249+
} catch (error) {
250+
console.warn(
251+
"Failed to parse EndorserBlockReceived log line:",
252+
logLine,
253+
error,
254+
);
255+
}
256+
257+
return null;
258+
};
259+
212260
function connectLokiWebSocket(lokiHost: string, dispatch: any): () => void {
213261
// NOTE: Single websocket is essential because:
214262
// 1. Timeline aggregation assumes events are chronologically ordered
@@ -247,7 +295,8 @@ function connectLokiWebSocket(lokiHost: string, dispatch: any): () => void {
247295
const event =
248296
parseRankingBlockSent(stream.stream, ts, logLine) ||
249297
parseRankingBlockReceived(stream.stream, ts, logLine) ||
250-
parseEndorserBlockSent(stream.stream, ts, logLine);
298+
parseEndorserBlockSent(stream.stream, ts, logLine) ||
299+
parseEndorserBlockReceived(stream.stream, ts, logLine);
251300
if (event) {
252301
console.warn("Parsed", event.time_s, event.message);
253302
events.push(event);

0 commit comments

Comments
 (0)